次の方法で共有


ExpansionProvider.FindExpansionByShortcut Method

Definition

Returns S_OK if match found, S_FALSE if expansion UI is shown, and error otherwise

public:
 virtual int FindExpansionByShortcut(Microsoft::VisualStudio::TextManager::Interop::IVsTextView ^ view, System::String ^ shortcut, Microsoft::VisualStudio::TextManager::Interop::TextSpan span, bool showDisambiguationUI, [Runtime::InteropServices::Out] System::String ^ % title, [Runtime::InteropServices::Out] System::String ^ % path);
 virtual int FindExpansionByShortcut(Microsoft::VisualStudio::TextManager::Interop::IVsTextView const & view, std::wstring const & shortcut, Microsoft::VisualStudio::TextManager::Interop::TextSpan span, bool showDisambiguationUI, [Runtime::InteropServices::Out] std::wstring const & & title, [Runtime::InteropServices::Out] std::wstring const & & path);
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);
abstract member FindExpansionByShortcut : Microsoft.VisualStudio.TextManager.Interop.IVsTextView * string * Microsoft.VisualStudio.TextManager.Interop.TextSpan * bool * string * string -> int
override this.FindExpansionByShortcut : Microsoft.VisualStudio.TextManager.Interop.IVsTextView * string * Microsoft.VisualStudio.TextManager.Interop.TextSpan * bool * string * string -> int
Public Overridable Function FindExpansionByShortcut (view As IVsTextView, shortcut As String, span As TextSpan, showDisambiguationUI As Boolean, ByRef title As String, ByRef path As String) As Integer

Parameters

view
IVsTextView

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

shortcut
String

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

span
TextSpan

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

showDisambiguationUI
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
String

[out] Returns the title of the snippet found.

path
String

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

Returns

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.

Applies to