Share via


LanguageService.ParseSource(ParseRequest) Method

Definition

Parses the source based on the specified ParseRequest object.

public:
 abstract Microsoft::VisualStudio::Package::AuthoringScope ^ ParseSource(Microsoft::VisualStudio::Package::ParseRequest ^ req);
 abstract Microsoft::VisualStudio::Package::AuthoringScope ParseSource(Microsoft::VisualStudio::Package::ParseRequest const & req);
public abstract Microsoft.VisualStudio.Package.AuthoringScope ParseSource (Microsoft.VisualStudio.Package.ParseRequest req);
abstract member ParseSource : Microsoft.VisualStudio.Package.ParseRequest -> Microsoft.VisualStudio.Package.AuthoringScope
Public MustOverride Function ParseSource (req As ParseRequest) As AuthoringScope

Parameters

req
ParseRequest

[in] The ParseRequest describing how to parse the source file.

Returns

If successful, returns an AuthoringScope object; otherwise, returns a null value.

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;  
        }  
    }  
}  

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.

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).

Applies to