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

Code action 'Create method...' does not work #3780

Closed
loralei28 opened this issue Sep 26, 2024 · 17 comments · Fixed by #3785 or #3792
Closed

Code action 'Create method...' does not work #3780

loralei28 opened this issue Sep 26, 2024 · 17 comments · Fixed by #3785 or #3792

Comments

@loralei28
Copy link

Environment
  • Operating System: Windows
  • JDK version:17
  • Visual Studio Code version:1.93.1
  • Java extension version: redhat-1.35.0
Steps To Reproduce
  1. Create a new Java file, for example Test.java
  2. In Test.java file, invoke class and main code snippet to generate code
  3. Type bar();
  4. Click ‘Quick fix..’ in the java file or click 'Show fix' in the error window
  5. Select code action "Create method 'bar()'"
Current Result

”Create method 'bar()'“ does not work and will delete "bar()"
3

@rgrunber
Copy link
Member

rgrunber commented Sep 26, 2024

Screencast.from.2024-09-26.08-52-55.mp4

Seems to be working for me. @loralei28 , @testforstephen what am I missing here. Also, if you activate Java: Open Java Language Server Log File, are there any errors in that log ? Does the "Extension Host" logs (from the dropdown) of the Output view indicate any errors ?

Could definitely see it being a regression of eclipse-jdtls/eclipse.jdt.ls#3229 though.

@datho7561
Copy link
Contributor

I reproduced this issue, it seems like it's Windows-specific

@datho7561
Copy link
Contributor

Here is a sample file:

package functions;

import io.quarkus.funqy.Funq;

/**
 * Your Function class
 */
public class Function {

    /**
     * Use the Quarkus Funqy extension for our function. This function simply echoes its input
     * @param input a Java bean
     * @return a Java bean
     */
    @Funq
    public Output function(Input input) {

        // Add business logic here
        bar();

        return null;
    }

}

Here is a trace of what the server returns for the quickfix:

[Trace - 10:45:24 AM] Received response 'codeAction/resolve - (119)' in 5ms.
Result: {
    "title": "Create method 'bar()'",
    "kind": "quickfix",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 18,
                    "character": 8
                },
                "end": {
                    "line": 18,
                    "character": 11
                }
            },
            "severity": 1,
            "code": "67108964",
            "source": "Java",
            "message": "The method bar() is undefined for the type Function"
        }
    ],
    "edit": {
        "changes": {},
        "documentChanges": [
            {
                "textDocument": {
                    "version": null,
                    "uri": "file:///C:/Users/david/Documents/Programming/TestProjects/quarkus-func/src/main/java/functions/Function.java"
                },
                "edits": [
                    {
                        "snippet": {
                            "value": "${1:bar}();\n\n        return null;\n    }\n\n    ${2|private,public,protected|} ${3:void} ${1:bar}() {\n        // TODO Auto-generated method stub\n        throw new UnsupportedOperationException(\"Unimplemented method 'bar'\");\n    }"
                        },
                        "range": {
                            "start": {
                                "line": 18,
                                "character": 8
                            },
                            "end": {
                                "line": 21,
                                "character": 5
                            }
                        },
                        "newText": ""
                    }
                ]
            }
        ]
    },
    "command": {
        "title": "refresh Diagnostics",
        "command": "java.project.refreshDiagnostics",
        "arguments": [
            "file:///c%3A/Users/david/Documents/Programming/TestProjects/quarkus-func/src/main/java/functions/Function.java",
            "thisFile",
            false,
            true
        ]
    }
}

@rgrunber
Copy link
Member

rgrunber commented Sep 26, 2024

I'm seeing the exact same response, only file URI is different (I'm on Linux). When you have time, i would try to validate whether

--- yours.txt	2024-09-26 11:17:54.751100419 -0400
+++ mine.txt	2024-09-26 11:23:02.727259008 -0400
@@ -1,4 +1,4 @@
-[Trace - 10:45:24 AM] Received response 'codeAction/resolve - (119)' in 5ms.
+[Trace - 11:22:36] Received response 'codeAction/resolve - (458)' in 39ms.
 Result: {
     "title": "Create method 'bar()'",
     "kind": "quickfix",
@@ -26,7 +26,7 @@
             {
                 "textDocument": {
                     "version": null,
-                    "uri": "file:///C:/Users/david/Documents/Programming/TestProjects/quarkus-func/src/main/java/functions/Function.java"
+                    "uri": "file:///home/rgrunber/sample-projects/my-quarkus-example/src/main/java/functions/Function.java"
                 },
                 "edits": [
                     {
@@ -53,7 +53,7 @@
         "title": "refresh Diagnostics",
         "command": "java.project.refreshDiagnostics",
         "arguments": [
-            "file:///c%3A/Users/david/Documents/Programming/TestProjects/quarkus-func/src/main/java/functions/Function.java",
+            "file:///home/rgrunber/sample-projects/my-quarkus-example/src/main/java/functions/Function.java",
             "thisFile",
             false,
             true

Definitely seems like something on the client side that's treated differently.

Update: Maybe the LSP text document URI is slightly different than the converted to VS Code text document URI ?

if (documentUris.includes(uri.toString())) {
.

@testforstephen
Copy link
Collaborator

Looks like snippet text of "codeAction/resolve" response is not respected on Windows, and it still applies newText, which is "" and behaves as delete.

@fp024
Copy link

fp024 commented Sep 27, 2024

Hello.

After upgrading the extension to version 1.35.0 in Windows 11 environment, Create local Variable '???' does not work properly.

However, there was no problem in Ubuntu 22.04 environment.

Windows 11 + Ext Ver. 1.35.0 (It became "")

win-do-not-work-create-val.mp4

Ubuntu 22.04 + Ext Ver. 1.35.0

ubuntu-do-work-create-val.mp4

@rgrunber
Copy link
Member

rgrunber commented Sep 27, 2024

@testforstephen , can you try the PR and let me know if it resolves it for you ? It should prevent newText from being populated.

If someone could try out java-win32-x64-1.36.0-179.vsix (on windows) from https://github.com/rgrunber/vscode-java/releases/tag/v1.36.0 and let me know if that fixes things for them, that would help.

@rgrunber rgrunber added this to the End October 2024 milestone Sep 27, 2024
@fp024
Copy link

fp024 commented Sep 27, 2024

In my Windows 11 environment, installing 1.36.0 did not solve the problem.

image

@rgrunber
Copy link
Member

@testforstephen , I think we should just disable the feature ( snippetEditSupport in extendedClientCapabilities ) until there's some kind of fix upstream / we find a proper solution for windows. Could we do a bug-fix release for Monday ?

@testforstephen
Copy link
Collaborator

@testforstephen , I think we should just disable the feature ( snippetEditSupport in extendedClientCapabilities ) until there's some kind of fix upstream / we find a proper solution for windows. Could we do a bug-fix release for Monday ?

+1

@rgrunber
Copy link
Member

I found the root cause on Windows. It's our code :

if (documentUris.includes(uri.toString())) {

URI from the language server is : file:///C:/Users/user/projects/foo/Test.java
URI after converting lsp.codeaction to a vscode.codeaction is : file:///C%3A/Users/user/projects/foo/Test.java

The conversion seems to be done by the asCodeAction conversion call that occurs higher up.

We can probably fix this by calling Uri.parse(..) on the initial Uri we retrieve from the language server.

Could someone try out https://github.com/rgrunber/vscode-java/releases/tag/v1.36.0 . It should contain a new vsix there that should work on Windows.

@datho7561
Copy link
Contributor

@rgrunber It seems to be working:

indentation-bug-linked-editing.mp4

There's a bug related to the indentation of the inserted content. At the end of the video I formatted the document manually and the content seems to be correct after that

@rgrunber
Copy link
Member

There's a bug related to the indentation of the inserted content. At the end of the video I formatted the document manually and the content seems to be correct after that

This is microsoft/vscode#63129

@fp024
Copy link

fp024 commented Sep 30, 2024

The v1.35.1 release yesterday worked well in a Windows environment. Thank you for your support. 👍

@iwangbowen
Copy link

Why it took so long to fix😡

@fbricon
Copy link
Collaborator

fbricon commented Oct 17, 2024

@iwangbowen I guess you get what you paid for

@rgrunber
Copy link
Member

1.35.0 was released on September 26th (Thursday). I think we were aware of the issue prior to release but didn't have enough information. The feature was available for about 20 days in the 1.35.0 pre-releases so had it been filed earlier, we probably could have fixed it well before the release.

We were investigating the problem the day of the release and by the next day, we decided it would be better to revert and see if we can re-enable for 1.36.0. We had a bug fix release (1.35.1) on Monday (30th).

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