ExpansionProvider.FindExpansionByShortcut(IVsTextView, String, TextSpan, Boolean, String, String) Method


Obtains the path and title of a code snippet given the snippet's shortcut name.

public virtual int FindExpansionByShortcut (Microsoft.VisualStudio.TextManager.Interop.IVsTextView view, string shortcut, Microsoft.VisualStudio.TextManager.Interop.TextSpan span, bool showDisambiguationUI, out string title, out string path);

[in] An IVsTextView object representing the view in which the snippet is to be inserted.


[in] A string containing the shortcut name of the snippet.


[in] A TextSpan object describing the position or selection in the current source.


[in] This is true if a user interface can be shown to resolve duplicate names; otherwise, false means to select the first expansion found that matches the shortcut name.


[out] Returns the title of the snippet found.


[out] Returns the path to the snippet template file.


If an expansion template was found, returns S_OK; otherwise, returns an error code from the VSConstants enumeration.


This helper method is called by your language service code. An expansion can occur because the user selected an expansion shortcut from a list (see the DisplayExpansionBrowser method) or a particular character is typed that triggers an expansion. For example, typing a space after typing "if" might trigger an expansion into "if () { }" where the cursor is positioned between the parentheses (this is also known as auto-completion). In this case, the word "if" is the shortcut for the snippet. If you handle auto-completions such as this, you would call the FindExpansionByShortcut method when a space or tab is typed. If the FindExpansionByShortcut method returns a path, then the snippet can be expanded by a call to the InsertNamedExpansion method.

See the example in the ExpansionProvider class to see how this method is used.

When a shortcut matches more than one snippet and showDisambiguationUI is true, then a list of possible choices displaying the snippet's title can be displayed to have the user resolve the conflict.

The base method obtains an IVsTextManager object from the SVsTextManager service and calls the GetExpansionByShortcut method on the IVsTextManager object. The GetExpansionByShortcut method does all the work. The base method returns true if the GetExpansionByShortcut method returns a success code.

Applies to