format_document

[codefix]

Formats a TypeScript or JavaScript document with TypeScript language-service edits.

Why this tool exists

Editor and agent workflows often need preview-first writes and in-memory text to stay aligned while planning or validating edits.

How it helps the agent

The model can preview disk writes, preserve live document version guards, and keep semantic reads aligned with fresh edits.

Try it locally in the TGlider playground

Parameters

NameTypeRequiredDescription
filePathstringYesWorkspace-relative or absolute file path.
applyChangesbooleanNoApply formatting edits to live workspace state instead of returning preview only.
includeDiffbooleanNoInclude a unified diff in the response.
maxDiffCharsnumberNoMaximum diff characters to return before truncating.
indentSizenumberNoIndent width to use for formatting. Defaults to the document indentation style.
tabSizenumberNoTab width to use for formatting. Defaults to the document indentation style.
convertTabsToSpacesbooleanNoUse spaces instead of tabs for indentation. Defaults to the document indentation style.
semicolonsstringNoSemicolon preference: 'ignore', 'insert', or 'remove'. Defaults to preserving existing semicolon style.

Examples

Preview formatting edits

Request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "format_document",
    "arguments": {
      "filePath": "src/app.ts"
    }
  }
}

Response Notes

Returns formatting edits, preview diff metadata, live-document version state, and whether changes were applied.

↑/↓ NavigateEnter OpenSpace Expand