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

Extension fails on Ubuntu devcontainer - couldn't create connection to server. #564

Open spaceunifyfifty opened 4 months ago

spaceunifyfifty commented 4 months ago

I am attempting to write Kotlin code within GitHub Codespaces, which are just remote ubuntu virtual machines viewed through the web client for vscode. I have tried doing this both for an empty folder structure containing only a Main.kt hello world with no Gradle/Maven, and for a pre-existing Gradle project that works on my local machine that I push up to GitHub and create the codespace from; both result in the Kotlin extension giving the error

Kotlin Language Client client: couldn't create connection to server.

resulting in no IDE hints / Intellisense.

When I go to the output, the following snippets seem most notable to me

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Caused by: org.javacs.kt.util.KotlinLSException: No repositories found at $MAVEN_REPOSITORY, $MAVEN_HOME, $M2_HOME or $HOME/.m2` seems most relevant.
[Error] Kotlin Language Client client: couldn't create connection to server.
  Message: Internal error.
  Code: -32603 

Here is a gist of the full console output.

Has anyone been able to get Kotlin language server in vscode working on a devcontainer / GitHub codespace?

Reproduce steps

  1. Create a new github repository containing an empty README.md
  2. Create new codespace from repository on main branch, with default specs 2-core, 8GB RAM, 32GB.
  3. Confirm that Java is installed
    /workspaces/testkotlin (main) $ java --version
    openjdk 21.0.2 2024-01-16 LTS
    OpenJDK Runtime Environment Microsoft-8905927 (build 21.0.2+13-LTS)
    OpenJDK 64-Bit Server VM Microsoft-8905927 (build 21.0.2+13-LTS, mixed mode, sharing)
  4. Install kotlin compiler
    
    /workspaces/testkotlin (main) $ sdk install kotlin

Downloading: kotlin 1.9.22 In progress... ################################################################################################################################################ 100.0% Installing: kotlin 1.9.22 Done installing! Setting kotlin 1.9.22 as default.

5. Install Kotlin extension. Click `Ok, Continue` on dependency installation prompt
<img width="450" alt="image" src="https://github.com/fwcd/kotlin-language-server/assets/158013953/db4a546d-a911-4086-aa71-c8edb5fc0c51">

6. Create a `Main.kt` file
```kt
fun main() {
    println("Hello world")
}

Observe error notice

image
spaceunifyfifty commented 4 months ago

Found this repo https://github.com/alexanderhansen/vscode-remote-try-kotlin, everything works when I create a codespace from it. What is his repo doing right that mine is not?

fwcd commented 4 months ago
Caused by: org.javacs.kt.util.KotlinLSException: No repositories found at $MAVEN_REPOSITORY, $MAVEN_HOME, $M2_HOME or $HOME/.m2` seems most relevant.

looks suspicious, the SLF4J stuff is fine (should probably add a troubleshooting entry on that). We probably should not be throwing an exception if we cannot find a local Maven repository (maybe make it optional instead?):

https://github.com/fwcd/kotlin-language-server/blob/7dd4680017d7f04f621fbb952988a78b7dca581e/shared/src/main/kotlin/org/javacs/kt/classpath/Home.kt#L20C14-L24

Note that support for non-Gradle/Maven projects isn't great yet, mostly because there are so many different ways Kotlin and its standard library could be packaged.

dmccoystephenson commented 2 months ago

I am also running into this error when attempting to use this plugin inside of a dev container with VSCode. I am using eclipse-temurin:17-jdk-jammy as a base image.

Here is the relevant output from the console:

[Error - 3:09:03 AM] Kotlin Language Client client: couldn't create connection to server. Message: Internal error. Code: -32603 java.util.concurrent.CompletionException: java.lang.ExceptionInInitializerError at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315) at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:840) Caused by: java.lang.ExceptionInInitializerError at org.javacs.kt.classpath.BackupClassPathResolverKt.findLocalArtifactDirUsingMaven(BackupClassPathResolver.kt:88) at org.javacs.kt.classpath.BackupClassPathResolverKt.findLocalArtifact(BackupClassPathResolver.kt:25) at org.javacs.kt.classpath.BackupClassPathResolverKt.findKotlinStdlib(BackupClassPathResolver.kt:21) at org.javacs.kt.classpath.WithStdlibResolverKt.wrapWithStdlib(WithStdlibResolver.kt:42) at org.javacs.kt.classpath.WithStdlibResolverKt.access$wrapWithStdlib(WithStdlibResolver.kt:1) at org.javacs.kt.classpath.WithStdlibResolver.getBuildScriptClasspath(WithStdlibResolver.kt:10) at org.javacs.kt.classpath.FirstNonEmptyClassPathResolver.getBuildScriptClasspath(ClassPathResolver.kt:76) at org.javacs.kt.classpath.CachedClassPathResolver.getBuildScriptClasspath(CachedClassPathResolver.kt:132) at org.javacs.kt.classpath.ClassPathResolver$DefaultImpls.getBuildScriptClasspathOrEmpty(ClassPathResolver.kt:24) at org.javacs.kt.classpath.CachedClassPathResolver.getBuildScriptClasspathOrEmpty(CachedClassPathResolver.kt:52) at org.javacs.kt.CompilerClassPath.refresh(CompilerClassPath.kt:75) at org.javacs.kt.CompilerClassPath.refresh$default(CompilerClassPath.kt:47) at org.javacs.kt.CompilerClassPath.addWorkspaceRoot(CompilerClassPath.kt:120) at org.javacs.kt.KotlinLanguageServer$initialize$1.invoke(KotlinLanguageServer.kt:129) at org.javacs.kt.KotlinLanguageServer$initialize$1.invoke(KotlinLanguageServer.kt:74) at org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ... 3 more Caused by: org.javacs.kt.util.KotlinLSException: No repositories found at $MAVEN_REPOSITORY, $MAVEN_HOME, $M2_HOME or $HOME/.m2 at org.javacs.kt.classpath.HomeKt.(Home.kt:22) ... 20 more