fwcd / kotlin-language-server

Kotlin code completion, diagnostics and more for any editor/IDE using the Language Server Protocol
MIT License
1.58k stars 202 forks source link

Extend "Add missing import" code action to suggest "static methods"/functions #528

Open themkat opened 7 months ago

themkat commented 7 months ago

Currently, the code action for adding missing imports only suggests classes. Often we might want to statically import a Java static method or similar. Those are currently not suggested by the code action. Worked a lot with some static helper methods in a library at work today, so it bothered me enough to create an issue 😛 If nothing else, then as a wishlist item.

Example: We have written the code currentThread() in our editor, and naturally we get an error. Neither the completion (when we wrote it) or the code action (after writing) suggests anything. One possible suggestion would be to import java.lang.Thread.currentThread (aka the static method currentThread).

Unsure on how to solve this. The easiest solution would probably be to put the static methods in the symbol index as well, as we would easily query it that way. The initialization of the server is already slow and consume a lot of memory, so I'm a little bit hesitant to implement it that way. Please let me know if anyone have any suggested solutions 🙂

This is probably true for the completion functionality as well.