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

Support source attachments for dependencies

Open fwcd opened this issue 5 years ago • 0 comments

Motivation

Currently the language server stores symbols (i.e. variables, classes, ...) in two locations:

  • The source path, containing the parsed .kt source files from the user's workspace
  • The class path, containing a list of .jar archives that the user's project depends on (e.g. the standard library, dependencies, ...)

If a user decides to lookup a symbol (e.g. by Ctrl-Clicking in his editor), the language server will attempt to locate the source code of the definition. For files on the source path this is straightforward: It just opens the source file in the workspace. For files on the class path (e.g. libraries used by the project) this is a bit trickier, however, since the .jar archives only contain compiled JVM bytecode. To work around this, the language server currently uses a decompiler to provide source code that at least is functionally equivalent to the original definition.

This has a few disadvantages, however:

  • Comments, variable names, documentation, etc. gets lost
  • The structure may not exactly reflect the original code

Since many libraries provide a source jar as well, the question would be, whether we could try to locate the jar and integrate into the current class path.

Tasks

  • Locate the source attachment jar alongside the class path jar
    • Note that this requires Maven/Gradle-specific logic and should ideally be integrated into the ClassPathResolvers
  • Map class path jars to these source attachment jars

Ideas

  • Possible introduce a new data class describing a class path entry with
    • a compiled jar
    • a source attachment
    • possible a doc attachment (in a future issue)

Useful starting points

fwcd avatar Jun 09 '20 02:06 fwcd