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

Formatting selected code doesn't work anymore, the whole file is formatted instead #1127

Open
travkin79 opened this issue Oct 1, 2024 · 1 comment

Comments

@travkin79
Copy link
Contributor

Issue
If you select some text in an LSP-based text editor and then you use the shortcut for formatting code (Ctrl + Shift + F on PCs), then the whole file is formatted instead of formatting the selected text only.

@travkin79
Copy link
Contributor Author

travkin79 commented Oct 1, 2024

See

return executor.computeFirst((w, ls) -> w.getServerCapabilitiesAsync().thenCompose(capabilities -> {
if (textSelection.getLength() == 0 && isDocumentRangeFormattingSupported(capabilities)
&& !(isDocumentFormattingSupported(capabilities))) {
return ls.getTextDocumentService().rangeFormatting(rangeParams)
.thenApply(edits -> new VersionedEdits(modificationStamp, edits, document));
} else {
return ls.getTextDocumentService().formatting(params)
.thenApply(edits -> new VersionedEdits(modificationStamp, edits, document));
}
}));

According to this code, the range parameters (the given text selection) are only used if the LS does not support document formatting and if the text selection has length 0. That does not make sense to me.

It seems the last change on LSPFormatter accidentally changed the conditions.

travkin79 added a commit to travkin79/lsp4e that referenced this issue Oct 1, 2024
travkin79 added a commit to travkin79/lsp4e that referenced this issue Oct 1, 2024
travkin79 added a commit to travkin79/lsp4e that referenced this issue Oct 2, 2024
Also adapt mock server to support range formatting and
add tests.
rubenporras pushed a commit that referenced this issue Oct 3, 2024
* Fix selective formatting (#1127)

Also adapt mock server to support range formatting and
add tests.

* Bump versions
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

No branches or pull requests

1 participant