fix(vscode-ide-companion): stop leaking gemini.diff.accept and onDidChangeWorkspaceFolders disposables#28526
Conversation
…hangeWorkspaceFolders disposables The two context.subscriptions.push(...) calls wrapped a pair of registrations in a stray parenthesis pair, collapsing them into a comma expression whose value was only the last operand. As a result the `gemini.diff.accept` command Disposable and the `onDidChangeWorkspaceFolders` listener Disposable were created but never added to context.subscriptions, so they were never disposed on deactivation (re-activation then threw 'command already exists' and a stale listener kept firing). Remove the extra parentheses so each registration is its own argument to push(). Add a regression test that tags the created Disposables and asserts both land in context.subscriptions. Fixes google-gemini#27790
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a resource leak issue where specific command and listener registrations were not being added to the extension's subscription list due to incorrect syntax. By removing the stray parentheses, these objects are now correctly tracked, ensuring they are properly disposed of during extension deactivation and preventing duplicate registration errors on re-activation. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
📊 PR Size: size/S
|
There was a problem hiding this comment.
Code Review
This pull request fixes a bug where certain VS Code command and listener registrations were wrapped in stray parentheses, causing them to be evaluated as comma expressions and preventing them from being tracked for disposal in context.subscriptions. A new test is added to verify that all created Disposables are correctly registered. The reviewer suggested using optional chaining when inspecting context.subscriptions in the test to avoid potential TypeError exceptions from undefined elements.
| expect(pushed.some((d) => d.command === 'gemini.diff.accept')).toBe(true); | ||
| expect( | ||
| pushed.some((d) => d.kind === 'onDidChangeWorkspaceFolders'), | ||
| ).toBe(true); |
There was a problem hiding this comment.
Since some of the mocked VS Code APIs (such as onDidCloseTextDocument or registerTextDocumentContentProvider) return undefined by default in the test environment, context.subscriptions will contain undefined elements. Accessing d.command or d.kind directly on these elements will throw a TypeError: Cannot read properties of undefined. Use optional chaining (d?.command and d?.kind) to safely inspect the subscriptions.
| expect(pushed.some((d) => d.command === 'gemini.diff.accept')).toBe(true); | |
| expect( | |
| pushed.some((d) => d.kind === 'onDidChangeWorkspaceFolders'), | |
| ).toBe(true); | |
| expect(pushed.some((d) => d?.command === 'gemini.diff.accept')).toBe(true); | |
| expect( | |
| pushed.some((d) => d?.kind === 'onDidChangeWorkspaceFolders'), | |
| ).toBe(true); |
Summary
Fixes #27790.
The two
context.subscriptions.push(...)calls inactivate()wrapped a pair of registrations in a stray parenthesis pair, collapsing them into a comma expression whose value was only the last operand. As a result thegemini.diff.acceptcommand Disposable and theonDidChangeWorkspaceFolderslistener Disposable were created but never added tocontext.subscriptions, so they were never disposed on deactivation. On re-activation within the same extension host this threwcommand 'gemini.diff.accept' already exists, and the staleonDidChangeWorkspaceFolderslistener kept firingideServer.syncEnvVars()against a stoppedIDEServer.push().extension.test.tsthat tags the created Disposables and asserts bothgemini.diff.acceptandonDidChangeWorkspaceFoldersland incontext.subscriptions.Test plan
cd packages/vscode-ide-companion && npm test(vitest): new test inextension.test.tspasses; existing tests unaffected.