kotlin-language-server
kotlin-language-server copied to clipboard
Implement textDocument/documentHighlight
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):

...and with arguments being highlighted:

...and a class highlighted:

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:

..and
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 😆
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!
Looks good, thank you very much!