AuthoringSink Class

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

This API is not CLS-compliant. 

Inheritance Hierarchy

Object
  Microsoft.VisualStudio.Package.AuthoringSink

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)

Syntax

'Declaration
<CLSCompliantAttribute(False)> _
Public Class AuthoringSink
[CLSCompliantAttribute(false)]
public class AuthoringSink
[CLSCompliantAttribute(false)]
public ref class AuthoringSink
[<CLSCompliantAttribute(false)>]
type AuthoringSink =  class end
public class AuthoringSink

The AuthoringSink type exposes the following members.

Constructors

  Name Description
Public method AuthoringSink Initializes the AuthoringSink class.

Top

Properties

  Name Description
Public property BraceMatching Indicates if brace matching should be done for a parse operation.
Public property Column Gets the column the parsing started on.
Public property FindNames Indicates whether identifiers are to be looked for.
Public property FoundMatchingBrace Tracks if a matching pair of braces was added to the internal list.
Public property HiddenRegions Indicates whether hidden regions should be processed during the parse operation.
Public property Line Returns the line the parsing operation started on.
Public property MethodParameters Indicates whether to process method parameters during the parse operation.
Public property ProcessHiddenRegions Indicates whether to update hidden regions.
Public property Reason Returns the reason the parse operation was started.

Top

Methods

  Name Description
Public method AddError Adds an error in parsing message for later reporting.
Public method AddHiddenRegion(NewHiddenRegion) Adds the specified NewHiddenRegion object to the internal hidden regions list.
Public method AddHiddenRegion(TextSpan) Adds a new hidden region to the internal list based on the given TextSpan object.
Public method AddHiddenRegion(TextSpan, String) Add a hidden region to the internal list.
Public method AutoExpression Adds the span of an expression to an internal list.
Public method CodeSpan This adds a span of executable code to an internal list.
Public method EndParameters Called to indicate the end of a method's parameter list.
Public method Equals Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as the default hash function. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method MatchMultiple 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.
Public method MatchPair Called to add the spans of the two paired elements in an internal list.
Public method MatchTriple Called to add a matching set of three elements to an internal list.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method NextParameter Called when parsing a method parameter list and the parameter separator character has just been parsed.
Public method QualifyName Called to note the location of a member reference.
Public method StartName Called when an identifier is parsed.
Public method StartParameters Called at the start of a method's parameter list.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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.

Errors

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

Brace Matching

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

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

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.

Autos

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.

Breakpoint Validation

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.

Thread Safety

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

See Also

Reference

Microsoft.VisualStudio.Package Namespace