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.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
Syntax
'Déclaration
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
'Utilisation
Dim instance As ExpansionProvider
Dim view As IVsTextView
Dim shortcut As String
Dim span As TextSpan
Dim showDisambiguationUI As Boolean
Dim title As String
Dim path As String
Dim returnValue As Integer
returnValue = instance.FindExpansionByShortcut(view, _
shortcut, span, showDisambiguationUI, _
title, path)
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
- 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.