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.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.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.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.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
)
public:
virtual int FindExpansionByShortcut(
    IVsTextView^ view, 
    String^ shortcut, 
    TextSpan span, 
    bool showDisambiguationUI, 
    [OutAttribute] String^% title, 
    [OutAttribute] String^% path
)
abstract FindExpansionByShortcut : 
        view:IVsTextView * 
        shortcut:string * 
        span:TextSpan * 
        showDisambiguationUI:bool * 
        title:string byref * 
        path:string byref -> int  
override FindExpansionByShortcut : 
        view:IVsTextView * 
        shortcut:string * 
        span:TextSpan * 
        showDisambiguationUI:bool * 
        title:string byref * 
        path:string byref -> int
public function FindExpansionByShortcut(
    view : IVsTextView, 
    shortcut : String, 
    span : TextSpan, 
    showDisambiguationUI : boolean, 
    title : String, 
    path : String
) : int

Parameters

  • shortcut
    Type: String

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

  • showDisambiguationUI
    Type: 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: String%

    [out] Returns the title of the snippet found.

  • path
    Type: String%

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

Return Value

Type: 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

See Also

Reference

ExpansionProvider Class

Microsoft.VisualStudio.Package Namespace