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

LSP range formatting converts indentation to tabs, inconsistent with full-file format #11085

Closed
cumber opened this issue Jul 4, 2024 · 3 comments · Fixed by #11169
Closed
Labels
A-language-server Area: Language server client C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR

Comments

@cumber
Copy link

cumber commented Jul 4, 2024

When I format with :format (or auto-format on save), I get spaces for indentation. But when I format a selection using =, the spaces are replaced by tabs.

By running with hx -v and watching the log, I see this when I use :format:

2024-07-04T15:25:04.568 helix_lsp::transport [INFO] vscode-json-language-server -> {"jsonrpc":"2.0","method":"textDocument/formatting","params":{"options":{"insertSpaces":true,"tabSize":2},"textDocument":{"uri":"file:///tmp/foo.json"}},"id":7}

And this when I press =:

2024-07-04T15:25:26.418 helix_lsp::transport [INFO] vscode-json-language-server -> {"jsonrpc":"2.0","method":"textDocument/rangeFormatting","params":{"options":{"insertSpaces":false,"tabSize":0},"range":{"end":{"character":1,"line":3},"start":{"character":0,"line":0}},"textDocument":{"uri":"file:///tmp/foo.json"}},"id":8}

It seems the :format command is sending the options {"insertSpaces":true,"tabSize":2} to the LSP, while the = command is sending {"insertSpaces":false,"tabSize":0}.

I was trying to search around for whether this was just something I needed to configure separately for some reason, but although I don't really know Rust it seems to me that the problem is here:

.text_document_range_formatting(
doc.identifier(),
range,
lsp::FormattingOptions::default(),
None,

This is (I think) just passing the default value for lsp::FormattingOptions regardless of configuration, as opposed to what I see here:

let request = language_server.text_document_formatting(
self.identifier(),
lsp::FormattingOptions {
tab_size: self.tab_width() as u32,
insert_spaces: matches!(self.indent_style, IndentStyle::Spaces(_)),
..Default::default()
},

Where it seems to be using Helix's settings for indentation to set those parameters.

(I'm observing this with vscode-json-language-server, but the issue doesn't seem to be related to the particular LSP server)

@pascalkuthe
Copy link
Member

good catch, please send a PR for that!

@the-mikedavis the-mikedavis added C-bug Category: This is a bug A-language-server Area: Language server client labels Jul 5, 2024
@kirawi kirawi added E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR labels Jul 13, 2024
@arcofx
Copy link
Contributor

arcofx commented Jul 14, 2024

As there is no PR for this issue, I'm going to submit one.

@cumber
Copy link
Author

cumber commented Jul 16, 2024

Thanks @arcofx for covering this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors E-has-instructions Call for participation: Has instructions for fixing the issue and opening a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants