neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
10.34k stars 2.05k forks source link

Kotlin LSP crashes if you cd before it starts #3239

Open B1kku opened 2 months ago

B1kku commented 2 months ago

Description

Hi there, I've noticed the kotlin_language_server crashes if you cd before opening a kotlin project, so for example, start neovim at ~, do :cd KotlinProject, so ~/KotlinProject open any KT file (I've only tested on gradle projects tho), proceeds to give an error. It works fine if you don't do that.

Doesn't happen to any other LSP that I've used, it turns pretty annoying specially if you use a sessions plugin or something similar.

I've fixed it by changing the default init_options.storagePath to

  init_options = {
    storagePath = fn.resolve(fn.stdpath("cache") .. "/kotlin_language_server")
  }

But I'm unsure why this happens, or if it's a good fix.

Lsp Log:

[START][2024-07-18 00:41:18] LSP logging initiated
[ERROR][2024-07-18 00:41:18] .../vim/lsp/rpc.lua:734    "rpc"   "/nix/store/f3ca6sj3jyr97axdvs04i10blndi9jic-kotlin-language-server-1.3.9/bin/kotlin-language-server"   "stderr"    'SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".\n'
[ERROR][2024-07-18 00:41:18] .../vim/lsp/rpc.lua:734    "rpc"   "/nix/store/f3ca6sj3jyr97axdvs04i10blndi9jic-kotlin-language-server-1.3.9/bin/kotlin-language-server"   "stderr"    "SLF4J: Defaulting to no-operation (NOP) logger implementation\nSLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.\n"
[ERROR][2024-07-18 00:41:19] .../vim/lsp/rpc.lua:734    "rpc"   "/nix/store/f3ca6sj3jyr97axdvs04i10blndi9jic-kotlin-language-server-1.3.9/bin/kotlin-language-server"   "stderr"    "Jul 18, 2024 12:41:19 AM org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint lambda$recursiveFindRpcMethods$2\nSEVERE: A delegate object is null, jsonrpc methods of 'public default org.eclipse.lsp4j.services.NotebookDocumentService org.eclipse.lsp4j.services.LanguageServer.getNotebookDocumentService()' are ignored\n"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "main      A delegate object is null, jsonrpc methods of 'public default org.eclipse.lsp4j.services.NotebookDocumentService org.eclipse.lsp4j.services.LanguageServer.getNotebookDocumentService()' are ignored"
[ERROR][2024-07-18 00:41:19] .../vim/lsp/rpc.lua:734    "rpc"   "/nix/store/f3ca6sj3jyr97axdvs04i10blndi9jic-kotlin-language-server-1.3.9/bin/kotlin-language-server"   "stderr"    "Jul 18, 2024 12:41:19 AM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint fallbackResponseError\nSEVERE: Internal error: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $\njava.util.concurrent.CompletionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $\n\tat java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)\n\tat java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)\n\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)\n\tat java.base/java.lang.Thread.run(Thread.java:1583)\nCaused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $\n\tat com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:270)\n\tat com.google.gson.Gson.fromJson(Gson.java:1058)\n\tat com.google.gson.Gson.fromJson(Gson.java:1129)\n\tat com.google.gson.Gson.fromJson(Gson.java:1101)\n\tat org.javacs.kt.ConfigurationKt.getStoragePath(Configuration.kt:64)\n\tat org.javacs.kt.KotlinLanguageServer$initialize$1.invoke(KotlinLanguageServer.kt:97)\n\tat org.javacs.kt.KotlinLanguageServer$initialize$1.invoke(KotlinLanguageServer.kt:74)\n\tat org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)\n\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)\n\t... 3 more\nCaused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $\n\tat com.google.gson.internal.bind.JsonTreeReader.expect(JsonTreeReader.java:163)\n\tat com.google.gson.internal.bind.JsonTreeReader.beginObject(JsonTreeReader.java:88)\n\tat com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:259)\n\t... 11 more\n\n"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "async0    Internal error: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "java.util.concurrent.CompletionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat java.base/java.lang.Thread.run(Thread.java:1583)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:270)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat com.google.gson.Gson.fromJson(Gson.java:1058)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat com.google.gson.Gson.fromJson(Gson.java:1129)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat com.google.gson.Gson.fromJson(Gson.java:1101)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat org.javacs.kt.ConfigurationKt.getStoragePath(Configuration.kt:64)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat org.javacs.kt.KotlinLanguageServer$initialize$1.invoke(KotlinLanguageServer.kt:97)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat org.javacs.kt.KotlinLanguageServer$initialize$1.invoke(KotlinLanguageServer.kt:74)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat org.javacs.kt.util.AsyncExecutor.compute$lambda$2(AsyncExecutor.kt:19)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\t... 3 more"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at path $"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat com.google.gson.internal.bind.JsonTreeReader.expect(JsonTreeReader.java:163)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat com.google.gson.internal.bind.JsonTreeReader.beginObject(JsonTreeReader.java:88)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\tat com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:259)"
[ERROR][2024-07-18 00:41:19] ...lsp/handlers.lua:535    "\t... 11 more"
tacascer commented 1 month ago

Could this be related to https://github.com/fwcd/kotlin-language-server/issues/546 ?

przybylski commented 21 hours ago

I had the same issue, but the solution was quite obvious. When I was opening a dir rather then a file i did not had the gradle file in the CWD, opening the file itself or the project root director fixes the problem.

In may case it was a React Native project which has gradle files in the android/ subdirectory.

I'm sure that there is a nice way to set root_dir configuration to detect the proper root with gradle or other build system

justinmk commented 14 hours ago

Surely this is a bug in the kotlin server? What is needed from nvim-lspconfig, which is just a collection of data?