Skip to content

didChange/didOpen appear to be sent out of order for global search-and-replace #1176

Closed

Description

This is a related bug to one i filed recently #1133

With global search-and-replace we are getting that didChange and didOpen events are out of order with full document sync -

Example from my test repo -

Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/foo.hh",
        "version": 2
    },
    "contentChanges": [
        {
            "text": "#pragma once\n\n// abcdefgh abcdefgh abcdefgh\nnamespace foo {\n\nvoid Foo();\n\n}  // namespace foo\n"
        }
    ]
}


[Trace - 3:09:24 PM] Sending notification 'textDocument/didOpen'.
Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/hello.ts",
        "languageId": "typescript",
        "version": 1,
        "text": "// abcdef abcdef abcdef abcdef abcdef\nexport const foo = 2;\n"
    }
}


[Trace - 3:09:24 PM] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/hello.ts",
        "version": 2
    },
    "contentChanges": [
        {
            "text": "// abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh\nexport const foo = 2;\n"
        }
    ]
}


[Trace - 3:09:24 PM] Sending notification 'textDocument/didOpen'.
Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/foo.hh",
        "languageId": "cpp",
        "version": 1,
        "text": "#pragma once\n\n// abcdef abcdef abcdef\nnamespace foo {\n\nvoid Foo();\n\n}  // namespace foo\n"
    }
}


[Trace - 3:09:24 PM] Sending request 'textDocument/formatting - (2)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/hello.ts"
    },
    "options": {
        "tabSize": 2,
        "insertSpaces": true
    }
}


[Trace - 3:09:24 PM] Sending request 'textDocument/formatting - (3)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/foo.hh"
    },
    "options": {
        "tabSize": 2,
        "insertSpaces": true
    }
}


[Trace - 3:09:24 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "diagnostics": [],
    "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/foo.hh"
}


[Trace - 3:09:24 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "diagnostics": [],
    "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/hello.ts"
}


[Trace - 3:09:25 PM] Received response 'textDocument/formatting - (2)' in 747ms.
Result: [
    {
        "newText": "// abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh\nexport const foo = 2;\n",
        "range": {
            "end": {
                "character": 4611686018427388000,
                "line": 4611686018427388000
            },
            "start": {
                "character": 0,
                "line": 0
            }
        }
    }
]


[Trace - 3:09:25 PM] Sending notification 'textDocument/didSave'.
Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/hello.ts"
    }
}


[Trace - 3:09:25 PM] Sending notification 'textDocument/didClose'.
Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/hello.ts"
    }
}


[Trace - 3:09:25 PM] Received response 'textDocument/formatting - (3)' in 803ms.
Result: [
    {
        "newText": "#pragma once\n\n// abcdefgh abcdefgh abcdefgh\nnamespace foo {\n\nvoid Foo();\n\n}  // namespace foo\n",
        "range": {
            "end": {
                "character": 4611686018427388000,
                "line": 4611686018427388000
            },
            "start": {
                "character": 0,
                "line": 0
            }
        }
    }
]


[Trace - 3:09:25 PM] Sending notification 'textDocument/didSave'.
Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/foo.hh"
    }
}


[Trace - 3:09:25 PM] Sending notification 'textDocument/didClose'.
Params: {
    "textDocument": {
        "uri": "file:///Users/lauri/work/trunk-format-on-save-bug/foo.hh"
    }
}

The repro steps are identical to the one attached in the aforementioned bug.

The extension works correctly - we currently have code to re-order the events in the LSP so that didOpen events are processed after didChange even if they are received after them, but we'd like to remove it as it's hacky. This incorrectly ordered event stream can be observed in the extension output.

We are currently on vscode-languageclient version 8.1.0-next.3 - trunk version 3.3.6.

Thank you very much for your help!

Activity

  1. added a commit that references this issue on Jan 13, 2023
    532dc99
  2. added a commit that references this issue on Jan 13, 2023
    2462ba1
  3. dbaeumer commented on Jan 16, 2023

    @dbaeumer
    Member

    release client and server @8.1.0-next.6

    Let me know how it goes.

  4. laurit17 commented on Jan 23, 2023

    @laurit17
    Author

    This fixes our issue - thank you so much!

  5. added this to the milestone on Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions