IVsExpansion.InsertExpansion Method

Definition

Inserts the code snippet associated with the shortcut that can be found at the given context position in the text buffer.

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

Parameters

tsContext
TextSpan

[in] The span (a pair of beginning and ending positions) in the text buffer that contains the snippet shortcut.

tsInsertPos
TextSpan

[in] The span that is to be replaced by the snippet (typically includes the shortcut span).

pExpansionClient
IVsExpansionClient

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

guidLang
Guid

[in] GUID of the language service. Can be a null value. Default is the language service of the file.

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::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 (IsValidKind method) to make sure the snippet can actually be inserted at the specified location.

Applies to