Skip to content

Commit d81d1e6

Browse files
authored
Merge pull request microsoft#183429 from microsoft/tyriar/183428
Move terminalResolver into contrib/terminal
2 parents 1bd0632 + bcb07d6 commit d81d1e6

File tree

5 files changed

+19
-30
lines changed

5 files changed

+19
-30
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import { IPreferencesService } from 'vs/workbench/services/preferences/common/pr
7979
import type { IMarker, Terminal as XTermTerminal } from 'xterm';
8080
import { IAudioCueService, AudioCue } from 'vs/platform/audioCues/browser/audioCueService';
8181
import { FileSystemProviderCapabilities, IFileService } from 'vs/platform/files/common/files';
82-
import { preparePathForShell } from 'vs/workbench/contrib/terminal/common/terminalEnvironment';
82+
import { getWorkspaceForTerminal, preparePathForShell } from 'vs/workbench/contrib/terminal/common/terminalEnvironment';
8383
import { IEnvironmentVariableCollection, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable';
8484
import { ISimpleSelectedSuggestion } from 'vs/workbench/services/suggest/browser/simpleSuggestWidget';
8585
import { TERMINAL_BACKGROUND_COLOR } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry';
@@ -88,7 +88,6 @@ import { PANEL_BACKGROUND, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme
8888
import { TerminalExtensionsRegistry } from 'vs/workbench/contrib/terminal/browser/terminalExtensions';
8989
import { ResolvedKeybinding } from 'vs/base/common/keybindings';
9090
import { ResultKind } from 'vs/platform/keybinding/common/keybindingResolver';
91-
import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver';
9291
import { AccessibilityVerbositySettingId } from 'vs/workbench/contrib/accessibility/browser/accessibilityContribution';
9392

9493
const enum Constants {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { TaskSettingId } from 'vs/workbench/contrib/tasks/common/tasks';
3838
import Severity from 'vs/base/common/severity';
3939
import { INotificationService } from 'vs/platform/notification/common/notification';
4040
import { IEnvironmentVariableCollection, IMergedEnvironmentVariableCollection } from 'vs/platform/terminal/common/environmentVariable';
41-
import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver';
4241
import { generateUuid } from 'vs/base/common/uuid';
4342

4443
const enum ProcessConstants {
@@ -150,7 +149,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
150149
@INotificationService private readonly _notificationService: INotificationService
151150
) {
152151
super();
153-
this._cwdWorkspaceFolder = getWorkspaceForTerminal(cwd, this._workspaceContextService, this._historyService);
152+
this._cwdWorkspaceFolder = terminalEnvironment.getWorkspaceForTerminal(cwd, this._workspaceContextService, this._historyService);
154153
this.ptyProcessReady = this._createPtyProcessReadyPromise();
155154
this.getLatency();
156155
this._ackDataBufferer = new AckDataBufferer(e => this._process?.acknowledgeDataEvent(e));
@@ -415,7 +414,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
415414

416415
// Fetch any extension environment additions and apply them
417416
private async _resolveEnvironment(backend: ITerminalBackend, variableResolver: terminalEnvironment.VariableResolver | undefined, shellLaunchConfig: IShellLaunchConfig): Promise<IProcessEnvironment> {
418-
const workspaceFolder = getWorkspaceForTerminal(shellLaunchConfig.cwd, this._workspaceContextService, this._historyService);
417+
const workspaceFolder = terminalEnvironment.getWorkspaceForTerminal(shellLaunchConfig.cwd, this._workspaceContextService, this._historyService);
419418
const platformKey = isWindows ? 'windows' : (isMacintosh ? 'osx' : 'linux');
420419
const envFromConfigValue = this._configurationService.getValue<ITerminalEnvironment | undefined>(`terminal.integrated.env.${platformKey}`);
421420
this._configHelper.showRecommendations(shellLaunchConfig);

src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99

1010
import * as path from 'vs/base/common/path';
1111
import { URI } from 'vs/base/common/uri';
12-
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
12+
import { IWorkspaceContextService, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
1313
import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver';
1414
import { sanitizeProcessEnvironment } from 'vs/base/common/processes';
1515
import { ILogService } from 'vs/platform/log/common/log';
1616
import { IShellLaunchConfig, ITerminalEnvironment, TerminalSettingId, TerminalSettingPrefix, TerminalShellType, WindowsShellType } from 'vs/platform/terminal/common/terminal';
1717
import { IProcessEnvironment, isWindows, language, OperatingSystem, platform, Platform } from 'vs/base/common/platform';
1818
import { escapeNonWindowsPath, sanitizeCwd } from 'vs/platform/terminal/common/terminalEnvironment';
19-
import { isString } from 'vs/base/common/types';
19+
import { isString, withNullAsUndefined } from 'vs/base/common/types';
2020
import { ITerminalBackend } from 'vs/workbench/contrib/terminal/common/terminal';
21+
import { IHistoryService } from 'vs/workbench/services/history/common/history';
2122

2223
export function mergeEnvironments(parent: IProcessEnvironment, other: ITerminalEnvironment | undefined): void {
2324
if (!other) {
@@ -470,3 +471,15 @@ export async function preparePathForShell(resource: string | URI, executable: st
470471

471472
return escapeNonWindowsPath(originalPath);
472473
}
474+
475+
export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService): IWorkspaceFolder | undefined {
476+
const cwdUri = typeof cwd === 'string' ? URI.parse(cwd) : cwd;
477+
let workspaceFolder = cwdUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(cwdUri)) : undefined;
478+
if (!workspaceFolder) {
479+
// fallback to last active workspace if cwd is not available or it is not in workspace
480+
// TOOD: last active workspace is known to be unreliable, we should remove this fallback eventually
481+
const activeWorkspaceRootUri = historyService.getLastActiveWorkspaceRoot();
482+
workspaceFolder = activeWorkspaceRootUri ? withNullAsUndefined(workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
483+
}
484+
return workspaceFolder;
485+
}

src/vs/workbench/contrib/terminal/electron-sandbox/localTerminalBackend.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import * as terminalEnvironment from 'vs/workbench/contrib/terminal/common/termi
2929
import { IProductService } from 'vs/platform/product/common/productService';
3030
import { IEnvironmentVariableService } from 'vs/workbench/contrib/terminal/common/environmentVariable';
3131
import { BaseTerminalBackend } from 'vs/workbench/contrib/terminal/browser/baseTerminalBackend';
32-
import { getWorkspaceForTerminal } from 'vs/workbench/services/configurationResolver/common/terminalResolver';
3332
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService';
3433
import { Client as MessagePortClient } from 'vs/base/parts/ipc/common/ipc.mp';
3534
import { acquirePort } from 'vs/base/parts/ipc/electron-sandbox/ipc.mp';
@@ -297,7 +296,7 @@ class LocalTerminalBackend extends BaseTerminalBackend implements ITerminalBacke
297296
const baseEnv = await (shellLaunchConfig.useShellEnvironment ? this.getShellEnvironment() : this.getEnvironment());
298297
const env = await terminalEnvironment.createTerminalEnvironment(shellLaunchConfig, envFromConfigValue, variableResolver, this._productService.version, this._configurationService.getValue(TerminalSettingId.DetectLocale), baseEnv);
299298
if (!shellLaunchConfig.strictEnv && !shellLaunchConfig.hideFromUser) {
300-
const workspaceFolder = getWorkspaceForTerminal(shellLaunchConfig.cwd, this._workspaceContextService, this._historyService);
299+
const workspaceFolder = terminalEnvironment.getWorkspaceForTerminal(shellLaunchConfig.cwd, this._workspaceContextService, this._historyService);
301300
await this._environmentVariableService.mergedCollection.applyToProcessEnvironment(env, { workspaceFolder }, variableResolver);
302301
}
303302
return env;

src/vs/workbench/services/configurationResolver/common/terminalResolver.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)