IVsExpansion::InsertNamedExpansion Method (String^, String^, TextSpan, IVsExpansionClient^, Guid, Int32, IVsExpansionSession^)

 

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

Namespace:   Microsoft.VisualStudio.TextManager.Interop
Assembly:  Microsoft.VisualStudio.TextManager.Interop.8.0 (in Microsoft.VisualStudio.TextManager.Interop.8.0.dll)

int InsertNamedExpansion(
	String^ bstrTitle,
	String^ bstrPath,
	TextSpan tsInsertPos,
	IVsExpansionClient^ pExpansionClient,
	Guid guidLang,
	int fShowDisambiguationUI,
	[OutAttribute] IVsExpansionSession^% pSession
)

Parameters

bstrTitle
Type: System::String^

[in] The full name of the code snippet.

bstrPath
Type: System::String^

[inThe full path to the code snippet file.

tsInsertPos
Type: Microsoft.VisualStudio.TextManager.Interop::TextSpan

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

pExpansionClient
Type: Microsoft.VisualStudio.TextManager.Interop::IVsExpansionClient^

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

guidLang
Type: System::Guid

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

fShowDisambiguationUI
Type: System::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
Type: Microsoft.VisualStudio.TextManager.Interop::IVsExpansionSession^

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

Return Value

Type: System::Int32

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

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 (M:Microsoft.VisualStudio.TextManager.Interop.IVsExpansionClient.IsValidKind(Microsoft.VisualStudio.TextManager.Interop.IVsTextLines,Microsoft.VisualStudio.TextManager.Interop.TextSpan[],System.String) method) to make sure the snippet can actually be inserted at the specified location.

Return to top
Show: