Share via


IVsLanguageTextOps.Format(IVsTextLayer, TextSpan[]) Method

Definition

Formats the selected text.

public:
 int Format(Microsoft::VisualStudio::TextManager::Interop::IVsTextLayer ^ pTextLayer, cli::array <Microsoft::VisualStudio::TextManager::Interop::TextSpan> ^ ptsSel);
public:
 int Format(Microsoft::VisualStudio::TextManager::Interop::IVsTextLayer ^ pTextLayer, Platform::Array <Microsoft::VisualStudio::TextManager::Interop::TextSpan> ^ ptsSel);
int Format(Microsoft::VisualStudio::TextManager::Interop::IVsTextLayer const & pTextLayer, std::Array <Microsoft::VisualStudio::TextManager::Interop::TextSpan> const & ptsSel);
public int Format (Microsoft.VisualStudio.TextManager.Interop.IVsTextLayer pTextLayer, Microsoft.VisualStudio.TextManager.Interop.TextSpan[] ptsSel);
abstract member Format : Microsoft.VisualStudio.TextManager.Interop.IVsTextLayer * Microsoft.VisualStudio.TextManager.Interop.TextSpan[] -> int
Public Function Format (pTextLayer As IVsTextLayer, ptsSel As TextSpan()) As Integer

Parameters

pTextLayer
IVsTextLayer

[in] An IVsTextLayer object containing the text to format.

ptsSel
TextSpan[]

[in] Text span to format within the specified layer. For more information, see TextSpan.

Returns

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

Remarks

COM Signature

From textmgr.idl:

HRESULT IVsLanguageTextOps::Format(  
   [in] IVsTextLayer *pTextLayer,  
   [in] const TextSpan *ptsSel  
);  

This function is called when the user selects Format Document or Format Selection from the Edit -> Advanced menu, and requests that the language service provide formatting for the referenced text span. Formatting typically means to adjusting line indenting, adding spaces after commas, or even moving braces to a new line with proper indentation.

This method can also be called whenever the user types a character that can trigger a reformat (what that character is depends on the language service but typically it is a closing brace or semicolon).

Note

It is strongly recommended that if you implement this method, you wrap all changes made to the document in an IVsCompoundAction object so the user can undo the entire format operation in one action.

Applies to