eclipse / lsp4e

Language Server Protocol support in Eclipse IDE
Eclipse Public License 2.0
62 stars 54 forks source link

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

Open travkin79 opened 12 hours ago

travkin79 commented 12 hours ago

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 commented 12 hours ago

See https://github.com/eclipse/lsp4e/blob/e3404b4cb632c261d5a7c217a96124a83084c168/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/format/LSPFormatter.java#L58-L67

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.