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

doesnt work outside of methods #3422

Closed
ewof opened this issue Dec 8, 2023 · 8 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2997
Closed

doesnt work outside of methods #3422

ewof opened this issue Dec 8, 2023 · 8 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2997

Comments

@ewof
Copy link

ewof commented Dec 8, 2023

there is 0 intellisense outside of methods

Environment
  • Operating System: mac
  • JDK version: 17
  • Visual Studio Code version: 1.85.0
  • Java extension version: v1.25.1
Steps To Reproduce
  1. open a java file
  2. make a blank class
  3. type ma or so Coll trying to outcomplete main method or println or some class like Collection and it wont work, all the autocompletion is just dictionary stuff (it says abc)

it was fine like a month ago
the extension not auto importing classes and stuff makes writing java actually horrible
works fine if u make a method and start typing inside of the method

[Please attach a sample project reproducing the error]
Please attach logs

Current Result
Expected Result
Additional Informations
@ewof
Copy link
Author

ewof commented Dec 8, 2023

Cannot read the array length because the return value of "org.eclipse.jdt.core.CompletionContext.getToken()" is null
java.lang.NullPointerException: Cannot read the array length because the return value of "org.eclipse.jdt.core.CompletionContext.getToken()" is null
	at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.matchCase(CompletionProposalRequestor.java:698)
	at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.accept(CompletionProposalRequestor.java:237)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.createTypeProposal(CompletionEngine.java:5534)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.proposeType(CompletionEngine.java:14568)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.acceptTypes(CompletionEngine.java:1677)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.findTypesAndPackages(CompletionEngine.java:11936)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.completionOnFieldType(CompletionEngine.java:2740)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete(CompletionEngine.java:2015)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete(CompletionEngine.java:2352)
	at org.eclipse.jdt.internal.core.Openable.codeComplete(Openable.java:136)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:367)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:357)
	at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.computeContentAssist(CompletionHandler.java:287)
	at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.completion(CompletionHandler.java:121)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.completion(JDTLanguageServer.java:633)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$recursiveFindRpcMethods$0(GenericEndpoint.java:65)
	at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)
	at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)
	at org.eclipse.jdt.ls.core.internal.ParentProcessWatcher.lambda$1(ParentProcessWatcher.java:144)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
	at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
	at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

this led me to #3186 but idk how to fix it

@ewof
Copy link
Author

ewof commented Dec 8, 2023

"java.completion.matchCase": "off", "fixes" it but i want to use it with it set to first letter but i cant bc it will crash

@rgrunber
Copy link
Member

rgrunber commented Dec 8, 2023

Tried on VS Code 1.85.0 with vscode-java 1.25.1 but can't get this to happen.

"java.completion.matchCase": "off" will definitely work around the issue, but I'm not sure why this would start happening now. If a user types mo|, so| or Coll| then the context should be one of those, and no null. Even if I type and immediately delete the tokens, the context is still an empty list.

The only thing I can think of is maybe JDT Core changed how it handles the token context. Fixing it would be an easy check at https://github.com/eclipse-jdtls/eclipse.jdt.ls/blob/cd8467833e3c988cdeca69badf60c169698f8902/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/contentassist/CompletionProposalRequestor.java#L698

Update: Or maybe something in VS Code 1.85.0 has changed some aspect of how code completions are cancelled ? I did notice null context in some instances, but they ended up receiving a cancellation (from the client) in my testing.

@snjeza can you reproduce this at all ?

@rgrunber rgrunber added the bug label Dec 8, 2023
@snjeza
Copy link
Contributor

snjeza commented Dec 8, 2023

@snjeza can you reproduce this at all ?

@rgrunber No, I can't.

@robstryker
Copy link
Contributor

This is the kind of bug that should be fixed even if people cannot replicate it. See https://github.com/eclipse-jdtls/eclipse.jdt.ls/pull/2997/files

@rgrunber rgrunber added this to the End December 2023 milestone Dec 11, 2023
rgrunber pushed a commit to robstryker/eclipse.jdt.ls that referenced this issue Dec 11, 2023
rgrunber pushed a commit to eclipse-jdtls/eclipse.jdt.ls that referenced this issue Dec 11, 2023
@rgrunber
Copy link
Member

This should be fixed in the latest pre-release and will be in the next release.

@ewof
Copy link
Author

ewof commented Dec 13, 2023

yea it seams to work on the latest prerelease but one really nice thing that was possible before but isn't now is that if you typed ma or main you could auto complete the entire main method. i don't see any snippets outside of methods in autocomplete, just classes and such

@rgrunber
Copy link
Member

class-snippet-context

In recent versions, we made snippets a bit more context aware (see above). So if you typed method or main snippets at the top of the file, they wouldn't display because unless you were within a type declaration, they were not valid (in the example I show a nested class, but not required). I think we might need to update this to account for the new ways main methods can be declared with the Java 21 preview feature, https://openjdk.org/jeps/445 .

Do you have a case where you wanted the main (or method) snippet within a type declaration where it wasn't showing up ?

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

Successfully merging a pull request may close this issue.

4 participants