eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

[regression] Code actions unrelated to diagnostics are ignored

Open fbricon opened this issue 7 years ago • 3 comments

  • given a basically empty class Bar.java
public class Bar {   
}
  • and a class Foo.java:
public class Foo { 
    public static void main(String[] args) {
        new Bar().thatField;
    }
}

"thatField" should have a code action to generate the field in Bar, but no code action is returned. Server log:

[Trace - 5:58:54 PM] Sending request 'textDocument/codeAction - (629)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/fbricon/Downloads/test/src/main/java/Foo.java"
    },
    "range": {
        "start": {
            "line": 7,
            "character": 21
        },
        "end": {
            "line": 7,
            "character": 21
        }
    },
    "context": {
        "diagnostics": [
            {
                "range": {
                    "start": {
                        "line": 7,
                        "character": 18
                    },
                    "end": {
                        "line": 7,
                        "character": 23
                    }
                },
                "message": "Syntax error, insert \"AssignmentOperator Expression\" to complete Expression",
                "severity": 1,
                "code": "1610612976",
                "source": "Java"
            }
        ]
    }
}


[Trace - 5:58:54 PM] Received response 'textDocument/codeAction - (629)' in 2ms.
Result: []

UnresolvedVariablesQuickFixTest.testBug300 (although it's broken), checks a code action for that case is sent, when there's no diagnostics info attached to the query

fbricon avatar Dec 17 '18 23:12 fbricon

I think the main part of this bug no longer happens; when I write the code you suggest, the code action appears and can be applied. Also the test you referenced is enabled.

However, the code action generates a public static field instead of just a public field as the code action name and the way the code is structured would suggest. Maybe this is intentional, but this seems like a bug.

datho7561 avatar Jan 24 '23 21:01 datho7561

However, the code action generates a public static field ...

This happens in Eclipse as well

datho7561 avatar Jan 24 '23 21:01 datho7561

with new App().thatField = 5;, the generated field is static with jdt.ls, not static in Eclipse. Something's fishy here.

fbricon avatar Nov 21 '25 15:11 fbricon