Skip to content

fix: do not send didSave notification once the client is disposed - #101

Merged
MaximeCheramy merged 1 commit into
mainfrom
fix/did-save-after-dispose
Oct 15, 2026
Merged

MaximeCheramy merged 1 commit into
mainfrom
fix/did-save-after-dispose

Conversation

@MaximeCheramy

@MaximeCheramy MaximeCheramy commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

InitializeTextDocumentFeature saves every opened document with await infrastructure.writeFile(...) and then sends textDocument/didSave. If the manager is disposed while writeFile is still running (for example when the editor switches to another file and the old client is torn down), dispose() has already set languageClient to undefined. The next sendNotification then throws as an unhandled rejection:

TypeError: Cannot read properties of undefined (reading 'sendNotification')

clear() disposes the onDidOpenTextDocument listener, but it doesn't stop a save that's already running.

Fix

After writeFile resolves, return early if the underlying client is gone. That covers both the disposed case and the stopped-and-restarting case.

Testing

  • npm run lint passes, and npm run compile succeeds with the guard in dist/extensions.js.
  • npm test fails in the same 3 Infrastructure tests with and without this change, so those failures already exist on main.

The InitializeTextDocumentFeature awaits writeFile before sending the
didSave notification. If the manager is disposed (or the client stopped)
in the meantime, languageClient is undefined and sendNotification throws
"Cannot read properties of undefined (reading 'sendNotification')" as an
unhandled rejection.
@MaximeCheramy
MaximeCheramy merged commit f82856d into main Oct 15, 2026
2 checks passed
@MaximeCheramy
MaximeCheramy deleted the fix/did-save-after-dispose branch October 15, 2026 09:38
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.

2 participants