kotlin-language-server icon indicating copy to clipboard operation
kotlin-language-server copied to clipboard

Implement textDocument/documentHighlight

Open themkat opened this issue 3 years ago • 1 comments

Really missed this in the Kotlin language server after programming Rust (using rust-analyzer) for a while. Having the same variable highlighted is super useful 🙂

Fixes #208

Basic info

Think I've covered most of the weird edge cases with the unit tests. Also tested manually using Emacs (lsp-mode). One example of how it looks with a global variable being highlighted (the blue'ish): image

...and with arguments being highlighted: image

...and a class highlighted: image

I think you get the point 🙂

Tried to re-use as much existing functionality as possible to make the code small and simple. Feel free to suggest any improvements if you find any. Know we have a bit different coding styles and stuff 🙂

Possible edge case

One weird thing I found: Hovering builtin symbols (e.g, println and Exception) and comments seems to just mark the containing function (or the nearest class or similar symbol it is commenting). I did not find this to be much of an inconvenience, so if you don't hate it either I suggest we just keep it. Unless you have a possible solution, then I'm all ears 🙂

Looks like this: image

..and

image

What is not supported (possible future work?)

  • Highlighting an imported symbol from the import list and in the file. Currently nothing happens when you hover the import list. If you hover the symbol in the file, it only highlights the occurences that are not in the import-list. Unsure how to solve this.

Hope you are not tired of PRs from me 😆

themkat avatar Sep 19 '22 18:09 themkat

Wow, this looks really useful, thanks! I'm actually a bit surprised, we didn't have this before, AFAIK VSCode performs a slightly less intelligent/non-semantic variant of this highlighting already.

Will review once I find some time, I absolutely appreciate your work on this project though, very happy to see people interested in this project!

fwcd avatar Sep 19 '22 20:09 fwcd

Looks good, thank you very much!

fwcd avatar Oct 03 '22 14:10 fwcd