Skip to content

Commit

Permalink
Dispose of Launch terminal if environment has changed (#3902)
Browse files Browse the repository at this point in the history
* Compare entire terminal launch environment and dispose if not equal

* Updated CHANGELOG

---------

Co-authored-by: Garrett Campbell <[email protected]>
  • Loading branch information
jophippe and gcampbell-msft authored Jul 22, 2024
1 parent 8ed18b2 commit 01db4d6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Bug Fixes:
- Fix issue with CMakeLists.txt depth search. [#3901](https://github.com/microsoft/vscode-cmake-tools/issues/3901)
- Fix localized file path for schema files. [#3872](https://github.com/microsoft/vscode-cmake-tools/issues/3872)
- Disable annoy and invalid extenion message about fix windows sdk for MSVC 2022. [#3837](https://github.com/microsoft/vscode-cmake-tools/pull/3837)
- Fix re-using a terminal for launching even when the environment has changed. [#3478](https://github.com/microsoft/vscode-cmake-tools/issues/3478)

## 1.18.43

Expand Down
47 changes: 21 additions & 26 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1288,11 +1288,7 @@ export class CMakeProject {
return false;
}

private refreshLaunchEnvironment: boolean = false;
async setKit(kit: Kit | null) {
if (!this.activeKit || (kit && this.activeKit.name !== kit.name)) {
this.refreshLaunchEnvironment = true;
}
this._activeKit = kit;
if (kit) {
log.debug(localize('injecting.new.kit', 'Injecting new Kit into CMake driver'));
Expand Down Expand Up @@ -2648,7 +2644,7 @@ export class CMakeProject {
}

/**
* Both debugTarget and launchTarget called this funciton, so it's refactored out
* Both debugTarget and launchTarget called this function, so it's refactored out
* Array.concat's performance would not beat the Dict.merge a lot.
* This is also the point to fixing the issue #1987
*/
Expand Down Expand Up @@ -2772,26 +2768,7 @@ export class CMakeProject {
});

private async createTerminal(executable: ExecutableTarget): Promise<vscode.Terminal> {
const launchBehavior = this.workspaceContext.config.launchBehavior.toLowerCase();
if (launchBehavior !== "newterminal") {
for (const [, terminal] of this.launchTerminals) {
const creationOptions = terminal.creationOptions! as vscode.TerminalOptions;
const executablePath = creationOptions.env![this.launchTerminalTargetName];
const terminalPath = creationOptions.env![this.launchTerminalPath];
if (executablePath === executable.name) {
if (launchBehavior === 'breakandreuseterminal') {
terminal.sendText('\u0003');
}
// Dispose the terminal if the User's settings for preferred terminal have changed since the current target is launched,
// or if the kit is changed, which means the environment variables are possibly updated.
if (terminalPath !== vscode.env.shell || this.refreshLaunchEnvironment) {
terminal.dispose();
break;
}
return terminal;
}
}
}
// Create terminal options
const userConfig = this.workspaceContext.config.debugConfig;
const drv = await this.getCMakeDriverInstance();
const launchEnv = await this.getTargetLaunchEnvironment(drv, userConfig.environment);
Expand All @@ -2805,7 +2782,25 @@ export class CMakeProject {
options.env[this.launchTerminalPath] = vscode.env.shell;
}

this.refreshLaunchEnvironment = false;
const launchBehavior = this.workspaceContext.config.launchBehavior.toLowerCase();
// Check for terminal re-use
if (launchBehavior !== "newterminal") {
for (const [, terminal] of this.launchTerminals) {
const creationOptions = terminal.creationOptions! as vscode.TerminalOptions;
// If the environment has changed at all since the last run, dispose of this terminal
if (JSON.stringify(creationOptions.env) !== JSON.stringify(options.env)) {
terminal.dispose();
break;
}

if (launchBehavior === 'breakandreuseterminal') {
terminal.sendText('\u0003');
}

return terminal;
}
}

return vscode.window.createTerminal(options);
}

Expand Down

0 comments on commit 01db4d6

Please sign in to comment.