Skip to content

Commit a58b538

Browse files
authored
create process in an empty workspace when cwd is userHome (microsoft#141660)
1 parent 9b0917d commit a58b538

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ import { TerminalCapability } from 'vs/workbench/contrib/terminal/common/capabil
7373
import { ITextModel } from 'vs/editor/common/model';
7474
import { IModelService } from 'vs/editor/common/services/model';
7575
import { ITextModelContentProvider, ITextModelService } from 'vs/editor/common/services/resolverService';
76+
import { IHistoryService } from 'vs/workbench/services/history/common/history';
77+
import { Schemas } from 'vs/base/common/network';
7678

7779
const enum Constants {
7880
/**
@@ -350,7 +352,8 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
350352
@IWorkbenchEnvironmentService workbenchEnvironmentService: IWorkbenchEnvironmentService,
351353
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService,
352354
@IEditorService private readonly _editorService: IEditorService,
353-
@IWorkspaceTrustRequestService private readonly _workspaceTrustRequestService: IWorkspaceTrustRequestService
355+
@IWorkspaceTrustRequestService private readonly _workspaceTrustRequestService: IWorkspaceTrustRequestService,
356+
@IHistoryService private readonly _historyService: IHistoryService
354357
) {
355358
super();
356359

@@ -1312,9 +1315,16 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
13121315
if (this._isDisposed) {
13131316
return;
13141317
}
1315-
1316-
const trusted = await this._trust();
1317-
if (!trusted) {
1318+
const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.file);
1319+
if (activeWorkspaceRootUri) {
1320+
const trusted = await this._trust();
1321+
if (!trusted) {
1322+
this._onProcessExit({ message: nls.localize('workspaceNotTrustedCreateTerminal', "Cannot launch a terminal process in an untrusted workspace") });
1323+
}
1324+
} else if (this._userHome && this._cwd !== this._userHome) {
1325+
// ensure that the process is launched in userHome for an empty workspace
1326+
this._shellLaunchConfig.cwd = this._userHome;
1327+
} else if (!this._userHome) {
13181328
this._onProcessExit({ message: nls.localize('workspaceNotTrustedCreateTerminal', "Cannot launch a terminal process in an untrusted workspace") });
13191329
}
13201330

0 commit comments

Comments
 (0)