emacs-lsp / lsp-java

lsp-mode :heart: java
https://emacs-lsp.github.io/lsp-java
GNU General Public License v3.0
650 stars 90 forks source link

jdtls checks/indexes all files and directories in all partitions and disks #285

Open asif-mahmud opened 4 years ago

asif-mahmud commented 4 years ago

Sorry if i sound too noob, but i can't find a solution of what i am facing about setting up lsp-java. My setup environment is as follows -

OS: Archlinux 64 bit
JDK: OpenJDK 11
Emacs: Version 27.1

I have been using use-package to load/configure all of the packages, and it is configured to ensure and defer all packages. Every other package works just fine. Here is my lsp-java config block -

(use-package lsp-java
  :init
  (setq lsp-java-jdt-download-url  "https://download.eclipse.org/jdtls/milestones/0.57.0/jdt-language-server-0.57.0-202006172108.tar.gz"))

After running lsp-install-server -> jdtls, lsp seems to install jdtls just fine.

Now if i open a standalone java file (not part of any project like maven or gradle), even if i open a maven project, it doesn't really matter, emacs hangs for a few seconds, then jdtls is connected, then jdtls seems to scan/index all and everything in all of my harddisks and partitions. That takes about a few minutes obviously, although i don't know why thats even necessary. But afterwards i see no auto-completion or any other feature that i would have expected from lsp-java. If it helps in anyway i am attaching my *lsp-log* partially, its too long to attach fully here. Here it is when jdtls says its ready [serverReady], and i am trying to edit the code -

Index out of bounds
Java Model Exception: Java Model Status [Index out of bounds]
    at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:163)
    at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:388)
    at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:381)
    at org.eclipse.jdt.ls.core.internal.JDTUtils.findElementsAtSelection(JDTUtils.java:719)
    at org.eclipse.jdt.ls.core.internal.JDTUtils.findElementAtSelection(JDTUtils.java:706)
    at org.eclipse.jdt.ls.core.internal.text.correction.SourceAssistProcessor.getSourceActionCommands(SourceAssistProcessor.java:101)
    at org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler.getCodeActionCommands(CodeActionHandler.java:164)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$14(JDTLanguageServer.java:619)
    at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:74)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
    at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

I know the log message is jdtls related issue, not specific to lsp-java, but what about the first issue about scanning everything.

So, if you have encountered similar issue and have a fix please share, if not, please share how you setup lsp-java in more details so i or anyone else coming to this page can find a guide for a complete working setup.

NOTE I have tried emacs -Q -l minimal-java.el where the minimal-java.el has the exact config from the readme file of the repo. Also i tried OpenJDK 9, OpenJDK 14, Oracle JDK 8, Oracle JDK 15. Everytime i cleaned .emacs.d, reinstalled jdtls and tried editing a java file. Same issue always. I don't have JAVA_HOME set, cause system default java is set to point to jdk install properly.

asif-mahmud commented 4 years ago

I have installed Oracle JDK 15, compiled jdtls release 0.63 and copied the org.eclipse.jdt.ls.product/target/repository under ~/.emacs.d/.cache/lsp and renamed to eclipse.jdt.ls. Seems like it worked. Except cant use the dap mode now. When i run dap-debug after (require 'dap-java), it says Open an issue in lsp-mode to implement vscode.java.resolveMainClass.