Skip to content

Commit 23215fd

Browse files
committed
Add environmentChangesIndicator setting
Part of microsoft#46696
1 parent 9cdf250 commit 23215fd

7 files changed

Lines changed: 45 additions & 7 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal
99
import { localize } from 'vs/nls';
1010

1111
export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo {
12+
readonly requiresAction = true;
13+
1214
constructor(
1315
private readonly _diff: IMergedEnvironmentVariableCollectionDiff,
1416
private readonly _terminalId: number,
@@ -57,6 +59,8 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo {
5759
}
5860

5961
export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariableInfo {
62+
readonly requiresAction = false;
63+
6064
constructor(
6165
private _collection: IMergedEnvironmentVariableCollection
6266
) {

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
9999

100100
private _widgetManager: TerminalWidgetManager = this._instantiationService.createInstance(TerminalWidgetManager);
101101
private _linkManager: TerminalLinkManager | undefined;
102-
private _environmentVariableWidget: EnvironmentVariableInfoWidget | undefined;
102+
private _environmentVariableWidgetDisposable: IDisposable | undefined;
103103
private _commandTrackerAddon: CommandTrackerAddon | undefined;
104104
private _navigationModeAddon: INavigationMode & ITerminalAddon | undefined;
105105

@@ -1157,6 +1157,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
11571157
// Never set webgl as it's an addon not a rendererType
11581158
this._safeSetOption('rendererType', config.rendererType === 'auto' ? 'canvas' : config.rendererType);
11591159
}
1160+
this._refreshEnvironmentVariableInfoWidgetState(this._processManager.environmentVariableInfo);
11601161
}
11611162

11621163
private async _updateUnicodeVersion(): Promise<void> {
@@ -1360,9 +1361,22 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
13601361
}
13611362

13621363
private _onEnvironmentVariableInfoChanged(info: IEnvironmentVariableInfo): void {
1363-
this._environmentVariableWidget?.dispose();
1364-
this._environmentVariableWidget = this._instantiationService.createInstance(EnvironmentVariableInfoWidget, info);
1365-
this._widgetManager.attachWidget(this._environmentVariableWidget);
1364+
this._refreshEnvironmentVariableInfoWidgetState(info);
1365+
}
1366+
1367+
private _refreshEnvironmentVariableInfoWidgetState(info?: IEnvironmentVariableInfo): void {
1368+
this._environmentVariableWidgetDisposable?.dispose();
1369+
1370+
// Check if the widget should not exist
1371+
if (!info ||
1372+
this._configHelper.config.environmentChangesIndicator === 'off' ||
1373+
this._configHelper.config.environmentChangesIndicator === 'warnonly' && !info.requiresAction) {
1374+
return;
1375+
}
1376+
1377+
// (Re-)create the widget
1378+
const widget = this._instantiationService.createInstance(EnvironmentVariableInfoWidget, info);
1379+
this._environmentVariableWidgetDisposable = this._widgetManager.attachWidget(widget);
13661380
}
13671381

13681382
private _getXtermTheme(theme?: IColorTheme): any {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
6363
private _latencyLastMeasured: number = 0;
6464
private _initialCwd: string | undefined;
6565
private _extEnvironmentVariableCollection: IMergedEnvironmentVariableCollection | undefined;
66+
private _environmentVariableInfo: IEnvironmentVariableInfo | undefined;
6667

6768
private readonly _onProcessReady = this._register(new Emitter<void>());
6869
public get onProcessReady(): Event<void> { return this._onProcessReady.event; }
@@ -81,6 +82,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
8182
private readonly _onEnvironmentVariableInfoChange = this._register(new Emitter<IEnvironmentVariableInfo>());
8283
public get onEnvironmentVariableInfoChanged(): Event<IEnvironmentVariableInfo> { return this._onEnvironmentVariableInfoChange.event; }
8384

85+
public get environmentVariableInfo(): IEnvironmentVariableInfo | undefined { return this._environmentVariableInfo; }
86+
8487
constructor(
8588
private readonly _terminalId: number,
8689
private readonly _configHelper: ITerminalConfigHelper,
@@ -246,7 +249,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
246249
this._register(this._environmentVariableService.onDidChangeCollections(newCollection => this._onEnvironmentVariableCollectionChange(newCollection)));
247250
this._extEnvironmentVariableCollection.applyToProcessEnvironment(env);
248251
if (this._extEnvironmentVariableCollection.map.size > 0) {
249-
this._onEnvironmentVariableInfoChange.fire(new EnvironmentVariableInfoChangesActive(this._extEnvironmentVariableCollection));
252+
this._environmentVariableInfo = new EnvironmentVariableInfoChangesActive(this._extEnvironmentVariableCollection);
253+
this._onEnvironmentVariableInfoChange.fire(this._environmentVariableInfo);
250254
}
251255

252256
const useConpty = this._configHelper.config.windowsEnableConpty && !isScreenReaderModeEnabled;
@@ -329,7 +333,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
329333
if (diff === undefined) {
330334
return;
331335
}
332-
const info = this._instantiationService.createInstance(EnvironmentVariableInfoStale, diff, this._terminalId);
333-
this._onEnvironmentVariableInfoChange.fire(info);
336+
this._environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoStale, diff, this._terminalId);
337+
this._onEnvironmentVariableInfoChange.fire(this._environmentVariableInfo);
334338
}
335339
}

src/vs/workbench/contrib/terminal/browser/widgets/environmentVariableInfoWidget.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWi
1818
private _container: HTMLElement | undefined;
1919
private _hoverWidget: HoverWidget | undefined;
2020

21+
get requiresAction() { return this._info.requiresAction; }
22+
2123
constructor(
2224
private _info: IEnvironmentVariableInfo,
2325
@IInstantiationService private readonly _instantiationService: IInstantiationService

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export interface IEnvironmentVariableService {
100100
export type ISerializableEnvironmentVariableCollection = [string, IEnvironmentVariableMutator][];
101101

102102
export interface IEnvironmentVariableInfo {
103+
readonly requiresAction: boolean;
103104
getInfo(): string;
104105
getIcon(): string;
105106
getActions?(): { label: string, iconClass?: string, run: () => void, commandId: string }[];

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export interface ITerminalConfiguration {
125125
osx: { [key: string]: string };
126126
windows: { [key: string]: string };
127127
};
128+
environmentChangesIndicator: 'off' | 'on' | 'warnonly';
128129
showExitAlert: boolean;
129130
splitCwd: 'workspaceRoot' | 'initial' | 'inherited';
130131
windowsEnableConpty: boolean;
@@ -295,6 +296,7 @@ export interface ITerminalProcessManager extends IDisposable {
295296
readonly remoteAuthority: string | undefined;
296297
readonly os: OperatingSystem | undefined;
297298
readonly userHome: string | undefined;
299+
readonly environmentVariableInfo: IEnvironmentVariableInfo | undefined;
298300

299301
readonly onProcessReady: Event<void>;
300302
readonly onBeforeProcessData: Event<IBeforeProcessDataEvent>;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ export const terminalConfiguration: IConfigurationNode = {
255255
},
256256
default: {}
257257
},
258+
'terminal.integrated.environmentChangesIndicator': {
259+
markdownDescription: localize('terminal.integrated.environmentChangesIndicator', "Whether to display the environment changes indicator on each terminal which explains whether extensions have made, or want to make changes to the terminal's environment."),
260+
type: 'string',
261+
enum: ['off', 'on', 'warnonly'],
262+
enumDescriptions: [
263+
localize('terminal.integrated.environmentChangesIndicator.off', "Disable the indicator."),
264+
localize('terminal.integrated.environmentChangesIndicator.on', "Enable the indicator."),
265+
localize('terminal.integrated.environmentChangesIndicator.warnonly', "Only show the warning indicator when a terminal's environment is 'stale', not the information indicator that shows a terminal has had its environment modified by an extension."),
266+
],
267+
default: 'on'
268+
},
258269
'terminal.integrated.showExitAlert': {
259270
description: localize('terminal.integrated.showExitAlert', "Controls whether to show the alert \"The terminal process terminated with exit code\" when exit code is non-zero."),
260271
type: 'boolean',

0 commit comments

Comments
 (0)