terminalEnvironment.ts ×15

Frontier kind: Code frontier

unlabeled · c_156a6e0a07f2

44 tests · 24770 LOC · 126 files · introduces 0 tests · 62 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
15 ranges62 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2699 ranges24770 lines · 126 files · Browse complete extent
All tests (intent)
44 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 62 introduced LOC across 15 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts 62 introduced LOC · 15 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- terminalEnvironment.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > /**
7 > * This module contains utility functions related to the environment, cwd and paths.
8 > */
9 >
10 > import * as path from '../../../../base/common/path.js';
11 > import { URI, uriToFsPath } from '../../../../base/common/uri.js';
12 > import { IWorkspaceContextService, IWorkspaceFolder } from '../../../../platform/workspace/common/workspace.js';
13 > import { IConfigurationResolverService } from '../../../services/configurationResolver/common/configurationResolver.js';
14 > import { sanitizeProcessEnvironment } from '../../../../base/common/processes.js';
15 > import { IShellLaunchConfig, ITerminalBackend, ITerminalEnvironment, ShellIntegrationTimeoutOverride, TerminalSettingId, TerminalShellType, WindowsShellType } from '../../../../platform/terminal/common/terminal.js';
16 > import { IProcessEnvironment, isWindows, isMacintosh, language, OperatingSystem } from '../../../../base/common/platform.js';
17 > import { escapeNonWindowsPath, sanitizeCwd } from '../../../../platform/terminal/common/terminalEnvironment.js';
18 > import { isNumber, isString } from '../../../../base/common/types.js';
19 > import { IHistoryService } from '../../../services/history/common/history.js';
20 > import { ILogService } from '../../../../platform/log/common/log.js';
21 > import type { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
22 >
23 > export function mergeEnvironments(parent: IProcessEnvironment, other: ITerminalEnvironment | undefined): void {
24 if (!other) {
25 return;
51 }
52 }
54 function _mergeEnvironmentValue(env: ITerminalEnvironment, key: string, value: string | null): void {
55 if (isString(value)) {
59 }
60 }
62 > export function addTerminalEnvironmentKeys(env: IProcessEnvironment, version: string | undefined, locale: string | undefined, detectLocale: 'auto' | 'off' | 'on'): void {
63 env['TERM_PROGRAM'] = 'vscode';
64 if (version) {
70 env['COLORTERM'] = 'truecolor';
71 }
73 function mergeNonNullKeys(env: IProcessEnvironment, other: ITerminalEnvironment | undefined) {
74 if (!other) {
82 }
83 }
85 async function resolveConfigurationVariables(variableResolver: VariableResolver, env: ITerminalEnvironment): Promise<ITerminalEnvironment> {
86 await Promise.all(Object.entries(env).map(async ([key, value]) => {
96 return env;
97 }
99 > export function shouldSetLangEnvVariable(env: IProcessEnvironment, detectLocale: 'auto' | 'off' | 'on'): boolean {
100 if (detectLocale === 'on') {
101 return true;
107 return false; // 'off'
108 }
110 > export function getLangEnvVariable(locale?: string): string {
111 const parts = locale ? locale.split('-') : [];
112 const n = parts.length;
183 return parts.join('_') + '.UTF-8';
184 }
186 export async function getCwd(
187 shell: IShellLaunchConfig,
220 return sanitizeCwd(cwd);
221 }
223 async function _resolveCwd(cwd: string, variableResolver: VariableResolver | undefined, logService?: ILogService): Promise<string | undefined> {
224 if (variableResolver) {
232 return cwd;
233 }
235 > export type VariableResolver = (str: string) => Promise<string>;
236 >
237 > export function createVariableResolver(lastActiveWorkspace: IWorkspaceFolder | undefined, env: IProcessEnvironment, configurationResolverService: IConfigurationResolverService | undefined): VariableResolver | undefined {
238 if (!configurationResolverService) {
239 return undefined;
241 return (str) => configurationResolverService.resolveWithEnvironment(env, lastActiveWorkspace, str);
242 }
244 export async function createTerminalEnvironment(
245 shellLaunchConfig: IShellLaunchConfig,
304 return env;
305 }
307 > /**
308 > * Takes a path and returns the properly escaped path to send to a given shell. On Windows, this
309 > * included trying to prepare the path for WSL if needed.
310 > *
311 > * @param originalPath The path to be escaped and formatted.
312 > * @param executable The executable off the shellLaunchConfig.
313 > * @param title The terminal's title.
314 > * @param shellType The type of shell the path is being sent to.
315 > * @param backend The backend for the terminal.
316 > * @param isWindowsFrontend Whether the frontend is Windows, this is only exposed for injection via
317 > * tests.
318 > * @returns An escaped version of the path to be executed in the terminal.
319 > */
320 export async function preparePathForShell(resource: string | URI, executable: string | undefined, title: string, shellType: TerminalShellType | undefined, backend: Pick<ITerminalBackend, 'getWslPath'> | undefined, os: OperatingSystem | undefined, isWindowsFrontend: boolean = isWindows): Promise<string> {
321 let originalPath: string;
379 return escapeNonWindowsPath(originalPath, shellType);
380 }
382 > export function getWorkspaceForTerminal(cwd: URI | string | undefined, workspaceContextService: IWorkspaceContextService, historyService: IHistoryService): IWorkspaceFolder | undefined {
383 const cwdUri = isString(cwd) ? URI.parse(cwd) : cwd;
384 let workspaceFolder = cwdUri ? workspaceContextService.getWorkspaceFolder(cwdUri) ?? undefined : undefined;
391 return workspaceFolder;
392 }
394 export async function getUriLabelForShell(uri: URI | string, backend: Pick<ITerminalBackend, 'getWslPath'>, shellType?: TerminalShellType, os?: OperatingSystem, isWindowsFrontend: boolean = isWindows): Promise<string> {
395 let path = isString(uri) ? uri : uri.fsPath;
410 }
411 }
413 > /**
414 > * Gets the unified duration to wait for shell integration after the terminal launches before
415 > * declaring the terminal lacks shell integration.
416 > */
417 > export function getShellIntegrationTimeout(
418 configurationService: IConfigurationService,
419 siInjectionEnabled: boolean,