Compartilhar via


IVsExpansion.InsertNamedExpansion Method

Definition

Inserts snippet with the specified name at the specified position in the text buffer.

public:
 int InsertNamedExpansion(System::String ^ bstrTitle, System::String ^ bstrPath, Microsoft::VisualStudio::TextManager::Interop::TextSpan tsInsertPos, Microsoft::VisualStudio::TextManager::Interop::IVsExpansionClient ^ pExpansionClient, Guid guidLang, int fShowDisambiguationUI, [Runtime::InteropServices::Out] Microsoft::VisualStudio::TextManager::Interop::IVsExpansionSession ^ % pSession);
public int InsertNamedExpansion (string bstrTitle, string bstrPath, Microsoft.VisualStudio.TextManager.Interop.TextSpan tsInsertPos, Microsoft.VisualStudio.TextManager.Interop.IVsExpansionClient pExpansionClient, Guid guidLang, int fShowDisambiguationUI, out Microsoft.VisualStudio.TextManager.Interop.IVsExpansionSession pSession);
abstract member InsertNamedExpansion : string * string * Microsoft.VisualStudio.TextManager.Interop.TextSpan * Microsoft.VisualStudio.TextManager.Interop.IVsExpansionClient * Guid * int * IVsExpansionSession -> int
Public Function InsertNamedExpansion (bstrTitle As String, bstrPath As String, tsInsertPos As TextSpan, pExpansionClient As IVsExpansionClient, guidLang As Guid, fShowDisambiguationUI As Integer, ByRef pSession As IVsExpansionSession) As Integer

Parameters

bstrTitle
String

[in] The full name of the code snippet.

bstrPath
String

[inThe full path to the code snippet file.

tsInsertPos
TextSpan

[in] Specifies the location in the text buffer to insert the code snippet.

pExpansionClient
IVsExpansionClient

[in] Receives notifications about the insertion process. This can be a null value.

guidLang
Guid

[in] The GUID of the language service. Can be null. The default is the language service of the file.

fShowDisambiguationUI
Int32

[in] This is non-zero (true) if a "disambiguation user interface (UI)" can be shown in the case where multiple snippets with the same name are found. If this value is zero (false) then the first snippet that matches the name is inserted.

pSession
IVsExpansionSession

[out] Returns an IVsExpansionSession object that is used while the snippet is being edited in place.

Returns

If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

COM Signature

From textmgr2.idl:

HRESULT IVsExpansion::InsertNamedExpansion(  
   [in]BSTR bstrTitle,  
   [in] BSTR bstrPath,  
   [in] TextSpan tsInsertPos,  
   [in]IVsExpansionClient *pExpansionClient,  
   [in]GUID guidLang,  
   [in] bool fShowDisambiguationUI,  
   [out] IVsExpansionSession **pSession  
);  

This method used to insert a code snippet when the name and path of the code snippet is known. The name and path can be obtained from the code snippet's shortcut by calling the M:Microsoft.VisualStudio.TextManager.Interop.IVsExpansionManager.GetExpansionByShortcut(Microsoft.VisualStudio.TextManager.Interop.IVsExpansionClient,System.Guid,System.String,Microsoft.VisualStudio.TextManager.Interop.IVsTextView,Microsoft.VisualStudio.TextManager.Interop.TextSpan[],System.Int32,System.String@,System.String@) method in the IVsExpansionManager interface.

This method is typically called from an implementation of the OnItemChosen method in the IVsExpansionClient interface as the OnItemChosen method is given the name and path of the code snippet.

If an IVsExpansionClient object is supplied, it receives before (OnBeforeInsertion method) and after (OnAfterInsertion method) notifications during the insertion process. The expansion client is also used to validate the kind of snippet (IsValidKind method) to make sure the snippet can actually be inserted at the specified location.

Applies to