[REGRESSION] Fix didOpen handler binding#5496
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a regression in the VS Code PowerShell extension’s LSP middleware by ensuring textDocument/didOpen (and didChange) properly wait for SessionManager initialization even when invoked without a valid this context, and adds tests around the initialization gate behavior.
Changes:
- Convert
SessionManager’sdidOpenanddidChangemiddleware hooks to arrow-function fields to preservethisbinding. - Add unit tests validating
didOpen/didChangedefer callingnextuntil session initialization is released.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/session.ts | Makes didOpen/didChange resilient to lost this binding by using arrow-function fields while still gating on started. |
| test/core/session.test.ts | Adds tests asserting didOpen/didChange delay calling next until initialization completes. |
Comments suppressed due to low confidence (1)
test/core/session.test.ts:147
- Similar to the
didOpencase, this test currently callsmanager.didChange(...)as a method and doesn't exercise the unbound-callback scenario that caused the undefined-context regression. To prevent reintroducing the bug, call the handler via an extracted reference (or otherwise ensure it’s invoked without an implicit receiver) and assert it still gates onstartedbefore callingnext.
const didChangePromise = manager.didChange(changeEvent, next);
await Promise.resolve();
assert.equal(
nextCalled,
false,
"didChange should wait for initialization",
);
Agent-Logs-Url: https://github.com/PowerShell/vscode-powershell/sessions/f08084c8-dc63-46ac-8904-e2c86582ee90 Co-authored-by: JustinGrote <15258962+JustinGrote@users.noreply.github.com>
auto-merge was automatically disabled
May 13, 2026 16:25
Head branch was pushed to by a user without write access
Contributor
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve the
didOpenmethod to ensure it does not get stuck due to an undefined context. Add tests to verify the behavior ofdidOpenanddidChangemethods, confirming they wait for session initialization before proceeding.Fixes regression in bd33d21
PR Summary
Improve the
didOpenmethod to ensure it does not get stuck due to an undefined context. Add tests to verify the behavior ofdidOpenanddidChangemethods, confirming they wait for session initialization before proceeding.PR Checklist
Note: Tick the boxes below that apply to this pull request by putting an
xbetween the square brackets.Please mark anything not applicable to this PR
NA.WIP:to the beginning of the title and remove the prefix when the PR is ready