fix(vscode-ide-companion): register Disposables leaked by comma operators#28100
fix(vscode-ide-companion): register Disposables leaked by comma operators#28100ianfigueroa wants to merge 1 commit into
Conversation
…tors
Two comma operators in activate() wrapped pairs of Disposables as
`(A, B)`, which evaluates to only the last operand (B). The first
Disposable of each pair was never added to context.subscriptions, so it
leaked and was never disposed on deactivate:
- `(registerCommand('gemini.diff.accept', ...), registerCommand('gemini.diff.cancel', ...))`
leaked the gemini.diff.accept command.
- `(onDidChangeWorkspaceFolders(...), onDidGrantWorkspaceTrust(...))`
leaked the onDidChangeWorkspaceFolders handler.
Remove the wrapping parentheses so every Disposable is passed as a
separate argument to context.subscriptions.push(). Add regression tests
asserting both Disposables are registered.
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 in the extension activation logic where comma operators were incorrectly grouping Disposables, causing the first item in each pair to be discarded. By removing the wrapping parentheses, all Disposables are now correctly passed to the subscription manager, ensuring they are properly disposed of upon extension deactivation. 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 in the VS Code companion extension where certain event and command disposables were not properly registered in context.subscriptions due to an accidental use of the comma operator inside parentheses. Specifically, it removes the redundant wrapping parentheses around vscode.commands.registerCommand and vscode.workspace.onDidChangeWorkspaceFolders calls, ensuring all disposables are correctly added to the subscriptions array and disposed of on deactivation. Additionally, regression tests have been added to verify that both onDidChangeWorkspaceFolders and gemini.diff.accept disposables are properly registered. There are no review comments, so I have no feedback to provide.
Summary
activate()inextension.tshas twocontext.subscriptions.push(...)calls where a comma operator wrapped a pair of Disposables in parentheses as(A, B). A comma expression evaluates to its last operand, so each(A, B)collapsed to justB. The first Disposable of each pair was therefore never passed topush(), never added tocontext.subscriptions, and never disposed ondeactivate().Two Disposables leaked:
(registerCommand('gemini.diff.accept', ...), registerCommand('gemini.diff.cancel', ...))leaked thegemini.diff.acceptcommand registration.(onDidChangeWorkspaceFolders(...), onDidGrantWorkspaceTrust(...))leaked theonDidChangeWorkspaceFoldershandler.The fix removes the wrapping parentheses so every Disposable is passed as a separate argument to
context.subscriptions.push(), which is the variadic API it was always meant to use.Test plan
gemini.diff.acceptandonDidChangeWorkspaceFoldersDisposables end up incontext.subscriptions. Both fail against the old(A, B)code and pass with the fix.npx vitest run src/extension.test.tsinpackages/vscode-ide-companion: 13/13 pass.eslintandprettier --checkclean on both changed files.Fixes #27790