Implementing the IBabelService Interface

If the default Babel implementation is not sufficient for your language, typically because you need to use a parser other than those produced by lex (or flex) and yacc (or bison), then you can implement IBabelService Interface yourself.

The Babel Package

The Babel package implements a language service for Visual Studio. It looks for all languages that use the Babel Package GUID as the package and instantiates a language service that wraps each implementation of the IBabelService Interface (note that the Babel Package assumes your language service implements the IBabelService interface; if the package fails to obtain the IBabelService interface from your language service, your language service is ignored).

注意

You can support multiple languages based on the IBabelService interface using only one installation of the Babel Package.

The Babel Package calls the IBabelService interface to accomplish specific tasks. You must create a DLL that contains a class that implements the IBabelService interface and all of its methods, implement a standard class factory to instantiate your class, and add code to register that DLL as a Visual Studio language service but with the package GUID set to the Babel Package. Your DLL must also implement a COM class factory and register itself as such with COM.

Examine the dllmain.cpp file in the Babel common library located in the Babel\Common folder (for example, <InstallPath>\VisualStudioIntegration\Babel\Common\dllmain.cpp) to see what is required to create a DLL that registers as a language service.

注意

If you need to modify the Babel Package code itself and you intend to ship that modified version with your language service, then you must compile the Babel Package with a new package and service GUID. Then both the modified Babel Package and your language service must be installed and registered with Visual Studio.

Methods

注意

The IBabelService interface derives from the IDispatch Interface that in turn derives from the IUnknown interface so you must implement all of the IUnknown and IDispatch methods as well.

The methods of the IBabelService Interface are called by the Babel Package, in the following order:

  1. IBabelService::Init Method

    Called once to provide the IBabelService implementation with the current language setting in Visual Studio (for example, French, German, or Japanese).

  2. IBabelService::ColorCount Method, IBabelService::GetColorInfo Method

    Called to obtain the number of custom colorable items and the style for each colorable item.

  3. IBabelService::GetMethodFormat Method, IBabelService::GetCommentFormat Method

    Called once to get custom method and comment information.

  4. IBabelService::GetImageList Method

    Called to get an image list of icons.

  5. IBabelService::ColorLine Method

    Called multiple times from the main (UI) thread to obtain colorization information for different spans of text. With the exception of the IBabelService::ParseSource Method method, all methods of IBabelService are called from this thread.

  6. IBabelService::ParseSource Method

    Called multiple times from the parse thread to obtain information used to display error markers, brace matching, statement completion, parameter info ToolTips, and so on.

    The ParseSource and ColorLine methods can be called simultaneously. For more information about threading in your IBabelService implementation, see IBabelService Threading Model.

  7. IBabelService::Done Method

    Called once to indicate that the language service is no longer needed.

The architecture of the IBabelService implementation is shown in the following diagram.

Overview of the Babel service
Babel Service Overview

If you implement the IBabelService interface, you must supply a parser that can keep track of white space, parentheses, and comments, while being able to recover from errors and provide a complete syntax tree.

Your implementation of the IBabelService::ColorLine Method accesses your parser to get information about token types to support syntax highlighting. Your implementation of the IBabelService::ParseSource Method accesses your parser to get information about the functionality and scope of tokens.

See Also

Concepts

Using the Babel Package

Using the Default Babel Implementation

IBabelService Threading Model