AuthoringSink Class

 

This class is used by the parser to gather information about the source being parsed.

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

System.Object
  Microsoft.VisualStudio.Package.AuthoringSink

[CLSCompliantAttribute(false)]
public class AuthoringSink

NameDescription
System_CAPS_pubmethodAuthoringSink(ParseReason, Int32, Int32, Int32)

Initializes the AuthoringSink class.

NameDescription
System_CAPS_pubpropertyBraceMatching

Indicates if brace matching should be done for a parse operation.

System_CAPS_pubpropertyColumn

Gets the column the parsing started on.

System_CAPS_pubpropertyFindNames

Indicates whether identifiers are to be looked for.

System_CAPS_pubpropertyFoundMatchingBrace

Tracks if a matching pair of braces was added to the internal list.

System_CAPS_pubpropertyHiddenRegions

Indicates whether hidden regions should be processed during the parse operation.

System_CAPS_pubpropertyLine

Returns the line the parsing operation started on.

System_CAPS_pubpropertyMethodParameters

Indicates whether to process method parameters during the parse operation.

System_CAPS_pubpropertyProcessHiddenRegions

Indicates whether to update hidden regions.

System_CAPS_pubpropertyReason

Returns the reason the parse operation was started.

NameDescription
System_CAPS_pubmethodAddError(String, String, TextSpan, Severity)

Adds an error in parsing message for later reporting.

System_CAPS_pubmethodAddHiddenRegion(NewHiddenRegion)

Adds the specified NewHiddenRegion object to the internal hidden regions list.

System_CAPS_pubmethodAddHiddenRegion(TextSpan)

Adds a new hidden region to the internal list based on the given TextSpan object.

System_CAPS_pubmethodAddHiddenRegion(TextSpan, String)

Add a hidden region to the internal list.

System_CAPS_pubmethodAutoExpression(TextSpan)

Adds the span of an expression to an internal list.

System_CAPS_pubmethodCodeSpan(TextSpan)

This adds a span of executable code to an internal list.

System_CAPS_pubmethodEndParameters(TextSpan)

Called to indicate the end of a method's parameter list.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodMatchMultiple(TextSpan[], Int32)

Matching multiples are used to highlight in bold a completed statement. For example, a language can define a construct like if ... elif ... elif ... else ... endif. A priority can also be given so that multiple overlapping pairs can be prioritized for brace matching. The matching pair with the highest priority (largest integer value) wins.

System_CAPS_pubmethodMatchPair(TextSpan, TextSpan, Int32)

Called to add the spans of the two paired elements in an internal list.

System_CAPS_pubmethodMatchTriple(TextSpan, TextSpan, TextSpan, Int32)

Called to add a matching set of three elements to an internal list.

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodNextParameter(TextSpan)

Called when parsing a method parameter list and the parameter separator character has just been parsed.

System_CAPS_pubmethodQualifyName(TextSpan, TextSpan, String)

Called to note the location of a member reference.

System_CAPS_pubmethodStartName(TextSpan, String)

Called when an identifier is parsed.

System_CAPS_pubmethodStartParameters(TextSpan)

Called at the start of a method's parameter list.

System_CAPS_pubmethodToString()

(Inherited from Object.)

An instantiation of this class is used extensively by the parser to remember various language elements that help with the following features:

  • Error reporting.

  • Brace matching.

  • IntelliSense Member Selection, Complete Word, Quick Info, and Method Tips.

  • Hidden regions.

  • Management of contents of the Autos window in the debugger.

  • Breakpoint validation.

The base class has support for all but the last two features.

The base class uses an internal ArrayList called errors to contain the errors found during parsing. This list is displayed at the end of a full parsing operation by converting each error message into a task list item by calling M:Microsoft.VisualStudio.Package.Source.CreateErrorTaskItem(Microsoft.VisualStudio.TextManager.Interop.IVsTextLineMarker,Microsoft.VisualStudio.TextManager.Interop.TextSpan,System.String) and adding it the Error List task window. These errors are also shown in the source file itself as squiggly lines under the code that is in error. This is handled automatically by the MPF classes. The AuthoringSink class constructor takes a parameter that specifies the maximum number of errors that can be retained by the class.

The base class uses an internal ArrayList called Braces to contain matching pairs of language elements (such as "{" and "}") as well as matching triples (such as "for()", "{", and "}"). A base class called BraceMatch is used for matching pairs while a derived class called TripleMatch adds information for a third language element. Calling the MatchPair and MatchTriple methods is done only when the reason for parsing is to match braces (see the BraceMatching property for details on the exact reasons). See the Example section of MatchPairfor a description of the BraceMatch class and see the Example section of MatchTriplefor a description of the TripleMatch class.

IntelliSense has at least four distinct modes that can be supported by the language service. These are:

  1. Member Selection: This option provides a list of members for the current scope, typically supplied after the user types a particular character. For example, if the user has entered a variable name followed by a "." then a member list for the type of that variable is displayed for selection.

  2. Complete Word: This option presents a list of possible completions for a word being entered by the user.

  3. Quick Info: This option presents information about an identifier. This is triggered either by the user holding the mouse cursor over the identifier or by positioning the edit caret on an identifier and selecting Quick Info from the IntelliSense menu.

  4. Method Tip: This option presents parameter information to help the user while entering a method and its parameters. A tool tip is displayed showing one of possible several overloaded forms of the method along with the parameters. As the user enters each parameter, the tool tip is updated to show the parameter being typed.

All of these modes are supported by the methods StartName and QualifyName and the internal lists MethodCalls, Names, and SourceLocations. MethodCalls is used to track method signatures as they are parsed. Names and SourceLocations are used to track the method parameters while parsing a method parameter list. Note that for each name in the Names list, there is a corresponding TextSpan object in the SourceLocations list.

Hidden regions are sections of code that can optionally be hidden from view by the user. These regions are typically used as part of support for outlining where each method and class can be collapsed into a single line, making the overall class structure clearer. Some languages support specific hidden regions through special keywords. For example, C# uses #region/#endregion to bracket a region that the user normally wants hidden. A hidden region is indicated by a TextSpan object that is wrapped in a NewHiddenRegion object that in turn is stored in an internal array called hiddenRegions. Hidden regions are added by calling AddHiddenRegion.

While debugging, the Autos window can show all local variables and parameters available in a particular scope of a stack frame. The language service can support these variables by locating them during parsing. This allows the Autos window to be dynamically updated while editing during debugging. The base class AuthoringSink does not support autos so you have to derive a class from the AuthoringSink class and implement the AutoExpression method yourself.

When a breakpoint is placed, the location of the breakpoint is not validated until debugging actually starts and the debug engine has been loaded. If your language service supports identifying valid sections of code where a breakpoint can be placed, then this information can be used to validate the placement of breakpoints without loading the debug engine. Note that the debug engine is always the final judge when validating breakpoint locations but the language service can provide fast feedback to the user. The base class AuthoringSink does not support breakpoint validation so you have to derive a class from the AuthoringSink class and implement the CodeSpan method yourself.

Notes to Implementers:

If your language service supports expressions in the Autos window or validating breakpoints in a span of code, you need derive a class from the AuthoringSink class and override the appropriate methods (AutoExpression and CodeSpan). Then override the CreateAuthoringSink method in the Source class to instantiate your version of the AuthoringSink class. The AuthoringSink class is instantiated every time a parse operation is called for.

Notes to Callers:

This class is accessed in several places in the Source class in order to handle brace matching, IntelliSense, and error reporting.

Tip: When implementing your class derived from AuthoringScope, add a field to your class to store the AuthoringSink object created for the ParseRequest object. This way, your AuthoringScope object can access all the information stored in the AuthoringSink object.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: