redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 442 forks source link

Code Completion stops when code files are reopened #3485

Open YaduAhuja opened 9 months ago

YaduAhuja commented 9 months ago

Whenever I open a folder and start to write some java code in it, then it works fine I get autocomplete and everything, but If I close VSCode and open that folder again then everything stops only some basic features work like syntax highlighting etc. even the auto imports feature does not even works until I have cleaned the Java Language server workspace.

Environment
Steps To Reproduce
  1. Open VSCode in an empty folder
  2. Create a java source file with some basic code in it (Like a hello world or read a number through terminal with scanner).
  3. Close VSCode.
  4. Open VSCode in the same folder again.
  5. Create a new java source file with some basic code.
  6. Now code completion will stop working.
Issue Replication Video

https://github.com/redhat-developer/vscode-java/assets/66440500/1c606780-d05e-49e7-8c15-04ac20999d94

Please attach logs .log client.log

Current Result

Screenshot (7)

Expected Result

Screenshot (8)

Additional Informations
rgrunber commented 9 months ago

@snjeza let me know if you're able to reproduce this or narrow it down. There's nothing weird in the attached client/server logs that would indicate an error. It just looks like the language server stops responding to textDocument/completion, although it looks like snippets still work. To me that implies some kind of failure in the underlying JDT code completion engine. Maybe the order in which some token was typed broke it ?

I thought maybe it had something to do with the Java 21 String Template completion (eg. STR) but it looks like by the time that shows up, the regular type-baesd completions have already stopped being returned.

Update: Another thing to try is with intellicode, since I can see it in the completion items.

snjeza commented 9 months ago

I can't reproduce issue.

There's nothing weird in the attached client/server logs that would indicate an error

@YaduAhuja Could you attach all client logs?

Update: Another thing to try is with intellicode, since I can see it in the completion items.

@YaduAhuja Could you try to add

"vsintellicode.java.completionsEnabled": false,
YaduAhuja commented 9 months ago

I added the setting you mentioned, Although it did not fixed the issue.

I have attached the logs before adding the setting and after the setting.

If any logs are missing, then let me know how to get them. As of now, I use the Open All Log Files command to get logs.

AfterAddingSetting.zip BeforeAddingSetting.zip

snjeza commented 9 months ago

@YaduAhuja Could you attach your settings.json?

YaduAhuja commented 9 months ago

Did you find anything in logs which can give insight regarding the error.

settings.json

snjeza commented 9 months ago

Did you find anything in logs which can give insight regarding the error

Yes, I am.

org.eclipse.core.runtime.CoreException: Cannot get completion responses.
    at org.eclipse.jdt.ls.core.internal.ExceptionFactory.newException(ExceptionFactory.java:28)
    at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.onDidCompletionItemSelect(CompletionHandler.java:185)
    at org.eclipse.jdt.ls.core.internal.JDTDelegateCommandHandler.executeCommand(JDTDelegateCommandHandler.java:198)
    at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:616)
    at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)

VS Code calls textDocument/completion before java.completion.onDidSelect However, I can't reproduce issue. A related issue - https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/2362

There are com.oracle.graal.* in your logs. How do you get it?

YaduAhuja commented 9 months ago

There are com.oracle.graal.* in your logs. How do you get it?

I am using GraalVM JDK 21 from Oracle, that is the reason I think I was getting those completions.

Do you think that maybe this JDK is creating problems for extension ?

Here is a screenshot for graal completions.

Screenshot (9)

Ideally, I think there must be a configuration like we have in Eclipse where we can specify on which keywords a completion is shown. If we had that, then I think we could even improve the performance of this extension, as we can reduce the number of calls made to the language server by making a configuration to give completions only on a list of characters like A-Z and . .

ghosh-rounak commented 8 months ago

Yes I agree with @YaduAhuja . This extension is not working at all like other JAVA ide for example Intellij IDEA. The code completion randomly stops . For example on typing S the code completion popup should show all valid java keywords including Scanner , String , System , etc. But this code completion behavior does not happen always . Sometimes it just stops to show JAVA keywords on the code completion list and only shows some snippets which are of no use.
The code completion behavior should be consistent and should always show all valid java keywords. Please fix this extension.