Model of a Language Service

A language service provides an editor with information and features specific to the language being shown in that editor. For example, syntax highlighting requires information about the language, which is provided by the language service.

To access text for parsing, a language service works closely with the text buffer the editor manages. To support commands specific to its language, a language service also works with the view that contains the editor. The Microsoft IntelliSense Quick Info option is an example of language-specific support.

A Minimal Language Service

The most basic language service that supports syntax highlighting contains the following two objects:

  • The language service object implements the IVsLanguageInfo interface, which is required for any language service. A language service object can retrieve information about the language including its name, source file name extensions, code window manager, and colorizer.

  • The colorizer object implements the IVsColorizer interface to let you color code specific language elements or keywords.

The following conceptual drawing shows a model of a basic language service.

Basic language service model
Language Service Model graphic

The document window hosts the document view object of the editor, in this model the Visual Studio core editor. The document view object interacts with the text buffer to create the editor. These objects coordinate with the integrated development environment (IDE) through a specialized document window called a code window. The code window is contained in an IVsWindowFrame object that is created and controlled by the IDE.

When a file of a particular file name extension is loaded, the editor locates the language service and passes the code window in the form of an IVsCodeWindow object. The editor does this by calling the GetCodeWindowManager method on the IVsLanguageInfo interface. The language service object returns a code window manager as an object implementing the IVsCodeWindowManager interface. The editor uses the code window manager to connect the document view to the language service. This connection lets the language service handle commands from Visual Studio.

As soon as the editor has retrieved the code window manager, it calls the GetColorizer method on the IVsLanguageInfo interface to obtain the colorizer as an object implementing the IVsColorizer interface. The colorizer object coordinates with the text buffer to colorize specific spans of text.

The following table provides an overview of the objects in the model.

Component

Object

Function

Text buffer

VsTextBuffer

An object that represents a Unicode stream of text. You can use a buffer to read and modify text. You must use Unicode to communicate with buffers; however, when required, a buffer can read and write images in other text encoding.

Code window

VsCodeWindow

A special document window that contains one or more text views. When Visual Studio is in multiple-document interface (MDI) mode, the code window is an MDI child.

Text view

VsTextView

A window that lets the user navigate and view text by using the keyboard and mouse. A text view appears to the user as an editor. You can use text views in ordinary editor windows, the Output window, and the Immediate window. Additionally, you can configure one or more text views within a code window.

Text manager

Managed by the SVsTextManager service, from which you obtain an IVsTextManager pointer

A component that maintains common information shared by all the components described previously.

Language service

Implementation dependent; implements IVsLanguageInfo

An object that provides the editor with language-specific information such as syntax highlighting, statement completion, and brace matching.

See Also

Concepts

Document Data and Document View Objects