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

No Autocomplete for Overriden Methods #3186

Closed
Brahvim opened this issue Jul 6, 2023 · 7 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2902
Closed

No Autocomplete for Overriden Methods #3186

Brahvim opened this issue Jul 6, 2023 · 7 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2902

Comments

@Brahvim
Copy link

Brahvim commented Jul 6, 2023

Environment
  • Operating System: KDE Neon 5.27, GNU-Linux.
  • JDK version: OpenJDK JavaSE-17, specifically jdk-17.0.7+7.
  • Visual Studio Code versions: 1.79.2 and 1.80.0.
  • Java extension version: 1.20.0.
Steps To Reproduce
  1. Write a class in the project, in the src folder, perhaps in a package,
  2. Write another class that extends it,
  3. Type the name of any overrideable method, and check the list of autocompletions.
Current Result

The autocompleion list simply shows unrelated fuzzy-matched symbols.
For example, double, for a method named draw(), or some sun-related packages for setup().

Expected Result

Pressing Tab should autocomplete the method signature, place curly braces, annotate the method with @Override, et cetera.

Additional Information

Apparently this affects only some methods declared as protected in the super-class.
This also applies to anonymous and inner classes.

I've written about this issue on stackoverflow as well.

@snjeza
Copy link
Contributor

snjeza commented Jul 6, 2023

@Brahvim I can't reproduce the issue.

draw

@Brahvim
Copy link
Author

Brahvim commented Jul 7, 2023

@snjeza, yes, the issue is hard to reproduce. Quite oddly however, it seems to be affecting only some methods in my code. Not all.

RedhatVsCodeJavaIssue3186.mp4

In the footage, you can see that when I override NerdScene::draw() incorrectly, the language server spots it and tells me that there's been an error in my code. I remove the extra parameter and the language server spots that too, removing its indication for the error. This proves that NerdScene::draw() is in fact, overrideable.

I then remove the entire method, type just its identifier, press Tab many times, but autocompletion does not work there.
As can be seen for little time - when I type the first character of the identifier, the list of autocompletions does indeed report only a double - what I stated in the last post for this issue. Autocompletions from the extension itself, stop after that.

However, I then demonstrate overriding a different method - NerdScene::post(), and in that case, autocompletion works as expected.

I hope this is enough proof. This is indeed very unexpected behavior, and I can see how tracking it down is not easy. Thank you for listening to me, though - I wish you have a good time!

@Brahvim
Copy link
Author

Brahvim commented Jul 7, 2023

Here are my settings for the extension in the case I myself got something terribly wrong:

// #region Java.
    "java.inlayHints.parameterNames.enabled": "none",
    "java.configuration.runtimes": [
        {
            "name": "JavaSE-17",
            "path": "/home/brahvim/java/jdk-17.0.7+7/",
            "default": true
        }
    ],
    "java.completion.filteredTypes": [
        "com.sun.*",
        "sun.*",
        "jdk.*"
    ],
    "java.jdt.ls.java.home": "/home/brahvim/java/jdk-17.0.7+7",
    "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xms128M -Xmx512M",
    "java.cleanup.actionsOnSave": [
        "qualifyStaticMembers",
        "addDeprecated",
        "stringConcatToTextBlock",
        "instanceofPatternMatch",
        "invertEquals",
        "tryWithResource",
        "addOverride",
        "addFinalModifier"
    ],
    "java.codeGeneration.hashCodeEquals.useInstanceof": true,
    "java.debug.settings.console": "internalConsole",
    "[java]": {
        "editor.defaultFormatter": "redhat.java"
    },
    "java.sources.organizeImports.starThreshold": 999,
    "java.sources.organizeImports.staticStarThreshold": 999,
    "java.project.sourcePaths": [
        "src"
    ],
    "java.project.resourceFilters": [
        "node_modules",
        "\\.git"
    ],
    "java.jdt.ls.androidSupport.enabled": "on",
    "java.import.gradle.home": "",
    "java.import.gradle.jvmArguments": "-Xmx256m",
    "java.import.gradle.offline.enabled": true,
    "java.jdt.ls.protobufSupport.enabled": false,
    "java.import.maven.offline.enabled": true,
    "java.compile.nullAnalysis.nonnull": [
        "javax.annotation.Nonnull",
        "org.eclipse.jdt.annotation.NonNull",
        "org.springframework.lang.NonNull"
    ],
    "java.compile.nullAnalysis.nullable": [
        "javax.annotation.Nullable",
        "org.eclipse.jdt.annotation.Nullable",
        "org.springframework.lang.Nullable"
    ],
    "java.completion.chain.enabled": true,
    "java.completion.enabled": true,
    "java.configuration.workspaceCacheLimit": 15,
    // #endregion

@karlvr
Copy link
Contributor

karlvr commented Jul 8, 2023

I think I'm seeing this behaviour as well, but only in one of my projects :-/ Autocomplete for method overrides is just suggestions of recently typed words. I'm also having trouble with autocomplete adding imports... I am having to add imports using Organize Imports.

At least in my case, this is a regression in Language Support for Java(TM) by Red Hat v1.20.0. If I revert to v1.19.0 and clean the Java language workspace, it works fine. If I then upgrade again to v1.20.0 and clean the Java language workspace, it's broken.

I see this exception in the Output:

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:650)
	at org.eclipse.jdt.ls.core.internal.contentassist.CompletionProposalRequestor.accept(CompletionProposalRequestor.java:207)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.findLocalMethodDeclarations(CompletionEngine.java:9423)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.findInterfacesMethodDeclarations(CompletionEngine.java:8882)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.findMethodDeclarations(CompletionEngine.java:10913)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.completionOnFieldType(CompletionEngine.java:2757)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete(CompletionEngine.java:2013)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete(CompletionEngine.java:2356)
	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:275)
	at org.eclipse.jdt.ls.core.internal.handlers.CompletionHandler.completion(CompletionHandler.java:110)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.completion(JDTLanguageServer.java:613)
	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)

HOWEVER on 1.19.0, the autocomplete still stops working... It is reproducible if I make a new Java file. Autocomplete is not available in that new Java file. There is nothing in the Language Support for Java Output window when this happens. Autocomplete continues to work in other Java files for a bit, but then can also die.

@starball5
Copy link

starball5 commented Jul 9, 2023

Did something with respect to suggestions in this extension break recently? I've been seeing multiple questions on Stack Overflow about suggestion issues related to Java in VS Code:

Should I raise a new issue ticket for this? Or is there an existing one covering these issues?

@snjeza
Copy link
Contributor

snjeza commented Jul 9, 2023

Should I raise a new issue ticket for this? Or is there an existing one covering these issues?

@starball5 You may want to take a look at #3179

@testforstephen
Copy link
Collaborator

fixed by eclipse-jdtls/eclipse.jdt.ls#2902

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

Successfully merging a pull request may close this issue.

6 participants