The document formatting request is sent from the server to the client to format a whole document.
Request
method: 'textDocument/formatting'
param: DocumentFormattingParams defined as follows
interface DocumentFormattingParams {
/**
* The document to format.
*/
textDocument: TextDocumentIdentifier;
/**
* The format options
*/
options: FormattingOptions;
}
/**
* Value-object describing what options formatting should use.
*/
interface FormattingOptions {
/**
* Size of a tab in spaces.
*/
tabSize: number;
/**
* Prefer spaces over tabs.
*/
insertSpaces: boolean;
/**
* Signature for further properties.
*/
[key: string]: boolean | number | string;
}
Response
result: TextEdit[] describing the modification to the document to be formatted.
error: code and message set in case an exception happens during the formatting request.
Document Range Formatting
The document range formatting request is sent from the client to the server to format a given range in a document.
Request
method: 'textDocument/rangeFormatting',
param: DocumentRangeFormattingParams defined as follows
interface DocumentRangeFormattingParams {
/**
* The document to format.
*/
textDocument: TextDocumentIdentifier;
/**
* The range to format
*/
range: Range;
/**
* The format options
*/
options: FormattingOptions;
}
Response
result: TextEdit[] describing the modification to the document to be formatted.
error: code and message set in case an exception happens during the range formatting request.
Document on Type Formatting
The document on type formatting request is sent from the client to the server to format parts of the document during typing.
Request
method: 'textDocument/onTypeFormatting'
param: DocumentOnTypeFormattingParams defined as follows
interface DocumentOnTypeFormattingParams {
/**
* The document to format.
*/
textDocument: TextDocumentIdentifier;
/**
* The position at which this request was send.
*/
position: Position;
/**
* The character that has been typed.
*/
ch: string;
/**
* The format options.
*/
options: FormattingOptions;
}
Response
result: TextEdit[] describing the modification to the document.
error: code and message set in case an exception happens during the range formatting request.
Document Formatting
The document formatting request is sent from the server to the client to format a whole document.
Request
DocumentFormattingParams
defined as followsResponse
TextEdit[]
describing the modification to the document to be formatted.Document Range Formatting
The document range formatting request is sent from the client to the server to format a given range in a document.
Request
DocumentRangeFormattingParams
defined as followsResponse
TextEdit[]
describing the modification to the document to be formatted.Document on Type Formatting
The document on type formatting request is sent from the client to the server to format parts of the document during typing.
Request
DocumentOnTypeFormattingParams
defined as followsResponse
TextEdit[]
describing the modification to the document.