Partilhar via


IntelliSense Complete Word (Managed Package Framework)

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.

Implementation Steps

  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.

Enabling Support for the Complete Word

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.

Implementing Complete Word in the ParseSource Method

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 IntelliSense Member Completion (Managed Package Framework).