From a58b5386624409bc2503fce780c96286552416c2 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Thu, 27 Jan 2022 12:57:49 -0600 Subject: [PATCH] create process in an empty workspace when cwd is userHome (#141660) --- .../terminal/browser/terminalInstance.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index d8b6b5fd7301c..58dc799869e57 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -73,6 +73,8 @@ import { TerminalCapability } from 'vs/workbench/contrib/terminal/common/capabil import { ITextModel } from 'vs/editor/common/model'; import { IModelService } from 'vs/editor/common/services/model'; import { ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService'; +import { IHistoryService } from 'vs/workbench/services/history/common/history'; +import { Schemas } from 'vs/base/common/network'; const enum Constants { /** @@ -350,7 +352,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { @IWorkbenchEnvironmentService workbenchEnvironmentService: IWorkbenchEnvironmentService, @IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService, @IEditorService private readonly _editorService: IEditorService, - @IWorkspaceTrustRequestService private readonly _workspaceTrustRequestService: IWorkspaceTrustRequestService + @IWorkspaceTrustRequestService private readonly _workspaceTrustRequestService: IWorkspaceTrustRequestService, + @IHistoryService private readonly _historyService: IHistoryService ) { super(); @@ -1312,9 +1315,16 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { if (this._isDisposed) { return; } - - const trusted = await this._trust(); - if (!trusted) { + const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.file); + if (activeWorkspaceRootUri) { + const trusted = await this._trust(); + if (!trusted) { + this._onProcessExit({ message: nls.localize('workspaceNotTrustedCreateTerminal', "Cannot launch a terminal process in an untrusted workspace") }); + } + } else if (this._userHome && this._cwd !== this._userHome) { + // ensure that the process is launched in userHome for an empty workspace + this._shellLaunchConfig.cwd = this._userHome; + } else if (!this._userHome) { this._onProcessExit({ message: nls.localize('workspaceNotTrustedCreateTerminal', "Cannot launch a terminal process in an untrusted workspace") }); }