Skip to content

Commit 27b1c8c

Browse files
author
Kartik Raj
authored
Always change drive letter if a file outside the workspace has been run on Windows (#18146)
1 parent 3454e66 commit 27b1c8c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/client/terminals/codeExecution/terminalCodeExecution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ICodeExecutionService } from '../../terminals/types';
1616

1717
@injectable()
1818
export class TerminalCodeExecutionProvider implements ICodeExecutionService {
19+
private hasRanOutsideCurrentDrive = false;
1920
protected terminalTitle!: string;
2021
private _terminalService!: ITerminalService;
2122
private replActive?: Promise<boolean>;
@@ -98,7 +99,8 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
9899
? this.workspace.rootPath.replace(/\:.*/g, '')
99100
: undefined;
100101
const fileDrive = fileDirPath.replace(/\:.*/g, '');
101-
if (fileDrive !== currentDrive) {
102+
if (fileDrive !== currentDrive || this.hasRanOutsideCurrentDrive) {
103+
this.hasRanOutsideCurrentDrive = true;
102104
await this.getTerminalService(file).sendText(`${fileDrive}:`);
103105
}
104106
}

src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ suite('Terminal - Code Execution', () => {
179179
await ensureWeSetCurrentDriveBeforeChangingDirectory(true);
180180
});
181181

182+
test('Ensure once set current drive before, we always send command to change the drive letter for subsequent executions', async () => {
183+
await ensureWeSetCurrentDriveBeforeChangingDirectory(true);
184+
const file = Uri.file(path.join('c:', 'path', 'to', 'file', 'one.py'));
185+
await executor.executeFile(file);
186+
terminalService.verify(async (t) => t.sendText(TypeMoq.It.isValue('c:')), TypeMoq.Times.once());
187+
});
188+
182189
async function ensureWeDoNotChangeDriveIfDriveLetterSameAsFileDriveLetter(
183190
_isWindows: boolean,
184191
): Promise<void> {

0 commit comments

Comments
 (0)