ExpansionProvider.FindExpansionByShortcut Method
Obtains the path and title of a code snippet given the snippet's shortcut name.
Namespace: Microsoft.VisualStudio.Package
Assemblies: Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
Syntax
'Declaration
Public Overridable Function FindExpansionByShortcut ( _
view As IVsTextView, _
shortcut As String, _
span As TextSpan, _
showDisambiguationUI As Boolean, _
<OutAttribute> ByRef title As String, _
<OutAttribute> ByRef path As String _
) As Integer
public virtual int FindExpansionByShortcut(
IVsTextView view,
string shortcut,
TextSpan span,
bool showDisambiguationUI,
out string title,
out string path
)
Parameters
- view
Type: Microsoft.VisualStudio.TextManager.Interop.IVsTextView
[in] An IVsTextView object representing the view in which the snippet is to be inserted.
- shortcut
Type: System.String
[in] A string containing the shortcut name of the snippet.
- span
Type: Microsoft.VisualStudio.TextManager.Interop.TextSpan
[in] A TextSpan object describing the position or selection in the current source.
- showDisambiguationUI
Type: System.Boolean
[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.
- title
Type: System.String%
[out] Returns the title of the snippet found.
- path
Type: System.String%
[out] Returns the path to the snippet template file.
Return Value
Type: System.Int32
If an expansion template was found, returns S_OK; otherwise, returns an error code from the VSConstants enumeration.
Remarks
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.
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.