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.
Core Editor Usage of a Language Service's Colorizer
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:
Calls the colorizer as needed to parse and analyze text as it is added or modified in the implementation of IVsTextBuffer.
Ensures that the display supplied by the document view provided by the IVsTextView implementation is updated and repainted using the information returned by the colorizer.
Non-core Editor Usage of a Language Service's Colorizer
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, a non-core editor must:
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 Using Fonts and Colors.