Repository navigation
feat: let plugins say whether they format a range - #1422
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #1408.
dprint-core (0.75.0)
PluginInfo::supports_range_formatting: Option<bool>, which is skipped when serializingNoneand defaults toNone, 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/rangeFormattingformats 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).Nonefrom 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
supportsRangeFormattingin their plugin info.