-
Notifications
You must be signed in to change notification settings - Fork 3
Make sure that the other visual stuff works as before. #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure that the other visual stuff works as before. #152
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request refactors the Flox environment activation management by moving process lifecycle management from the extension.ts file into the Env class in env.ts. The main goal is to improve encapsulation and maintainability by centralizing the activation process management within the Env class.
Key changes:
- Moved
floxActivateProcessfrom a module-level variable to an instance property of theEnvclass - Created
spawnActivateProcess()andkillActivateProcess()methods to encapsulate process management logic - Modified
exec()method to automatically wrap commands inflox activatewhen an activation process is running - Updated environment active detection to check for the existence of
floxActivateProcessinstead of parsing environment variables
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/extension.ts | Removed process management code and updated to use new Env methods for spawning and killing the activation process |
| src/env.ts | Added floxActivateProcess property, implemented spawnActivateProcess() and killActivateProcess() methods, and enhanced exec() to wrap commands when activation is active |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/extension.ts
Outdated
| }); | ||
|
|
||
| let didActivate = await env.spawnActivateProcess(); | ||
| if(didActivate) { |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Missing space after if keyword. Add a space between if and the opening parenthesis for consistency with TypeScript style guidelines: if (didActivate).
| if(didActivate) { | |
| if (didActivate) { |
src/env.ts
Outdated
| if (this.floxActivateProcess) { | ||
| return await promisify(execFile)('flox', | ||
| ['activate', "--dir", this.workspaceUri?.fsPath || "", '--'] | ||
| .concat([command]) | ||
| .concat(options.argv), | ||
| execOptions); | ||
| } |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential issue with recursive flox activate calls. When this.floxActivateProcess is running and exec("flox", { argv: ["activate", ...] }) is called (e.g., from line 63 in the constructor), it will wrap it as flox activate --dir ... -- flox activate ..., creating a nested activation. Consider adding a check to skip the wrapping when the command is already "flox" with "activate" as the first argument, or handle this case explicitly.
| this.floxActivateProcess.on('exit', (code, signal) => { | ||
| console.log(`Flox activate process exited with code ${code} and signal ${signal}`); | ||
| this.floxActivateProcess = undefined; | ||
| this.context.workspaceState.update('flox.activatePid', undefined); | ||
| vscode.commands.executeCommand('setContext', 'flox.envActive', false); | ||
| }); | ||
|
|
||
| // Handle errors | ||
| this.floxActivateProcess.on('error', (error) => { | ||
| console.error('Flox activate process error:', error); | ||
| this.displayError(`Failed to start flox activate: ${error.message}`); | ||
| this.floxActivateProcess = undefined; | ||
| this.context.workspaceState.update('flox.activatePid', undefined); | ||
| vscode.commands.executeCommand('setContext', 'flox.envActive', false); | ||
| }); |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The async operations this.context.workspaceState.update() and vscode.commands.executeCommand() in the event handlers are not awaited. While this might be intentional to avoid blocking the event handler, it could lead to race conditions or unhandled promise rejections. Consider either awaiting these calls or explicitly handling any potential errors, e.g.:
this.context.workspaceState.update('flox.activatePid', undefined).catch(err =>
console.error('Failed to update workspace state:', err)
);
src/extension.ts
Outdated
| console.error('Failed to kill flox activate process:', error); | ||
| await env.displayError(`Failed to deactivate Flox environment: ${error}`); | ||
| } | ||
| env.killActivateProcess(); |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The killActivateProcess() method is async but not awaited here. This could lead to issues where the command completes before the process is properly cleaned up and state updates are finished. Add await before the call.
| env.killActivateProcess(); | |
| await env.killActivateProcess(); |
src/env.ts
Outdated
| } | ||
| } | ||
|
|
||
| async spawnActivateProcess(): Promise<Boolean> { |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the primitive wrapper type Boolean instead of the primitive type boolean. TypeScript best practice is to use lowercase boolean for return types. Change Promise<Boolean> to Promise<boolean>.
| async spawnActivateProcess(): Promise<Boolean> { | |
| async spawnActivateProcess(): Promise<boolean> { |
garbas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼 generally good, just one comment that we can fix in the following PRs.
255d5c9 to
033ce64
Compare
066af3d to
a6e774f
Compare
a6e774f to
6246f93
Compare
6246f93 to
07888d0
Compare
No description provided.