fwcd / kotlin-language-server

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

Unresolved reference for all dependencies #487

Open MagnusMG opened 1 year ago

MagnusMG commented 1 year ago

I have a problem with the VSCode editor underlining all names from external dependencies in red, and not being able to give me any suggestions. My guess is that it is the language server that does not find the dependencies. (I have had problems with this before, but I have been able to resolve it.)

The output from the language server can be found here.

How do I debug this? How does the plugin/language server find dependencies? Is there a way to check which external libraries the language server has found? I'm using VSCode 1.81.1 on macos Ventura 13.5 with the Kotlin plugin (fwcd). I have kotlin 1.9.0 and JRE 20.

theothornhill commented 1 year ago

I had the same issue, and built from 3f394167a91c77c46a70721741621c39e646980c, which seems to work. My guess is that there's a regression between that commit and what's on main

Try that if you can, and maybe that helps the maintainers with debugging :)

MagnusMG commented 1 year ago

No luck, but I'm not at all sure that I managed to build the right version of the language server. I am NOT used to github. I had already pulled some version of the source code from from github, so I moved to that directory and ran git checkout 3f39416. After that I and built the whole thing again, with ./gradlew :server:installDist. I already had the path to this local build of the language server in the VSCode Kotlin plugin setting.

How do I know which version I actually built?

themkat commented 1 year ago

Can't reproduce šŸ™ There should be no breaking changes between the commits that @theothornhill mentions above. Might be something I'm overlooking. Have to take a closer look after work.

How does the plugin/language server find dependencies? Is there a way to check which external libraries the language server has found?

It reads the local Maven or Gradle cache, and then reads the jar files directly. Standard library has an extra mechanism that loads it from your Kotlin install if no Maven or Gradle version is found. Don't remember if there is a way to see which it has read. Probably would have to add a logging statement in one of the Classpath resolver classes. You should at least see log entries that dependencies have been fetched by Gradle (or an error message from Gradle if not).

I always build my system using Maven/Gradle before starting the language server just in case. Just to make sure that all dependencies have been downloaded. As the language server reads the Maven and Gradle cache directories directly, I want to make sure that they are present. Might not be necessary, but I'm always paranoid šŸ˜›

How do I know which version I actually built?

With the infrequent releases that happens, I think commit ids are a better indicator. If you have built the specified commit it is 1.3.3 ++++. If you want to try specific versions, then checkout the tags.

@MagnusMG , did using that commit solve the issue for you? Or did you get the same issue?


@MagnusMG, I looked through the logs above. It doesn't seem that the language server recognises your project as a Gradle project. Is the build.grade file in your project root directory? Usually you would see a "Successfully resolved dependencies using Gradle", Gradle error messages or similar.

MagnusMG commented 1 year ago

Thanks for your reply, @themkat. Your observation that the language server did not recognise my project as a gradle project set me off in the right direction: I searched the output log for references to gradle and found the following error message: Gradle error: ERROR: JAVA_HOME is set to an invalid directory: /Users/xgumag/.jenv/versions/system"

So JAVA_HOME was not set correctly. Silly... I fixed that and now it works.

Thanks!

theothornhill commented 1 year ago

That's interesting, because if I jump between the commit i mentioned and latest master I get unresolved references all over the project. I'm using a maven project, if that is interesting.

unclechu commented 10 months ago

Deleting Graddle wrapper seems to fix the issue:

        deleted:    gradle/wrapper/gradle-wrapper.jar
        deleted:    gradle/wrapper/gradle-wrapper.properties
        deleted:    gradlew
        deleted:    gradlew.bat

Iā€™m using Graddle provided by Nix. nix-shell configuration:

{ pkgs ? import (import nix/nixpkgs.github.nix) {}
}:

let
  # Newer version of LSP
  kotlin-language-server = pkgs.kotlin-language-server.overrideAttrs (old: rec {
    version = "1.3.7"; # Latest version (default in ā€œnixpkgs-unstableā€ is 1.3.5)
    src = pkgs.fetchzip {
      url = "https://github.com/fwcd/kotlin-language-server/releases/download/${version}/server.zip";
      hash = "sha256-BEQywg3ZU4LtF9trntGbDp64SIWH4y93o/VVMSRP+cc=";
    };
  });
in

pkgs.mkShell {
  buildInputs = [
    pkgs.kotlin # Compiler/interpreter (also Java/OpenJDK as a dependency)
    kotlin-language-server # LSP
    pkgs.gradle
  ];
}

And the nixpkgs pin:

fetchTarball {
  # # October 25, ā€œrelease-23.05ā€ branch
  # url = "https://github.com/NixOS/nixpkgs/archive/883a9dfd007347f32f7f9893b709d45744435376.tar.gz";
  # sha256 = "0a8qbys41q6sfjp06wh4yaikk9zxkd1z96wqw9rq8x78cy2h8lcn";

  # Fresher versions from unstable
  # October 25, ā€œnixpkgs-unstableā€ branch
  url = "https://github.com/NixOS/nixpkgs/archive/75a52265bda7fd25e06e3a67dee3f0354e73243c.tar.gz";
  sha256 = "0w0dmb0jc8vz678yrh0imfngjdar3d39ab7my4hyzws2pavzdzld";
}