Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LSP range formatting #3209

Open
abusch opened this issue Jul 27, 2022 · 3 comments
Open

Support LSP range formatting #3209

abusch opened this issue Jul 27, 2022 · 3 comments
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements

Comments

@abusch
Copy link

abusch commented Jul 27, 2022

Describe your feature request

Helix supports LSP document formatting (via the :format command, and on save). It would be nice to also support the textDocument/rangeFormatting LSP command to only format a range of lines. rust-analyzer is an example of an LSP server that supports it.

@abusch abusch added the C-enhancement Category: Improvements label Jul 27, 2022
@the-mikedavis the-mikedavis added the A-helix-term Area: Helix term improvements label Jul 27, 2022
@the-mikedavis
Copy link
Member

Quoting relevant implementation discussion from archseer in the matrix space:

It's actually fully implemented in the commands.rs file but it had some issues with multiple selections
The easiest way to do it is to fetch all the formatting changes and apply them in reverse order, starting from the end of the document. That way earlier changes don't change later offsets
But a lsp could emit changes outside that range

@abusch
Copy link
Author

abusch commented Jul 27, 2022

Looking at how vscode handles this, it seems to be something like the following:

  • get the list of ranges corresponding to the multiple selections
  • sort them by their starting position
  • if 2 consecutive ranges intersect or touch each other, merge them into one
  • get the list of edits for each range (from the LSP server)
  • if 2 consecutive ranges result in edits that conflict, merge them and recompute the list of edits for that new range (replacing the 2 conflicting lists of edits).

@johalun
Copy link

johalun commented Dec 19, 2023

+1 for this. I'm working in a big legacy C code base often adding functions or sections of code that I want to format without formatting the whole file. If Helix had this feature I'd be able to switch fully from Emacs to Helix. Don't really care about multiple selections, single selection (of multiple lines) is fine.

matoous added a commit to matoous/helix that referenced this issue Dec 24, 2023
Add basic range formatting capabilities when multiple selection
are present.

Related: helix-editor#3209 (comment)
matoous added a commit to matoous/helix that referenced this issue Dec 24, 2023
Add basic range formatting capabilities when multiple selection
are present.

Related: helix-editor#3209 (comment)
matoous added a commit to matoous/helix that referenced this issue Feb 1, 2024
Add basic range formatting capabilities when multiple selection
are present.

Related: helix-editor#3209 (comment)
matoous added a commit to matoous/helix that referenced this issue Feb 1, 2024
Add basic range formatting capabilities when multiple selection
are present.

Related: helix-editor#3209 (comment)
matoous added a commit to matoous/helix that referenced this issue Feb 1, 2024
Add basic range formatting capabilities when multiple selection
are present.

Related: helix-editor#3209 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements
Projects
None yet
Development

No branches or pull requests

3 participants