From f50aca723344970c545e11dfa06fb0e1323c64d8 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Wed, 29 Nov 2023 12:07:38 -0800 Subject: [PATCH] Properly build deactivate commands for powershell --- .../envCollectionActivation/deactivateService.ts | 9 +++++++-- .../envCollectionActivation/shellIntegrationService.ts | 2 +- .../terminalEnvVarCollectionService.unit.test.ts | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/terminals/envCollectionActivation/deactivateService.ts b/src/client/terminals/envCollectionActivation/deactivateService.ts index b763bd95e88c..0758f3e22311 100644 --- a/src/client/terminals/envCollectionActivation/deactivateService.ts +++ b/src/client/terminals/envCollectionActivation/deactivateService.ts @@ -8,7 +8,7 @@ import { ITerminalManager } from '../../common/application/types'; import { pathExists } from '../../common/platform/fs-paths'; import { _SCRIPTS_DIR } from '../../common/process/internal/scripts/constants'; import { identifyShellFromShellPath } from '../../common/terminal/shellDetectors/baseShellDetector'; -import { TerminalShellType } from '../../common/terminal/types'; +import { ITerminalHelper, TerminalShellType } from '../../common/terminal/types'; import { Resource } from '../../common/types'; import { waitForCondition } from '../../common/utils/async'; import { cache } from '../../common/utils/decorators'; @@ -37,6 +37,7 @@ export class TerminalDeactivateService implements ITerminalDeactivateService { constructor( @inject(ITerminalManager) private readonly terminalManager: ITerminalManager, @inject(IInterpreterService) private readonly interpreterService: IInterpreterService, + @inject(ITerminalHelper) private readonly terminalHelper: ITerminalHelper, ) {} @cache(-1, true) @@ -58,7 +59,11 @@ export class TerminalDeactivateService implements ITerminalDeactivateService { globalInterpreters.length > 0 && globalInterpreters[0] ? globalInterpreters[0].path : 'python'; const checkIfFileHasBeenCreated = () => pathExists(outputFile); const stopWatch = new StopWatch(); - terminal.sendText(`${interpreterPath} "${this.envVarScript}" "${outputFile}"`); + const command = this.terminalHelper.buildCommandForTerminal(shellType, interpreterPath, [ + this.envVarScript, + outputFile, + ]); + terminal.sendText(command); await waitForCondition(checkIfFileHasBeenCreated, 30_000, `"${outputFile}" file not created`); traceVerbose(`Time taken to get env vars using terminal is ${stopWatch.elapsedTime}ms`); } diff --git a/src/client/terminals/envCollectionActivation/shellIntegrationService.ts b/src/client/terminals/envCollectionActivation/shellIntegrationService.ts index 485af6f3cc99..dfeb8bad8abc 100644 --- a/src/client/terminals/envCollectionActivation/shellIntegrationService.ts +++ b/src/client/terminals/envCollectionActivation/shellIntegrationService.ts @@ -53,7 +53,7 @@ export class ShellIntegrationService implements IShellIntegrationService { const deferred = createDeferred(); const timestamp = new Date().getTime(); const name = `Python ${timestamp}`; - const onDidExecuteTerminalCommand = this.appShell.onDidExecuteTerminalCommand?.bind(this.appShell); + const { onDidExecuteTerminalCommand } = this.appShell; if (!onDidExecuteTerminalCommand) { // Proposed API is not available, assume shell integration is working at this point. return true; diff --git a/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts b/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts index daf3150fdbd0..c1955c2704e6 100644 --- a/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts +++ b/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts @@ -341,7 +341,7 @@ suite('Terminal Environment Variable Collection Service', () => { test('Also prepend deactivate script location if available', async () => { reset(terminalDeactivateService); - when(terminalDeactivateService.initializeScriptParams(anything())).thenResolve(); + when(terminalDeactivateService.initializeScriptParams(anything())).thenReject(); // Verify we swallow errors from here when(terminalDeactivateService.getScriptLocation(anything(), anything())).thenResolve('scriptLocation'); const processEnv = { PATH: 'hello/1/2/3' }; reset(environmentActivationService);