Skip to content

Create file or method from quick fix doesn't work. #4320

Closed
eclipse-jdtls/eclipse.jdt.ls
#3698

Description

@yuyully
Environment
  • Operating System: Windows
  • JDK version: 21.0.8
  • Visual Studio Code version: 1.108.2
  • Java extension version: 1.52.0
Steps To Reproduce
  1. Open a java project > New a java file
  2. Set "editor.pasteAs.enabled": false
  3. Copy File f = new File("demo.txt"); into the java file > Create file from quick fix > It doesn't work
  4. Copy Foo f = new Foo(); f.call(); into the java file > Create method from quick fix > It doesn't work
Current Result
Image Image
Expected Result

Activity

  1. fbricon commented on Jan 29, 2026

    @fbricon
    Collaborator

    I can reproduce. I have a hunch this might have been caused by eclipse-jdtls/eclipse.jdt.ls#3650. Need to investigate further.

  2. fbricon commented on Jan 29, 2026

    @fbricon
    Collaborator

    This is what codeAction/resolve returns in 1.52, doesn't contain any text edits:

    [Trace - 10:06:38 AM] Received response 'codeAction/resolve - (575)' in 1ms.
    Result: {
        "title": "Create class 'File'",
        "kind": "quickfix",
        "diagnostics": [
            {
                "range": {
                    "start": {
                        "line": 5,
                        "character": 2
                    },
                    "end": {
                        "line": 5,
                        "character": 6
                    }
                },
                "severity": 1,
                "code": "16777218",
                "source": "Java",
                "message": "File cannot be resolved to a type",
                "data": {
                    "arguments": [
                        "File"
                    ]
                }
            }
        ],
        "command": {
            "title": "refresh Diagnostics",
            "command": "java.project.refreshDiagnostics",
            "arguments": [
                "file:///Users/fbricon/Dev/souk/quickfix-bug/src/main/java/Apple.java",
                "thisFile",
                false,
                true
            ]
        }
    }
    

    This is what 1.51.0 returns:

    [Trace - 10:11:39 AM] Received response 'codeAction/resolve - (35)' in 18ms.
    Result: {
        "title": "Create class 'File'",
        "kind": "quickfix",
        "diagnostics": [
            {
                "range": {
                    "start": {
                        "line": 5,
                        "character": 2
                    },
                    "end": {
                        "line": 5,
                        "character": 6
                    }
                },
                "severity": 1,
                "code": "16777218",
                "source": "Java",
                "message": "File cannot be resolved to a type",
                "data": {
                    "arguments": [
                        "File"
                    ]
                }
            }
        ],
        "edit": {
            "changes": {},
            "documentChanges": [
                {
                    "uri": "file:///Users/fbricon/Dev/souk/quickfix-bug/src/main/java/File.java",
                    "options": {
                        "overwrite": false,
                        "ignoreIfExists": true
                    },
                    "kind": "create"
                },
                {
                    "textDocument": {
                        "version": null,
                        "uri": "file:///Users/fbricon/Dev/souk/quickfix-bug/src/main/java/File.java"
                    },
                    "edits": [
                        {
                            "range": {
                                "start": {
                                    "line": 0,
                                    "character": 0
                                },
                                "end": {
                                    "line": 0,
                                    "character": 0
                                }
                            },
                            "newText": "\npublic class File {\n\n}\n"
                        }
                    ]
                }
            ]
        },
        "command": {
            "title": "refresh Diagnostics",
            "command": "java.project.refreshDiagnostics",
            "arguments": [
                "file:///Users/fbricon/Dev/souk/quickfix-bug/src/main/java/Apple.java",
                "thisFile",
                false,
                true
            ]
        }
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions