LanguageService.ParseSource Method

Parses the source based on the specified ParseRequest object.

Namespace:  Microsoft.VisualStudio.Package
Assembly:  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)

Syntax

'Declaration
Public MustOverride Function ParseSource ( _
    req As ParseRequest _
) As AuthoringScope
'Usage
Dim instance As LanguageService 
Dim req As ParseRequest 
Dim returnValue As AuthoringScope 

returnValue = instance.ParseSource(req)
public abstract AuthoringScope ParseSource(
    ParseRequest req
)
public:
virtual AuthoringScope^ ParseSource(
    ParseRequest^ req
) abstract
public abstract function ParseSource(
    req : ParseRequest
) : AuthoringScope

Parameters

Return Value

Type: Microsoft.VisualStudio.Package.AuthoringScope
If successful, returns an AuthoringScope object; otherwise, returns a null value.

Remarks

This method must be implemented in your class that is derived from the LanguageService class. Be aware that the parse operation may operate on the entire source file or a single line or even a single token. The ParseReason code on the ParseRequest dictates the scope of the parse operation.

The returned AuthoringScope contains all the information parsed from the source file.

Note

AuthoringScope is an abstract class and you must derive your own class from it to provide the necessary functionality. Your version of AuthoringScope is instantiated in this method, ParseSource. You must return an AuthoringScope object even if all members of that class return null values!

This method can be called on either the foreground or background thread and is always expected to parse the source according to the ParseReason code before returning.

Warning

Even though the ParseRequest structure contains an IVsTextView object, you cannot use that object in a background thread due to threading issues. In fact, you cannot use on the background thread the Source, ViewFilter, CodeWindowManager classes, or any class that communicates directly or indirectly with the view. The ParseSource method parser must obtain all of its information about the source from the text supplied in the ParseRequest structure (which always contains the entire source file).

Examples

Here is a simple skeleton of a possible implementation of the ParseSource method.

using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Package;

namespace MyLanguagePackage
{
    public class MyLanguageService : LanguageService
    {
        public AuthoringScope ParseSource(ParseRequest req)
        {
            MyAuthoringScope scope = new MyAuthoringScope();
            if (req.Reason == ParseReason.Check ||
                req.Reason == ParseReason.None)
            {
                // Parse the entire source as given in req.Text. Store results in the MyAuthoringScope object.
            }
            else if (req.Reason == ParseReason.DisplayMemberList)
            {
                // Parse the line specified in req.Line for the two tokens just before req.Col to get the identifier and the member connector symbol. Find members of the identifer in the parse tree and store the list of members in the Declarations class.
            }
            else if (req.Reason == ParseReason.MethodTip)
            {
                // Parse the line specified in req.Line for the token just before req.Col to obtain the name of the method. Find all method signatures with the same name in the existing parse tree and store the list of signatures in the Methods class.
            }
            // continue for the rest of the supported ParseReason values.
            return scope;
        }
    }
}

.NET Framework Security

See Also

Reference

LanguageService Class

LanguageService Members

Microsoft.VisualStudio.Package Namespace