Skip to content

Snapshot TextDocuments when delayOpenNotifications=true to avoid serving updated info to middleware/server#1755

Draft
DanTup wants to merge 1 commit intomicrosoft:mainfrom
DanTup:delay-open-notifications
Draft

Snapshot TextDocuments when delayOpenNotifications=true to avoid serving updated info to middleware/server#1755
DanTup wants to merge 1 commit intomicrosoft:mainfrom
DanTup:delay-open-notifications

Conversation

@DanTup
Copy link
Copy Markdown
Contributor

@DanTup DanTup commented Apr 22, 2026

When delayOpenNotifications is enabled and an open notification is delayed, we cannot use the live VS Code TextDocument to pass to middleware or to the server because it may have updated version/content info.

Instead, capture a snapshot of the document at the time the original notification would've been sent, and then when the notification will be sent, provide that snapshot to the middleware and build the server parameters from it.

Fixes #1695

…ing updated info to middleware/server

When delayOpenNotifications is enabled and an open notification is delayed, we cannot use the live VS Code TextDocument to pass to middleware or to the server because it may have updated version/content info.

Instead, capture a snapshot of the document at the time the original notification would've been sent, and then when the notification will be sent, provide that snapshot to the middleware and build the server parameters from it.

Fixes microsoft#1695
@DanTup DanTup force-pushed the delay-open-notifications branch from 3b58e46 to d12ba08 Compare April 22, 2026 18:18
} No newline at end of file
}

class TextDocumentSnapshot implements TextDocument {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbaeumer the implementation here was written by GPT-5.4 with some tidying up by me. I don't like that so much is repeated here from VS Code (and I haven't tried to verify the behaviour matches perfectly, because I'm hoping you might have a better idea :-))

I did add 'vscode-languageserver-textdocument' but it only provided a small number of the methods we needed.

I also noticed there is a very similar class here, but it uses some additional types from VS Code so I couldn't just lift it:

https://github.com/microsoft/vscode/blob/a14d0306921f937f5644bb89bfbb66c699e66409/extensions/copilot/src/platform/editing/common/textDocumentSnapshot.ts

I wonder if it'd be better adding a good implementation of this to vscode-languageserver-textdocument and then using it both in Copilot and here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

delayOpenNotifications=true results in the wrong document version and content being sent in didOpen notification

1 participant