IVsLanguageTextOps.Format Method
Formats the selected text.
Namespace: Microsoft.VisualStudio.TextManager.Interop
Assembly: Microsoft.VisualStudio.TextManager.Interop (in Microsoft.VisualStudio.TextManager.Interop.dll)
Syntax
'Declaration
Function Format ( _
pTextLayer As IVsTextLayer, _
ptsSel As TextSpan() _
) As Integer
int Format(
IVsTextLayer pTextLayer,
TextSpan[] ptsSel
)
int Format(
[InAttribute] IVsTextLayer^ pTextLayer,
[InAttribute] array<TextSpan>^ ptsSel
)
abstract Format :
pTextLayer:IVsTextLayer *
ptsSel:TextSpan[] -> int
function Format(
pTextLayer : IVsTextLayer,
ptsSel : TextSpan[]
) : int
Parameters
pTextLayer
Type: Microsoft.VisualStudio.TextManager.Interop.IVsTextLayer[in] An IVsTextLayer object containing the text to format.
ptsSel
Type: array<Microsoft.VisualStudio.TextManager.Interop.TextSpan[][in] Text span to format within the specified layer. For more information, see TextSpan.
Return Value
Type: System.Int32
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.
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.