Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin LSP crashes if you cd before it starts #3239

Closed
B1kku opened this issue Jul 17, 2024 · 3 comments
Closed

Kotlin LSP crashes if you cd before it starts #3239

B1kku opened this issue Jul 17, 2024 · 3 comments
Labels
question Further information is requested

Comments

@B1kku
Copy link

B1kku commented Jul 17, 2024

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"
@B1kku B1kku added the bug Something isn't working label Jul 17, 2024
@tacascer
Copy link

tacascer commented Aug 4, 2024

Could this be related to fwcd/kotlin-language-server#546 ?

@przybylski
Copy link

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 justinmk added question Further information is requested and removed bug Something isn't working labels Sep 17, 2024
@justinmk
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants