Haskell-language-server: Expand selection weird behaviors

Created on 20 Jul 2020  路  5Comments  路  Source: haskell/haskell-language-server

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:

  1. Selects foo
  2. Selects foo = s -- start with your cursor on this line, somewhere on the foo field
  3. Selects foo = 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...)
  4. Selects everything between the brackets excluded (including new lines)
  5. Selects everything between the brackets included
  6. :boom: Selects the pattern case of bar (i.e. does not include the empty string case)
  7. :boom: Selects the whole file

IMHO 6 is weird, there should be additional steps:

  • Between 5 and 6: Select the whole Foo {} expression
  • TBD: Between 6 and 7: Select the whole implementation but not the signature (I am much less opinionated on this one)
  • Between 6 and 7: Select the whole implementation, including the signature
  • Between 6 and 7: Select all declarations (types, functions, etc.) but not imports
  • Between 6 and 7: Select all declarations (types, functions, etc.) and imports, but not module declaration
enhancement

Most helpful comment

All 5 comments

At 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?

@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

Was this page helpful?
0 / 5 - 0 ratings