feat(format): external formatting with managed Prettier (#671)

Reformat Code only asked the language server for formatting, so files whose server has no formatting capability (Markdown with marksman, and others depending on the server) could not be formatted.

Languages can now declare an external formatter. Prettier is the first: a managed tool installed on demand, or the project's own node_modules/prettier, an explicit path, or PATH. It runs on the backend copy of the document with the file's path so Prettier resolves the project's config, overrides and ignore files, and its result is applied as one undoable edit. Language servers that format a file keep doing so unless Prettier is preferred in Settings › Languages › Prettier; formatting on save is opt-in. Parsers without range support format the whole file and say so.

Errors carry structured tool data, so a missing Prettier reuses the shared install prompt and Prettier diagnostics or timeouts show as non-sticky notifications.

Fixes #639
This commit is contained in:
l0ng-ai
2026-11-01 16:54:31 +08:00
committed by GitHub
parent 9bb44cbeb3
commit ec5193f827
49 changed files with 1111 additions and 29 deletions
+1
View File
@@ -1,5 +1,6 @@
id = "javascriptreact"
name = "JavaScript JSX"
formatter = { tool = "prettier", parser = "babel", range = true }
extensions = ["jsx"]
line-comment = "//"
block-comment = ["/*", "*/"]