eclipse-jdtls / eclipse.jdt.ls

Java language server
1.8k stars 400 forks source link

JDTLS Doesn't Work Properly On Neovim After Creating New Buffers #2196

Open anthony-S93 opened 2 years ago

anthony-S93 commented 2 years ago

Hello, I'm using JDTLS on Neovim v0.7.2, mostly in single-file mode. I don't need all of JDTLS features, just the basic code completion, diagnostics, etc.

Everything works perfectly as long as I open an existing .java file with neovim:

Works For Existing File

Code completion and diagnostics work as expected whenever I open an exiting java file for editing.

However, problems emerged whenever I created new buffers in the same Neovim instance, say, by running :e NewFile.java

Creating New File

After creating that new buffer, I ran :LspInfo to check if the server was attached:

Server Attached

And as you can see, file detection works and the server was indeed attached and running, yet basic features like diagnostics, suggestions, and autocomplete did not work for that new buffer (NewFile.java)

In the screenshot below, I spelled import halfway and waited for the floating window to appear to no avail.

No Autocomplete

When I switched back to the previous file CurrentFile.java, the server was still functioning normally.

I even tried saving the file first by running :w, but that didn't help also. There are only two ways to get it to function. The first is by closing that buffer and then opening it again with :e NewFile.java (this is just the same as opening an existing file). The second way is by running the LspRestart command followed by LspStart. I've tested it many times, these are the only two ways to make it work.

Here is what LspLog has to say:

[ERROR][2022-08-23 16:59:59] ...lsp/handlers.lua:455    "Aug 23, 2022, 4:59:59 PM Problem with codeComplete for file:///home/anthony93/programming/java/testing/NewFile.java\nRange [3, 7) out of bounds for length 1\njava.lang.StringIndexOutOfBoundsException: Range [3, 7) out of bounds for length 1\n\tat java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55)\n\tat java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52)\n\tat java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)\n\tat java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)\n\tat java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)\n\tat java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:112)\n\tat java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:349)\n\tat java.base/java.lang.String.checkBoundsBeginEnd(String.java:4589)\n\tat java.base/java.lang.String.substring(String.java:2703)\n\tat org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.isCompletionForConstructor(CompletionHandler.java:214)\n\tat org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.computeContentAssist(CompletionHandler.java:117)\n\tat org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.completion(CompletionHandler.java:86)\n\tat org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$5(JDTLanguageServer.java:545)\n\tat org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:75)\n\tat java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:646)\n\tat java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483)\n\tat java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)\n\tat java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)\n\tat java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)\n\tat java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)\n\tat java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)\n"

I'm running jdtls' latest build, which I curled from https://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz I have not done sufficient tests to know whether other builds have the same problem.

lbrayner commented 2 years ago

You're using nvim-lspconfig. I use nvim-jdtls and that is not an issue. Check my config files: ftplugin/java.lua and lua/lbrayner/jdtls.lua.

I start the language server with a buffer local command JdtlsStart, which uses some goodies from nvim-lspconfig.

mfussenegger commented 2 years ago

I think this is a duplicate of https://github.com/eclipse/eclipse.jdt.ls/issues/1815