From 85e9cf90214294102a2459ee013c7c636891e887 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Sun, 18 Oct 2026 13:06:57 +0530 Subject: [PATCH] docs(editor-languages): document register options and formatAs --- docs/utilities/ace-modes.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/utilities/ace-modes.md b/docs/utilities/ace-modes.md index 0718909..a53cf44 100644 --- a/docs/utilities/ace-modes.md +++ b/docs/utilities/ace-modes.md @@ -11,7 +11,7 @@ const editorLanguages = acode.require("editorLanguages"); ## Methods -### `register(name, extensions, caption?, loader?)` +### `register(name, extensions, caption?, loader?, options?)` Registers a language mode. @@ -19,6 +19,10 @@ Registers a language mode. - `extensions`: String or string array (without `.`), for example `"mymode"` or `["mymode", "mym"]`. - `caption` (optional): Label shown in UI. - `loader` (optional): Function returning a CodeMirror extension (or a Promise resolving to one). +- `options` (optional): + - `aliases`: other names that resolve to this mode. + - `filenameMatchers`: `RegExp[]` matched against file names. + - `formatAs`: name of a mode whose formatter this mode reuses. See [Formatting](#formatting). ```javascript const editorLanguages = acode.require("editorLanguages"); @@ -43,6 +47,29 @@ const editorLanguages = acode.require("editorLanguages"); editorLanguages.unregister("myMode"); ``` +## Formatting + +A new mode has no formatter, and the built-in Prettier doesn't know its name. If your language is a variant of an existing one, set `formatAs` to reuse that mode's formatter: + +```javascript +editorLanguages.register( + "json-bedrock", + ["jsonbe"], + "JSON (Bedrock)", + loadBedrockLanguage, + { formatAs: "json" }, // [!code focus] +); +``` + +When the user formats a `json-bedrock` file: + +- Acode uses the formatter chosen for `json-bedrock` in **Settings → Formatter**, or the one chosen for `json` if there is none. +- Prettier formats it with the `json` parser. + +In **Settings → Formatter**, the "JSON (Bedrock)" row shows the inherited formatter, for example "Prettier (JSON)", and its picker also lists the formatters available for `json`. Picking one there overrides the inherited choice. This works with any formatter, not only Prettier. + +Older Acode versions ignore `formatAs`, so passing it is safe; the mode just has no formatter there. + ## Apply A Mode To Active File ```javascript