Word Completion in a Legacy Language Service


For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

Word completion fills in the missing characters on a partially typed word. If there is only one possible completion, the word is completed when the completion character is entered. If the partial word matches more than one possibility, a list of possible completions is displayed. A completion character can be any character that is not used for identifiers.

Legacy language services are implemented as part of a VSPackage, but the newer way to implement language service features is to use MEF extensions. To find out more, see Extending the Editor and Language Services.

System_CAPS_ICON_note.jpg Note

We recommend that you begin to use the new editor API as soon as possible. This will improve the performance of your language service and let you take advantage of new editor features.

  1. When the user selects Complete Word from the IntelliSense menu, the COMPLETEWORD command is sent to the language service.

  2. The ViewFilter class catches the command and calls the Completion method with the parse reason of CompleteWord.

  3. The Source class then calls the ParseSource method to get the list of possible word completions and then displays the words in a tool tip list using the CompletionSet class.

    If there is only one matching word, the Source class completes the word.

Alternatively, if the scanner returns the trigger value MemberSelect when the first character of an identifier is typed, the Source class detects this and calls the Completion method with the parse reason of MemberSelect. In this case the parser must detect the presence of a member selection character and provide a list of members.

To enable support for word completion set the CodeSense named parameter passed to the ProvideLanguageServiceAttribute user attribute associated with the language package. This sets the EnableCodeSense property on the LanguagePreferences class.

Your parser must return a list of declarations in response to the parse reason value CompleteWord, for word completion to operate.

For word completion, the Source class calls the GetDeclarations method on the AuthoringScope class to obtain a list of possible word matches. You must implement the list in a class that is derived from the Declarations class. See the Declarations class for details on the methods you must implement.

If the list contains only a single word, then the Source class automatically inserts that word in place of the partial word. If the list contains more than one word, the Source class presents a tool tip list from which the user can select the appropriate choice.

Also look at the example of a Declarations class implementation in Member Completion in a Legacy Language Service.