Skip to content

feat: let plugins say whether they format a range - #1422

Merged
dsherret merged 2 commits into
mainfrom
feat/plugin-range-formatting
Nov 2, 2026
Merged

dsherret merged 2 commits into
mainfrom
feat/plugin-range-formatting

Conversation

@dsherret

@dsherret dsherret commented Nov 2, 2026

Copy link
Copy Markdown
Member

Split out of #1408.

dprint-core (0.75.0)

  • PluginInfo::supports_range_formatting: Option<bool>, which is skipped when serializing None and defaults to None, so existing plugins and plugin caches keep working.
  • SingleThreadMessageWriter::flush, which waits for the messages that were sent to be written (ex. before exiting the process).

Range formatting in the language server

How textDocument/rangeFormatting formats depends on what the plugins that format the file say:

  • Some(true) from every plugin: the plugin is given the range as it is and decides what to format around it (ex. the nodes it overlaps).
  • None from any plugin: the plugin is given the range expanded to whole lines, and only the edits within those lines are kept, because many plugins don't format a range and would otherwise format the whole document.
  • Some(false) from any plugin: the range isn't formatted. This is logged rather than shown, because a client may format a range without the user asking (ex. on paste), and shown when the user runs the "format selection with the global config" command.

The editor service (schema 5) still passes the range to the plugin as before.

Release notes

  • Plugins can say whether they format a range with supportsRangeFormatting in their plugin info.
  • The language server formats a range with a plugin that doesn't say by giving it the range's whole lines and only applying the changes in them.

Add `supports_range_formatting` to `PluginInfo`, which bumps dprint-core
to 0.75.0, and use it to decide how the language server formats a range:

- `Some(true)` - Give the plugin the range as it is and keep what it
  formats, because it knows what to format around it (ex. the nodes it
  overlaps).
- `None` - Give the plugin the range expanded to whole lines and only keep
  the edits within those lines, because many plugins don't format a range.
- `Some(false)` - Don't format a range with the plugin and say that it
  doesn't support it.

This also adds `SingleThreadMessageWriter::flush` to dprint-core for
waiting for the messages that were sent to be written.
@dsherret
dsherret merged commit 4be4592 into main Nov 2, 2026
5 checks passed
@dsherret
dsherret deleted the feat/plugin-range-formatting branch November 2, 2026 00:18
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