openscad-LSP icon indicating copy to clipboard operation
openscad-LSP copied to clipboard

fix: hover on incorrect node

Open Jeansidharta opened this issue 1 year ago • 3 comments

Bug description

When hovering on the first letter of an identifier, it`d often show nothing.

Steps to reproduce

  1. Create a new scad file
  2. open it in your editor, and write
batata = 10;
cube(batata);
  1. Hover on the first letter of the word batata.

Tested on Neovim v0.9.4

Logs

Here are my LSP logs for the request/response:

[DEBUG][2023-12-16 00:30:19] .../vim/lsp/rpc.lua:284    "rpc.send"      {
  id = 3,
  jsonrpc = "2.0",
  method = "textDocument/hover",
  params = {
    position = {
      character = 5,
      line = 1
    },
    textDocument = {
      uri = "file:///home/username/batata.scad"
    }
  }
}
[DEBUG][2023-12-16 00:30:19] .../vim/lsp/rpc.lua:387    "rpc.receive"   {
  id = 3,
  jsonrpc = "2.0"
}

The solution ?

I have no idea why this is happening. The tree_sitter function goto_first_child_for_point (docs) is simply returning earlier than it should for the Point. My solution is just a simple hack that should fix most/all cases

Jeansidharta avatar Dec 16 '23 05:12 Jeansidharta

I test it on VSCode on Mac, and can't reproduce it.

Leathong avatar Jan 12 '24 04:01 Leathong

I am using emacs lsp-mode and see the same behaviour as @Jeansidharta (using openscad-lsp v1.2.5). Put your cursor on the cube([b]atata) and no hover shows (and you also cannot jump to definition). Move one character to the right (cube(b[a]tata)) and both hover and jump to defn work fine.

If you instead have cube(size = batata);, having cursor on the first b works just fine.

Lenbok avatar Jan 18 '24 01:01 Lenbok

I reproduced this bug, but it has little impact on usage. This workaround maybe cause other problem, so I won't merge it for now.

Leathong avatar Jan 31 '24 02:01 Leathong