Skip to content

Code Action doesn't return correct document version #50

Description

@rchl
  1. Add import fs from 'fs'; in a <script> tag in Vue file
  2. Trigger code actions on that line and select Delete all unused imports

Volar doesn't return matching document version in the codeAction/resolve response.

[Trace - 11:01:42] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "uri": "file:///usr/local/workspace/file.vue",
        "version": 2
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 86,
                    "character": 0
                },
                "end": {
                    "line": 86,
                    "character": 0
                }
            },
            "rangeLength": 0,
            "text": "import fs from 'fs';"
        }
    ]
}

[Trace - 11:01:48] Received response 'codeAction/resolve - (25)' in 7ms.
Result: {
    "title": "Delete all unused imports",
    "data": {
        "uri": "file:///usr/local/workspace/file.vue.ts",
        "type": "fixAll",
        "fileName": "/usr/local/workspace/file.vue.ts",
        "fixIds": [
            "unusedIdentifier_deleteImports"
        ]
    },
    "kind": "",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 6,
                    "character": 0
                },
                "end": {
                    "line": 6,
                    "character": 20
                }
            },
            "message": "'fs' is declared but its value is never read.",
            "data": {
                "uri": "file:///usr/local/workspace/file.vue",
                "version": 4,
                "type": "service",
                "serviceOrRuleId": "typescript",
                "isFormat": false,
                "original": {},
                "ruleFixIndex": 0,
                "documentUri": "file:///usr/local/workspace/file.vue.ts"
            },
            "code": 6133,
            "severity": 4,
            "tags": [
                1
            ],
            "source": "ts"
        }
    ],
    "edit": {
        "documentChanges": [
            {
                "textDocument": {
                    "uri": "file:///usr/local/workspace/file.vue",
                    "version": 4
                },
                "edits": [
                    {
                        "newText": "",
                        "range": {
                            "start": {
                                "line": 86,
                                "character": 0
                            },
                            "end": {
                                "line": 87,
                                "character": 0
                            }
                        }
                    }
                ]
            }
        ]
    }
}

As can be seen here, Volar specified version 4 in the code action while the document is at version 2 right now.

It appears that VSCode doesn't really care about version and still applies the edit but in case of Sublime Text the edit is ignored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions