Intercepting Language Service Commands

With Visual Studio, you can insert a command filter into the text view from your language service. Doing this lets the language service intercept commands that the text view would otherwise handle. The command interception feature can be useful for specialized behavior that is too language-specific for the text view to initiate.

Getting and Routing the Command

A command filter is an IOleCommandTarget object that monitors certain character sequences or key commands. You can associate more than one command filter with a single text view. Each text view maintains a chain of command filters. After you create a new command filter, you add the filter to the chain for the appropriate text view.

Call the AddCommandFilter method on the IVsTextView to add your command filter to the chain and to handle commands for the text view. When you call AddCommandFilter, the integrated development environment (IDE) returns another command filter to which you can pass the commands that your command filter does not handle.

When you create your command filter, you have the following options for command handling:

  • Handle the command and then pass the command on to the next command filter in the chain.

  • Handle the command and do not pass the command on to the next command filter in the chain.

  • Do not handle the command, but pass the command on to the next command filter in the chain.

For information about which commands your language service should handle, see Key Commands for Language Service Filters.

See Also

Concepts

Developing a Language Service