lsp-java icon indicating copy to clipboard operation
lsp-java copied to clipboard

Autocompletion stops working, after initially working.

Open adhilton opened this issue 4 years ago • 7 comments

Describe the bug Autocompletion initially works properly, then at some point stops.
I believe that lsp-java-organize-imports causes the problem reliably. However, I think I have also had this stop working when not doing this command.

To Reproduce

  1. mkdir test
  2. cd test
  3. gradle init Note: using gradle 7.3.3 Selections during initialization:
    2 (application) 3 (Java) 1 (No) 1 (Groovy) no (to new APIs) 4 (JUnit Jupiter) project name: test (default) source package name: test (default)
  4. emacs -q -l ~/Downloads/lsp-start-plain.el app/src/main/java/test/App.java
  5. wait for lsp-start-plain to install its temporary packages
  6. Answer "jdtls" when prompted for language server, then wait for it to install.
  7. Select "I" to choose project root interactively and select ~/test (or wherever you made the directory for this)
  8. Write some code and observe that auto-complete is initially working
  9. Continue writing code. I think, but am not sure that lsp-java-organize-imports breaks it (but other things seem to cause the problem as well---I have had a hard time figuring out exactly what does it).
  10. At some point, observe that auto-complete has stopped working properly. Completions are not given for some things, and no useful completions are given for others.

Expected behavior Autocomplete should continue working as it initially did.

Screen Recording and Logs I obtained the the logs and a screen recording. They are available here: Screen recording (webm format, 5:44 long, 6.7MB total) - Once we past the basic gradle project setup/lsp-start-plain.el doing its thing/jdtls install, I show the lsp log and LSP IO log in the lower half, in case you need to match up time stamps with what was happening in the code. - At time index 3:36, you can see autocompletion working properly, for both a class name (System) and a method within it (currentTimeMillis). - At 4:14 I do lsp-java-organize-imports . This seems to be reliably break the autocompletion. Though I think it may break in other ways too.
- At time index 4:26 you can see attempts to autocomplete the class name System no long works properly. - At time index 4:45 you can see that attempts to autocomplete a method name inside System no longer provides useful completion - At time index 4:53 i perform M-x company-diag to show company diagnostics on Sys and its lack of completions - At time index 5:19 I show M-x lsp-describe-session and expand its Capabilities in case that is useful. LSP's IO Log LSP's log

Similar Previous Bug I will also note that this sounds similar to https://github.com/emacs-lsp/lsp-java/issues/192 which was closed with the user still facing issues from time to time, but having trouble reproducing it.

adhilton avatar Jan 08 '22 22:01 adhilton

It looks like setting lsp-java-format-on-type-enabled to nil is a viable workaround for this bug.

adhilton avatar Jan 09 '22 20:01 adhilton

I've run into this issue and I have determined the conditions for this occurring. If lsp-mode was unable to automatically determine the project root, this bug will occur when the buffer is saved. Before the buffer is saved the completions behave normally.

The way I workaround this issue is by running git init on the project root so lsp-mode can automatically find it. So if you follow @adhilton 's method but run git init after gradle init you will find it to be without this bug.

UserWasNotFound avatar Apr 14 '22 04:04 UserWasNotFound

@UserWasNotFound lsp-mode does not automatically look for the root. It asks the user.

yyoncho avatar Apr 14 '22 05:04 yyoncho

@yyoncho Sorry, let me explain better. On project import, if the first option i==>Import project root /a/path/ is not the correct project root, this bug will occur for me.

UserWasNotFound avatar Apr 14 '22 05:04 UserWasNotFound

@UserWasNotFound the second option allows interactively picking the right directory, so no need to create git project. Also, there is .projectile marker to mark the project root.

yyoncho avatar Apr 14 '22 05:04 yyoncho

@yyoncho What I am saying is that the bug that @adhilton describes occurs if the project root guessed by lsp-mode is incorrect. Selecting the root interactively will not prevent this bug from occurring. This bug will only be prevented if the project root is in such a state that lsp-mode correctly guesses it as the root. And this is not to say that lsp-mode project importing is the cause of this issue, just that it will only occur under these conditions as far as I know.

UserWasNotFound avatar Apr 14 '22 06:04 UserWasNotFound

After continued experimentation, I have found the only way to have completions reliably work in a Gradle project is to not only git init but also git add the relevant file(s). Using projectile and the .projectile file does not prevent this bug. I don't know if this bug exists outside of Gradle projects.

UserWasNotFound avatar Apr 15 '22 00:04 UserWasNotFound