14 — Reference
Formatting
Built-in Prettier and external executables, with selection and saving rules.
On this page
Format a document
- Open a project file in source and press Alt+Shift+F or Format document in the palette.
- OEC selects byExtension or defaultFormatter. none skips formatting; prettier receives content, filepath and configured options.
- Apply the result only if path and content still match on completion. Save afterwards with Ctrl+S.
Options and format on save
Defaults use Prettier for JavaScript, TypeScript, JSON, CSS, HTML, SVG, Markdown and YAML. SVG forces the HTML parser to handle it as markup. Five options are exposed: printWidth, tabWidth, useTabs, semi and singleQuote.
formatOnSave applies during normal saving, only to project files in source. A formatter error does not prevent that save from continuing. Close/quit confirmation paths skip formatting.
Register an external formatter
Declare it globally only. The process receives text on stdin and must return the full document on stdout; stderr is used for diagnostics. It runs without a shell, with a timeout, inheriting process environment and cwd.
- Map .txt to myFormatter in global editor.formatting.byExtension. The executable’s extensions list must support that extension.
- All four fields are required. There is no automatic path interpolation or sandbox. This does not declare new palette commands.
"formatters": {
"external": {
"myFormatter": {
"command": "my-formatter",
"args": ["--stdin"],
"extensions": [".txt"],
"timeoutMs": 5000
}
}
}Chapter sources
Links pinned to the reviewed commit; they do not follow main.