Condividi tramite


Statement Completion

Statement completion is the process by which the language service helps users finish a language keyword or element that they have started typing in the core editor. This topic discusses how statement completion works and how to implement it in your language service.

Implementing Statement Completion

In the core editor, statement completion activates a special UI that interactively helps you more easily and quickly write code. Statement completion helps by displaying pertinent objects or classes when they are needed, which avoids you having to remember specific elements or having to look them up in a Help reference topic.

To implement statement completion, your language must have a statement completion trigger, which can be parsed. For example, Visual Basic uses a dot (.) operator, while Visual C++ uses an arrow (->) operator. A language service can use more than one trigger to initiate statement completion. These triggers are programmed in the command filter.

Command Filters and Triggers

Command filters intercept occurrences of your trigger or triggers. To add the command filter to the view, implement the IOleCommandTarget interface and attach it to the view by calling the AddCommandFilter method. You can use the same command filter (IOleCommandTarget) for all aspects of your language service, such as statement completion, error markers, and method tips. For more information, see Intercepting Language Service Commands.

When the trigger is entered in the editor — specifically, the text buffer — your language service then calls the UpdateCompletionStatus method. This causes the editor to bring up the UI so that the user can choose from the statement completion candidates. This method requires you to implement IVsCompletionSet and the UpdateCompletionFlags flags as parameters. The list of completion items appears in a scrolling list box. As the user continues typing, the selection within the list box is updated to reflect the closest match to the most recent characters typed. The core editor implements the UI for statement completion, but the language service must implement the IVsCompletionSet interface to define a set of candidate completion items for the statement.

See Also

Concepts

Intercepting Language Service Commands