LanguageService.ParseSource Method
Parses the source based on the specified ParseRequest object.
Namespace: Microsoft.VisualStudio.Package
Assemblies: Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)
Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
Syntax
'Declaration
Public MustOverride Function ParseSource ( _
req As ParseRequest _
) As AuthoringScope
public abstract AuthoringScope ParseSource(
ParseRequest req
)
public:
virtual AuthoringScope^ ParseSource(
ParseRequest^ req
) abstract
abstract ParseSource :
req:ParseRequest -> AuthoringScope
public abstract function ParseSource(
req : ParseRequest
) : AuthoringScope
Parameters
req
Type: Microsoft.VisualStudio.Package.ParseRequest[in] The ParseRequest describing how to parse the source file.
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.
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
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.