Skip to main content

formattersAPI

MS Code Extension API


MS Code Extension API / core/extensionAPI/modules/languages/formattersAPI

core/extensionAPI/modules/languages/formattersAPI

Interfaces

DocumentFormattingEditProvider

Defined in: core/extensionAPI/modules/languages/formattersAPI.ts:8

Interface representing a provider that supplies formatting edits for a document.

Methods

provideDocumentFormattingEdits()

provideDocumentFormattingEdits(model, options, token): TextEdit[] | Promise<TextEdit[]>

Defined in: core/extensionAPI/modules/languages/formattersAPI.ts:17

Triggered when the user executes the "Format Document" command.

Parameters
model

ITextModel

The Monaco TextModel of the current file.

options

FormattingOptions

Formatting configuration (e.g., tabSize, insertSpaces).

token

CancellationToken

A cancellation token to handle aborted formatting requests.

Returns

TextEdit[] | Promise<TextEdit[]>

An array of TextEdits or a promise that resolves to them.

Functions

createFormattersAPI()

createFormattersAPI(): object

Defined in: core/extensionAPI/modules/languages/formattersAPI.ts:28

Factory function to create the Formatters API. Allows extensions to register language-specific code formatters.

Returns

registerDocumentFormattingEditProvider

registerDocumentFormattingEditProvider: (languageId, provider) => object

Registers a formatting provider for a specific language.

Parameters
languageId

string

The target language identifier (e.g., 'javascript', 'cpp', 'css').

provider

DocumentFormattingEditProvider

The implementation of the formatting logic.

Returns

A disposable object to unregister the provider.

dispose

dispose: () => void

Unregisters the formatting provider and cleans up resources.

Returns

void