Skip to content

feat: format the files of a workspace for editor extensions with dprint lsp - #1408

Merged
dsherret merged 291 commits into
mainfrom
feat/workspace-editor-service
Nov 16, 2026
Merged

dsherret merged 291 commits into
mainfrom
feat/workspace-editor-service

Conversation

@dsherret

@dsherret dsherret commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Part of #1400. This also includes the commits of #1401, which GitHub shows as merged because they were added to this branch.

This lets an editor extension (dprint-vscode and dprint-intellij) format a whole workspace with one dprint lsp process, which finds the config file of each file itself. Editor extensions use dprint/* methods of the language server through an off-the-shelf JSON-RPC library, so there's one server implementation. Because opening a project isn't the same as choosing to run dprint in it, the server only downloads from untrusted domains, reads files on another machine, or runs process plugins after the user approves it.

The full protocol is in docs/editor-extension-development.md. This description summarizes it and lists what changes for users.

The dprint/* methods

  • An extension sends the dprint experimental capability with the method versions it supports ({ "versions": [1] }), an optional sessionId, and opt-in features.
  • The server responds with:
    • the version it uses;
    • the features it uses of the ones the client sent:
      • fileUri formats a document as another file, ex. a git: document;
      • watchFiles has the server register what it needs watched, for extensions built on a generic language client library;
    • where dprint's own files are (files);
    • the config file names and globs to watch (configFileNames, dotConfigFileNames, configFileGlobs).
  • When there's no common version, it responds with only its versions and a message saying what to update. It advertises nothing else, and the methods fail with -32601. A dprint older than 0.65 has no capability, so the extension falls back to editor service schema 5.
  • Methods:
    • dprint/format, dprint/fileInfo and dprint/configInfo return a result with the config file that was used and a status.
    • dprint/configSchema.
    • dprint/approve, dprint/pendingApprovals, dprint/decisions and dprint/forgetDecisions.
    • dprint/reset.
    • the dprint/configChanged notification.
  • Each result says whether the extension keeps acting as the document's formatter (claim), when and how to show its message (show, severity), and what the user can do (actions). Older extensions then handle reasons added later.
  • Documents aren't synced; the text is sent when formatting. Untitled documents and notebook cells are formatted as a file named after their language.
  • dprint/format takes ranges with UTF-16 positions. A position past the end is the end, and a range that starts after its end is an InvalidParams error.
  • The plain language server keeps working for other clients:
    • it asks about approvals with window/showMessageRequest: Allow/Deny/Always Deny for a download, a proxy, reading from another machine, and process plugins. A client that can't show actions is told to run dprint install instead;
    • what's logged and the progress stay on stderr for it, and only go to an editor extension (window/logMessage and $/progress);
    • it publishes config file problems as diagnostics;
    • for a range format, it gives a plugin that doesn't say whether it formats ranges the range's whole lines.

Config files

  • For each file, the server finds the config file in an ancestor directory like the CLI (including .config and "inherit"), or uses the global config file when the extension asks for that.
  • A config file is identified by its uri and the directory it's used for (dirUri). The global config file has results for each root directory it's used for.
  • The server uses canonical paths internally, but every uri it provides is the editor's path. Examples: a workspace opened through a symlink, a junction, a subst drive, or /tmp on macOS.
    • An alias is checked again for each request that uses it.
    • When an alias stops leading to its directory (ex. a git checkout), the server takes back the diagnostics published through it and sends configChanged. It then uses another path the editor used that still leads there, or else the canonical path.
  • A config file that's a symlink is known by where it was found, not by its target, and it's used for the directory it was found in. Its canonical path goes in watchUris.
  • A config file whose names are in another case on disk is known by the names that were looked up.

Watching

  • The server doesn't watch the workspace. The extension watches the configFileGlobs, the ancestor directories it chooses to, and each result's watchUris, and sends workspace/didChangeWatchedFiles.
    • Watchers must never follow a symlink to another machine. The spec has the exact rules: watch directories rather than files, lstat each directory below the workspace folder, and don't poll with a stat that follows symlinks.
  • With watchFiles, the server registers the canonical directories it needs instead.
  • The server watches dprint's own files itself: the settings file, the approvals file and the global config file. It resolves the used config files again when they change.
  • dprint/configChanged is sent whenever what a config file formats may have changed. The extension gets the results of its known config files and its open documents again.

Approvals

  • Downloads: plugins and extended config files download without asking only from registry.npmjs.org, plugins.dprint.dev, github.com, githubusercontent.com and editor.trustedDomains. That includes each redirect.

  • .npmrc proxies: a proxy set by an .npmrc other than the user's own ~/.npmrc is approved like a download, because it receives every download and the setting's credentials.

  • Network paths: reading a file on another machine is approved like a download (item kind networkPath). Examples:

    • a UNC path;
    • /net or an automounter's directory;
    • a share mount;
    • a symlink that leads to one.

    This covers config files, extended files, .npmrc and .gitignore files, npm packages and plugin files.

    • The server doesn't follow such a path before it's allowed, and it doesn't look above a share's root.
    • A config file found on another machine has onAnotherMachine until it's allowed, so the extension doesn't open it.
  • Process plugins: they aren't sandboxed, so they run only after approval. An approval covers the config file and each plugin with its configuration, unless editor.allowProcessPlugins is true.

    • Until then, nothing is formatted with that config file, not even by its Wasm plugins, so the result matches the CLI.
    • A plugin that isn't set up yet is approved by its trusted configuration, so it isn't run to get its information before it's allowed.
  • Downloads offer allow and alwaysDeny, which are stored in editor-approvals.json as downloadDecisions until forgotten, and deny, which is for the session. An allow is for the exact url or path shown, not its domain (to trust a whole domain, the user adds it to editor.trustedDomains). Process plugins offer alwaysAllow, deny and alwaysDeny, not a session-only allow, because the user would be asked again each session and alwaysAllow only covers the plugins with their current configuration.

  • Text from the project shown in a prompt (paths, urls, specifiers, proxy settings) is escaped, so it can't pretend to be something else.

Security scope

  • Guaranteed: dprint never contacts another machine before the user allows it through anything it does on its own: reading, looking up, canonicalizing, watching and finding config files. That includes what an extension does without the user asking.
  • Best effort: files the user opens themselves, such as clicking a diagnostic or "Open Configuration File". The editor's own file handling follows symlinks too.

Decisions

  • Session decisions are kept per server in a session file (editor-sessions/<id>.json in the cache directory). A server restarted with the same sessionId after a crash asks about the same things.
    • Only the user can read the file (0600), because it may have proxy credentials.
    • A server holds an exclusive lock of <id>.lock for the session. It deletes its file on the exit after shutdown, and files nobody used for a week.
    • A file's process plugin allows only apply when its approvals file fingerprint still matches.
  • Stored decisions (alwaysAllow/alwaysDeny for process plugins) go in editor-approvals.json next to the settings file. Every write takes an exclusive lock of .editor-approvals.lock for the whole read and write. When the lock can't be taken, the decision is only kept for the session and the result says so.
  • The most recent decision wins. A denial wins a tie, and an alwaysDeny stored after a session allow wins whatever the clocks say.
  • dprint/forgetDecisions forgets the decisions of a config file (or all), including stored ones. dprint/decisions lists them.

--config

  • dprint lsp --config <path> uses one local config file for every file. That can be a path, a ~/ path or a file: url.
  • A url or npm: specifier exits with an error at start: the server watches the file and provides it by its path. Extend a remote file from a local one instead.
  • The capability's config file names and globs are empty then. Changes of that file are sent as configChanged without a configFile.

Settings and approvals files

  • settings.json holds editor.allowProcessPlugins, editor.trustedDomains and init. It's only read from the global config directory, never from a project.
  • editor-approvals.json and .editor-approvals.lock live next to it.
  • Their location is pinned for every version:
    • DPRINT_CONFIG_DIR when it isn't empty;
    • otherwise the system config directory + dprint. On macOS that's XDG_CONFIG_HOME, then ~/Library/Application Support when its dprint directory exists, then ~/.config.
  • A golden test checks the resolved paths.
  • Both files are written atomically, through a symlink when one is used (ex. dotfiles). A dangling symlink or a read-only file is refused rather than replaced.

Compatibility

  • Method and capability versions: the client lists what it supports, and the server picks one. Features are opt-in. New fields and values are added so older clients handle them: unknown kinds and reasons have defined fallbacks.
  • Approvals file: version/minVersion.
    • Additions don't raise minVersion; a version that doesn't know them ignores them and keeps them when writing.
    • A narrowing change uses a new configHash version for each allow.
    • A version below minVersion still applies the file's denials, but never writes to it or uses its allows.
    • How config files and plugins are written as keys is pinned.
  • Settings: a property or value in editor that a version doesn't know is only logged with a warning to update dprint, and the rest of the settings are used. So an older version doesn't honor a setting a newer one adds. Only a settings file that can't be read or parsed fails closed: no trusted domains and no stored allows. Properties outside editor are lenient too.
  • Session files: a version number. A server ignores files of versions it can't read, and every version follows the same deletion and lock rules. A golden test pins the format.
  • Approval ids: the same in every server of the same dprint version.

Changes for the CLI

  • Running dprint with a config file allows its process plugins in editors, which is the same as Allow in the prompt: dprint fmt, dprint check, dprint install, dprint config update, and the commands that output what the plugins do (output-resolved-config, output-file-paths, output-format-times, incremental-state). It isn't done in CI (CI is true or 1), and a failure to store it is only logged in debug mode. Once the stored allow is over a minute old, running dprint stores it again with the time of that run, so it's more recent than a Deny made in an editor session since. dprint config add and dprint init allow them too because the user chose the plugins, setting up the process plugins to do so (a failure there is only logged in debug mode). dprint fmt --stdin doesn't, because editor integrations run it without the user choosing to.
  • The same commands allow the editors to read the files on another machine that the config file names (a plugin or a file it extends), because dprint read them. They're stored in editor-approvals.json as networkPathDecisions, each as the exact path with where it resolved to, and forgetting a config file's decisions removes them.
  • dprint clear-cache stops the user's running dprint lsp processes that use the same cache directory and then deletes the whole cache directory, including the session files, so editors start their servers again with nothing from before. A server that uses another cache directory (DPRINT_CACHE_DIR) keeps running.
  • Config discovery doesn't look above the root of a network share or an automounter's directory. On Linux, /net only counts when it's an automounter's.
  • The home directory's .config is an ordinary directory, not a .config directory whose config file applies to its parent.
  • dprint init saves its preferences to the init property of the settings file. It reads init.json while the settings file has none, and leaves it in place for dprint 0.64.
  • An .npmrc proxy setting other than the user's own is ignored with a warning when it isn't the url of a proxy.

Release notes (user-facing changes)

  • Editors using dprint lsp ask before downloading from a domain that isn't trusted, before reading a file on another machine, before using a project's .npmrc proxy, and before running process plugins. Running dprint in a project (ex. dprint fmt, dprint install, dprint config update, dprint config add or dprint init) allows its process plugins, except in CI.
  • New settings file ~/.config/dprint/settings.json (or the platform's equivalent), with editor.trustedDomains, editor.allowProcessPlugins and init.
  • A --config that's a symlink is now used for its own directory, not its target's, in the CLI and in editors.
  • In editors, a remote config file is downloaded at most once while the server runs. A change to it is picked up after a reset or a restart, or once the CLI downloads it again.
  • dprint lsp --config only accepts a local file.
  • dprint clear-cache stops the language servers that use the cache directory, so editors start them again.
  • The language server publishes config file problems as diagnostics. Range formatting gives a plugin that doesn't say whether it formats ranges the range's whole lines, and only applies the changes in them. It reads the new ensureStableFormat and verbose settings.
  • lsp-state.json becomes editor-state.json. What dprint 0.60–0.64 dismissed is still read.
  • init.json is kept for older versions; preferences now live in the settings file.

Known limitations and decisions

  • Prompts, asked-once marks and session decisions belong to one server. Stored decisions are shared through the approvals file.
  • Allowing a download is stored per exact url or path. Trusting a whole domain goes through editor.trustedDomains in the user's settings, so a project can't add it.
  • editor.allowProcessPlugins is a dprint setting rather than an editor setting, because workspace settings can come from the project.
  • A directory the editor knows by several paths is only named by the one it used last. Extensions refresh every open document on configChanged rather than mapping paths.
  • A language client library's own file handling isn't covered by the guarantee: its recursive watching for watchFiles, and how it looks up publishDiagnostics uris. The spec says so.
  • macOS: creating ~/Library/Application Support/dprint later moves the config directory there, leaving ~/.config/dprint unused.
  • A relative DPRINT_CONFIG_DIR is relative to each process's current directory.
  • The server only finds local config files, so a remote or npm config file only appears in dprint/decisions (from running the CLI with one).
  • Editor service schema 6, a binary protocol written earlier in this PR, was replaced by these methods and removed.

…hema version 6 of the editor service

Not choosing an action leaves running the process plugins undecided instead of denying them for the session.
A process plugin is now allowed with its own configuration in the configuration file, so changing the configuration of another plugin or the global configuration doesn't ask again. A plugin that isn't set up yet is allowed to be set up first because its configuration isn't known until then, and it's allowed with its configuration once it is.

Running `dprint fmt` or `dprint config install` with a configuration file allows its process plugins in editors because that's the same as choosing to run them, which replaces `dprint config editor-approve`.

With schema version 6 of the editor service, the install plugins message asks the user to allow the process plugins it installs, which replaces the message to ask again, and a format only asks when the plugins are installed.
Denying a process plugin that isn't set up denies it with any configuration
because its configuration isn't known until then, so neither formatting nor
installing asks about it again, and `Always Deny` stores that.
- The environment checks the download policy before each request, including
  each redirect, so a plugin's config schema url, a redirect, an npm tarball,
  a process plugin's archive, or a registry from an `.npmrc` can't download
  from a domain that isn't trusted without the user allowing it.
- Reading a file on another machine (a UNC path or a `file://` url with a host
  on Windows) needs to be allowed like a download, unless the config file is on
  the same network share.
- Allowing a download only allows what the user was shown, and what that leads
  to (ex. a config file that an allowed one extends) is asked about too.
- Show the url instead of the error message when asking to download a config
  file that a config file extends.
…language server

The editor service's schema version 6 is replaced by `dprint/*` methods of the
language server, which an editor extension uses by providing the `dprint`
experimental capability. They're only sent a document's text when formatting
it, so the server doesn't sync the documents. One implementation formats for
both language clients and editor extensions.

- `dprint/format`, `dprint/fileInfo`, `dprint/configInfo`,
  `dprint/configSchema`, `dprint/approve`, and `dprint/reset`, along with the
  `dprint/configChanged` notification.
- What needs to be approved (downloads from domains that aren't trusted and
  process plugins) is in the results as data, which an editor extension asks the
  user about and approves with `dprint/approve`. The server asks a language
  client's user itself.
- Configuration file problems are published as diagnostics, progress uses
  `$/progress`, and what's logged uses `window/logMessage` for an editor
  extension.
- `dprint/configInfo` has `formatsOtherFiles` instead of the includes,
  excludes, associations, and shebangs, and its plugins are `null` when they
  aren't known.
- Remove `dprint editor-service --info` and `--schema-version`.
- Editors ask to allow process plugins unless `editor.allowProcessPlugins` is
  `true` in the settings file.
- The process plugin decisions to always use are in a versioned
  `editor-approvals.json` file next to the settings file instead of the cache
  directory, so clearing the cache doesn't forget what was denied. Nothing is
  allowed and the file isn't written over when it can't be read, and the oldest
  decisions that allowed a plugin are forgotten first.
- The `editor.trustedDomains` setting adds domains to download from without
  asking, which replaces the `DPRINT_TRUSTED_DOMAINS` environment variable
  because what an editor is started with may come from the project.
@dsherret dsherret changed the title feat: add schema version 6 of the editor service for formatting a whole workspace feat: format the files of a workspace for editor extensions with dprint lsp Oct 29, 2026
The server doesn't watch the file system, so the editor sends
`workspace/didChangeWatchedFiles` for a config file, which has the server
publish its diagnostics and send `dprint/configChanged`. The server registers
it for a language client that supports that.
…another machine

Every other kind of Windows prefix can reach another machine (ex. `\.\UNC\server\share`), a home directory path is checked too, and a path in `/net` is on another machine on macOS.
- Handle up to 64 requests and notifications at the same time instead of 4,
  so a request waiting on a config file's plugins being downloaded doesn't hold
  up the others (ex. a format on save for another config file).
- `workspace/didChangeWatchedFiles` doesn't wait on handling the changes, which
  are handled together after a short delay. Only a config file that was
  resolved before is resolved again, an editor extension is told about the
  others with `dprint/configChanged`, and config files in `node_modules` are
  ignored.
- Changing a config file only shuts down the plugins that no config file uses
  anymore instead of every plugin.
…equest failed

Approving resolves the config file again and returns what's still needed, including a denied approval, so null only means it's ready. An approval that isn't pending anymore is a ContentModified error and a document that can't be formatted is InvalidParams. The approvalRequired reason replaces downloadRequired and processPluginsNotAllowed, and an approval says its config file and the configuration of the process plugins that run.
…e user saw and deny with any configuration

A grant to set up a process plugin is for the trusted configuration of the config file, is only used for a plugin that isn't set up, and is consumed by the approval. Denying a process plugin that's set up denies it with any configuration so that changing it doesn't ask again.
…a config file needs approval

The editor knows what a config file formats while the user needs to approve its plugins, including in a new session, and formatsOtherFiles comes from the config file instead of the resolved plugins.
… the results

The server only shows them to a language client's user because an editor extension knows whether the user made the request.
Approvals are a list, each item is an object with what's known about it, and an approval lists the decisions it accepts. fileInfo and configInfo have a status like a format result, globalConfig says when the global config file is used for a document, a config file says its kind, and dprint/reset takes optional params.
configInfo has globs of the files the plugins may format, the files a config file was resolved from, which the editor watches, and more about each plugin. A document that can't be formatted is a reason it isn't formatted, a stale approval's error has what needs to be approved now, an approval says what was decided before, dprint/pendingApprovals lists the approvals, configSchema says whether it has each plugin's schema, the requests report progress on their token, fileInfo takes the text, null resets a setting, and configChanged says why.
…findings

The editor extension sends the versions it supports and the server responds with the one it uses, or handles it like a language client when it doesn't support any. A config file that fails to resolve keeps what it was resolved from watched and tells the editor once it resolves again (ex. after what it extends was fixed or allowed), associations are made relative to the config file's directory in filePatterns, a deleted or changed config file updates what needs to be approved, a request reports the total progress of what's being done including what started before it, and the config schema is only said to have changed once per config file when a plugin's schema downloaded.
…obal config directory, or a directory above them
…, the global config directory, or a directory above them"

This reverts commit f05f3f2.
@dsherret
dsherret merged commit f2632cc into main Nov 16, 2026
7 checks passed
@dsherret
dsherret deleted the feat/workspace-editor-service branch November 16, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant