diff --git a/src/client/terminals/codeExecution/codeExecutionManager.ts b/src/client/terminals/codeExecution/codeExecutionManager.ts index 740256ca78b3..30e5b7facd2d 100644 --- a/src/client/terminals/codeExecution/codeExecutionManager.ts +++ b/src/client/terminals/codeExecution/codeExecutionManager.ts @@ -5,7 +5,7 @@ import { inject, injectable } from 'inversify'; import { Disposable, EventEmitter, Terminal, Uri } from 'vscode'; - +import * as path from 'path'; import { ICommandManager, IDocumentManager } from '../../common/application/types'; import { Commands } from '../../common/constants'; import '../../common/extensions'; @@ -130,6 +130,15 @@ export class CodeExecutionManager implements ICodeExecutionManager { if (!fileToExecute) { return; } + + // Check on setting terminal.executeInFileDir + const pythonSettings = this.configSettings.getSettings(file); + let cwd = pythonSettings.terminal.executeInFileDir ? path.dirname(fileToExecute.fsPath) : undefined; + + // Check on setting terminal.launchArgs + const launchArgs = pythonSettings.terminal.launchArgs; + const totalArgs = [...launchArgs, fileToExecute.fsPath.fileToCommandArgumentForPythonExt()]; + const fileAfterSave = await codeExecutionHelper.saveFileIfDirty(fileToExecute); if (fileAfterSave) { fileToExecute = fileAfterSave; @@ -138,19 +147,9 @@ export class CodeExecutionManager implements ICodeExecutionManager { const show = this.shouldTerminalFocusOnStart(fileToExecute); let terminal: Terminal | undefined; if (dedicated) { - terminal = await runInDedicatedTerminal( - fileToExecute, - [fileToExecute.fsPath.fileToCommandArgumentForPythonExt()], - undefined, - show, - ); + terminal = await runInDedicatedTerminal(fileToExecute, totalArgs, cwd, show); } else { - terminal = await runInTerminal( - fileToExecute, - [fileToExecute.fsPath.fileToCommandArgumentForPythonExt()], - undefined, - show, - ); + terminal = await runInTerminal(fileToExecute, totalArgs, cwd, show); } if (terminal) {