IVsExpansion::InsertExpansion Method (TextSpan, TextSpan, IVsExpansionClient^, Guid, IVsExpansionSession^)
Inserts the code snippet associated with the shortcut that can be found at the given context position in the text buffer.
Assembly: Microsoft.VisualStudio.TextManager.Interop.8.0 (in Microsoft.VisualStudio.TextManager.Interop.8.0.dll)
int InsertExpansion(
TextSpan tsContext,
TextSpan tsInsertPos,
IVsExpansionClient^ pExpansionClient,
Guid guidLang,
[OutAttribute] IVsExpansionSession^% pSession
)
Parameters
- tsContext
-
Type:
Microsoft.VisualStudio.TextManager.Interop::TextSpan
[in] The span (a pair of beginning and ending positions) in the text buffer that contains the snippet shortcut.
- tsInsertPos
-
Type:
Microsoft.VisualStudio.TextManager.Interop::TextSpan
[in] The span that is to be replaced by the snippet (typically includes the shortcut span).
- pExpansionClient
-
Type:
Microsoft.VisualStudio.TextManager.Interop::IVsExpansionClient^
[in] Teceives notifications about the insertion process. This can be a null value.
- guidLang
-
Type:
System::Guid
[in] GUID of the language service. Can be a null value. Default is the language service of the file.
- 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::Int32If the method succeeds, it returns S_OK. If it fails, it returns an error code.
From textmgr2.idl:
HRESULT IVsExpansion::InsertExpansion( [in] TextSpan tsContext, [in] TextSpan tsInsertPos, [in]IVsExpansionClient *pExpansionClient, [in]GUID guidLang, [out] IVsExpansionSession **pSession );
This method reads the snippet shortcut from the text buffer at the position specified by the tsContext parameter (remember, the IVsExpansion interface is implemented on the same object that implements the IVsTextBuffer interface), loads the snippet based on the shortcut and then inserts the snippet into the text buffer at position specified by the tsInsertPos parameter.
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.