In This Article

Tagger Provider

Tagger provider services allow taggers to be created for a document or view. Each language should provide a token tagger for documents using the language. Token taggers read tokens from the language's lexer and marks them with a logical categorization such as Identifier, Keyword, Comment, or anything else. These classifications can then be translated to highlighting styles, thereby achieving syntax highlighting in SyntaxEditor.

What are Taggers?

Taggers are objects that can apply data (in the form of tags) over various text ranges. This data could be anything from classifications, to squiggle tags, and more. Since each tagger can only be associated with a single document or view, tagger provider services are used to create taggers for documents/views upon request.

See the Taggers and Tagger Providers topic for details on how taggers and providers work.

Taggers are used for many features of SyntaxEditor including being involved in:

  • Classification
  • Syntax highlighting
  • Snapshot reading by token
  • Squiggle lines
  • Adornment layer managers

Token Taggers and Syntax Highlighting

As mentioned above, token taggers are special classes that are used to provide classification and token tags. When working with an editor like SyntaxEditor, the token tagger reads tags from the language's lexer and can return associated classifications, that are mapped to highlighting styles and used to achieve syntax highlighting.

Therefore if you need syntax highlighting, your language must have a lexer service, a token tagger provider service, and must have set up classification types to have mapped to highlighting styles in the ambient highlighting style registry.

Registering with a Syntax Language

As described in the Taggers and Tagger Providers topic, CodeDocumentTaggerProvider, TextViewTaggerProvider, and TokenTaggerProvider objects can be used as language services to provide taggers to any tag aggregator that request them.

This code shows how to register a document-oriented tagger provider language service that provides ParseErrorTagger objects for documents that use the language. Note that we are also passing a "singleton" key so that the tagger that is created for any document using the language is persisted in the document's Properties dictionary while it is active.

language.RegisterService(new CodeDocumentTaggerProvider<ParseErrorTagger>(typeof(ParseErrorTagger)));

This code shows how to register a document-oriented token tagger provider language service. Token taggers automatically persist themselves in the document's Properties dictionary while they are active. Only one token tagger provider service should ever be registered on a language instance at a time.

language.RegisterService(new TokenTaggerProvider<TokenTagger>());