Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The regression test can pass without the freshness guard because it asserts before the independently dispatched stale response is guaranteed to be processed.
1 open issue
What changed in this PR
This PR protects HTML and Vue auto-insert operations from late language-server responses by checking that the editor still matches the request’s captured state.
Changes:
- Adds a shared
EditorSnapshotfor document, modification-stamp, and caret checks. - Guards both reconcilers against stale responses and removes Vue’s per-change console logging.
- Updates HTML caret setup in tests and adds a stale-response regression test.
| File | Description |
|---|---|
| org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/vue/autoinsert/VueAutoInsertReconciler.java | Checks response freshness and removes debug logging. |
| org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/util/EditorSnapshot.java | Introduces shared editor-state capture and validation. |
| org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/html/autoinsert/HTMLAutoInsertReconciler.java | Checks response freshness before inserting text. |
| org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestHTML.java | Updates caret setup and tests stale-response handling. |
Review effort: Balanced
| DisplayHelper.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000, | ||
| () -> document.get().startsWith("<foo></foo>")), | ||
| "Autoclose not done"); | ||
| assertFalse(document.get().contains("</bar>"), "Stale response was applied"); |
A late response from the language server was inserted at its original offset even if the document, caret or editor input had changed in the meantime. Assisted-by: multiple AI agents and layers of automated tooling 🤖
78d94bd to
a1dfc93
Compare
akurtakov
left a comment
There was a problem hiding this comment.
Thanks, dropping stale auto-insert responses fixes a real problem: closing tags and quotes landing in the wrong place after you keep typing or switch editors. I rebased the PR on master.
For comparison, VS Code's HTML client (html-language-features/client) handles the html/autoInsert response like this:
- it ignores changes from undo and redo;
- it sends the request 100 ms after the change, and a new change cancels the pending request;
- it inserts the response only if the document version is unchanged and the document is still the active editor's;
- if the caret moved, it still inserts at the original position. That position is still valid, since the document hasn't changed.
Based on that, a few suggestions:
1. The caret check isn't needed. As long as the modification stamp is unchanged, the original offset is still correct, so the response can be applied even if the caret moved. Checking only the viewer, the document and its modification stamp would be enough. That is also how LSP4E's VersionedEdits detects stale edits. Dropping the response on a caret move makes auto-close disappear in cases where it would have been correct.
2. Cancel superseded requests. Instead of collectAll and then filtering for the server type, use
computeFirst((w, ls) -> ls instanceof HTMLLanguageServerAPI api ? api.autoInsert(params) : CompletableFuture.completedFuture(null)).
Canceling the returned future sends $/cancelRequest to the server. If the next change cancels the previous request, the server doesn't do useless work and most stale responses never arrive. The CompletableFuture.runAsync wrapper can then go too: compute the parameters in documentChanged, while they still match the document.
3. Ignore undo and redo. Undoing the deletion of a > currently triggers an auto-close; this already happens without this PR. LSP4E's LSPonTypeFormattingReconcilingStrategy skips these changes with an IOperationHistoryListener.
4. Test.
- In
autoCloseIgnoresStaleResponse, the first response is already stale because of the second edit, so moving the caret to 0 and back doesn't test anything. With suggestion 1 that step can go. - The
assertFalse(...contains("</bar>"))runs as soon as<foo></foo>appears. If the stale response arrives after that, the test passes without checking anything. Processing UI events for a short time before the assertion would make it reliable.
5. Nit. viewer.getTextWidget() can return null for a disposed viewer, and the new code then throws an NPE in documentChanged.
I'd be fine merging with 4 and 5 addressed, and doing 1–3 as a follow-up if you prefer.
This review was prepared with Claude Code (Anthropic) and checked by me before posting.

A late auto-insert response from the HTML or Vue language server was inserted at its original offset even if the user had kept typing, moved the caret or switched the editor input, which could put closing tags or quotes in the wrong place. Both reconcilers now capture the editor state with the request in a shared
EditorSnapshotand drop the response if that state has changed. This also removes a straySystem.out.printlnthat ran on every change in Vue editors.