Syntax Coloring in Custom Editors
Visual Studio Environment SDK editors, including the core editor, use language services to identify specific syntactical items and display them with specified colors for a given document view.
All editors implementing a language service's colorizer must:
Obtain an interface to a particular language service by querying the VSPackage's service provider using the languages service's identifying GUID.
Call the SetLanguageServiceID method of the object implementing IVsTextBuffer. This method associates the language service with the IVsTextBuffer implementation that the VSPackage uses to manage the text that is to be colorized.
When a language service with a colorizer is obtained by an instance of the core editor, the parsing and rendering of text by a language service's colorizer occurs automatically without requiring any further intervention on your part.
The IDE transparently:
Non-core editor instances can also use a language service's syntax colorization service, but they must explicitly retrieve and apply the service's colorizer and repaint their document views themselves.
To do this requires a non-core editor to:
Obtain a language service's colorizer object (which implements T:Microsoft.VisualStudio.TextManager.Interop.IVsColorizer and IVsColorizer2). Your VSPackage does this by calling the GetColorizer method on the language service's interface.
Call the ColorizeLine method to request that a particular span of text be colorized.
The ColorizeLine method returns an array of values, one for each letter in the text span being colorized. It also identifies the text span as a particular type of colorable item, such as a comment, keyword, or data type.
Use the colorization information returned by ColorizeLine to repaint and display its text.
In addition to using a language service's colorizer, a VSPackage can choose to use the general-purpose Visual Studio Environment SDK text-coloring mechanism. For more information on this mechanism, see Fonts.