openscad-LSP
openscad-LSP copied to clipboard
fix: hover on incorrect node
Bug description
When hovering on the first letter of an identifier, it`d often show nothing.
Steps to reproduce
- Create a new scad file
- open it in your editor, and write
batata = 10;
cube(batata);
- 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
I test it on VSCode on Mac, and can't reproduce it.
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.
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.