Skip to content

Commit

Permalink
Properly build deactivate commands for powershell (#22570)
Browse files Browse the repository at this point in the history
For #20950
  • Loading branch information
Kartik Raj authored Nov 29, 2023
1 parent db6e15e commit 61fcf3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
Expand All @@ -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`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 61fcf3a

Please sign in to comment.