Hi,
I started toying with the "Expand selection" (Alt + Shift + Right arrow by default on Linux) feature in VS Code and I noticed some quirks here and there. As usual, I am unsure if this is an HLS or Ghcide issue, sorry :sweat_smile:
To reproduce:
{-# LANGUAGE DataKinds #-}
module Foo where
import Prelude
newtype Foo = Foo {
foo :: String
}
bar :: String -> Foo
bar "" = undefined
bar s = Foo {
foo = s -- start with your cursor on this line, somewhere on the foo field
}
baz :: Bool -> ()
baz _ = ()
When using "Expand selection" feature several times, here's what happens:
foofoo = s -- start with your cursor on this line, somewhere on the foo fieldfoo = s -- start with your cursor on this line, somewhere on the foo field (the left spaces are now included, but Github doesn't display them...)bar (i.e. does not include the empty string case)IMHO 6 is weird, there should be additional steps:
Foo {} expressionAt first I was about to put this down as just a vscode thing but apparently it does use LSP? https://code.visualstudio.com/updates/v1_31#_smart-selections
From what I understand, yes, it relies on LSP. Also, I think it makes sense, since it's really language-dependent to know what token spans are "bigger than/including" smaller token spans. E.g. a language/framework may use an opening bracket { without closing one, and only an LSP server can be aware of that, not VS Code globally
I'm wondering what specific LSP features it uses though, since as far as I'm aware there's no "smart selection" language feature in LSP. Perhaps it's using the semantic highlighting stuff?
@bubba There is now, @maklad championed it for rust-analyzer.
https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange
https://github.com/microsoft/language-server-protocol/issues/613
@Avi-D-coder nice! I think we should be able to implement this seeing as it just looks like a matter of dealing with the parsed ast. Perhaps we can add it at the ghcide level
Most helpful comment
@bubba There is now,
@makladchampioned it for rust-analyzer.https://microsoft.github.io/language-server-protocol/specification#textDocument_selectionRange
https://github.com/microsoft/language-server-protocol/issues/613