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

General override member(s) functionality

Open themkat opened this issue 3 years ago • 0 comments
trafficstars

General info

Override any member that is currently not implemented in the current class. This includes open functions, functions with default implementations, open members, abstract stuff etc. The main difference here is that this is general override member functionality, NOT JUST abstract members like the quick fix does. This is super useful for cases where you need to override a default implementation (e.g toString, Thread run, lsp4j interface methods like in TextDocumentService etc.), NOT just the unimplemented abstract ones. For me it would be super useful for my day job using Kotlin 😄 Having to google api docs to find signatures are a pain in the ass just for doing simple stuff like this.

Two small issues:

  • Implicit Any/Object methods does not seem to work. I can't really figure out why. The methods from them show up if the class has at least one superclass. Unsure on how to solve this, there are a TODO in the code at a relevant place.
  • No support for empty class bodies (i.e, no brackets). Not sure how to solve that. Probably not super important either.

I think these are very minor. Just having this functionality in place would at least make me more productive using the language server 😄

The quick fix for abstract methods and this new functionality, share a lot of code. I've moved most of the code to the override-package, as that was the most logical place to put it.

Fixes #359

This is a new protocol extension, so each lsp-client will need to have an implementation to use it. I've only done one for Emacs so far, and speaking of...

Emacs screenshots

Running lsp-kotlin-override-members on MyClass (notice that multiple selections are possible!): image

When we click enter: image (yes, it is the same sample project I often use for screenshot. A boring Spring Boot demo app)

Yes, it works for external interfaces and open classes as well, don't worry 🙂 There is an example of JDK Thread in the tests (in this PR, not in Emacs)

Emacs client implementation (lsp-mode): https://github.com/themkat/lsp-mode/blob/kotlin_overrides/clients/lsp-kotlin.el#L224

Will make a PR for it once this PR has been merged. Just in case something changes.

~Will see if I can find the time to make a VSCode version or not. If not, I will make an issue in the vscode-kotlin repo with enough details to get someone else started~ 🙂 Really want to work on either Type hierarchy or Javadoc for Kotlin SDK and the JDK instead 😛

EDIT: Made a VSCode version, as I was bored after work yesterday: https://github.com/fwcd/vscode-kotlin/pull/104

themkat avatar Aug 04 '22 15:08 themkat