Skip to content

Commit

Permalink
Add environmentChangesIndicator setting
Browse files Browse the repository at this point in the history
Part of #46696
  • Loading branch information
Tyriar committed Apr 17, 2020
1 parent 9cdf250 commit 23215fd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal
import { localize } from 'vs/nls';

export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo {
readonly requiresAction = true;

constructor(
private readonly _diff: IMergedEnvironmentVariableCollectionDiff,
private readonly _terminalId: number,
Expand Down Expand Up @@ -57,6 +59,8 @@ export class EnvironmentVariableInfoStale implements IEnvironmentVariableInfo {
}

export class EnvironmentVariableInfoChangesActive implements IEnvironmentVariableInfo {
readonly requiresAction = false;

constructor(
private _collection: IMergedEnvironmentVariableCollection
) {
Expand Down
22 changes: 18 additions & 4 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {

private _widgetManager: TerminalWidgetManager = this._instantiationService.createInstance(TerminalWidgetManager);
private _linkManager: TerminalLinkManager | undefined;
private _environmentVariableWidget: EnvironmentVariableInfoWidget | undefined;
private _environmentVariableWidgetDisposable: IDisposable | undefined;
private _commandTrackerAddon: CommandTrackerAddon | undefined;
private _navigationModeAddon: INavigationMode & ITerminalAddon | undefined;

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

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

private _onEnvironmentVariableInfoChanged(info: IEnvironmentVariableInfo): void {
this._environmentVariableWidget?.dispose();
this._environmentVariableWidget = this._instantiationService.createInstance(EnvironmentVariableInfoWidget, info);
this._widgetManager.attachWidget(this._environmentVariableWidget);
this._refreshEnvironmentVariableInfoWidgetState(info);
}

private _refreshEnvironmentVariableInfoWidgetState(info?: IEnvironmentVariableInfo): void {
this._environmentVariableWidgetDisposable?.dispose();

// Check if the widget should not exist
if (!info ||
this._configHelper.config.environmentChangesIndicator === 'off' ||
this._configHelper.config.environmentChangesIndicator === 'warnonly' && !info.requiresAction) {
return;
}

// (Re-)create the widget
const widget = this._instantiationService.createInstance(EnvironmentVariableInfoWidget, info);
this._environmentVariableWidgetDisposable = this._widgetManager.attachWidget(widget);
}

private _getXtermTheme(theme?: IColorTheme): any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
private _latencyLastMeasured: number = 0;
private _initialCwd: string | undefined;
private _extEnvironmentVariableCollection: IMergedEnvironmentVariableCollection | undefined;
private _environmentVariableInfo: IEnvironmentVariableInfo | undefined;

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

public get environmentVariableInfo(): IEnvironmentVariableInfo | undefined { return this._environmentVariableInfo; }

constructor(
private readonly _terminalId: number,
private readonly _configHelper: ITerminalConfigHelper,
Expand Down Expand Up @@ -246,7 +249,8 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
this._register(this._environmentVariableService.onDidChangeCollections(newCollection => this._onEnvironmentVariableCollectionChange(newCollection)));
this._extEnvironmentVariableCollection.applyToProcessEnvironment(env);
if (this._extEnvironmentVariableCollection.map.size > 0) {
this._onEnvironmentVariableInfoChange.fire(new EnvironmentVariableInfoChangesActive(this._extEnvironmentVariableCollection));
this._environmentVariableInfo = new EnvironmentVariableInfoChangesActive(this._extEnvironmentVariableCollection);
this._onEnvironmentVariableInfoChange.fire(this._environmentVariableInfo);
}

const useConpty = this._configHelper.config.windowsEnableConpty && !isScreenReaderModeEnabled;
Expand Down Expand Up @@ -329,7 +333,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
if (diff === undefined) {
return;
}
const info = this._instantiationService.createInstance(EnvironmentVariableInfoStale, diff, this._terminalId);
this._onEnvironmentVariableInfoChange.fire(info);
this._environmentVariableInfo = this._instantiationService.createInstance(EnvironmentVariableInfoStale, diff, this._terminalId);
this._onEnvironmentVariableInfoChange.fire(this._environmentVariableInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export class EnvironmentVariableInfoWidget extends Widget implements ITerminalWi
private _container: HTMLElement | undefined;
private _hoverWidget: HoverWidget | undefined;

get requiresAction() { return this._info.requiresAction; }

constructor(
private _info: IEnvironmentVariableInfo,
@IInstantiationService private readonly _instantiationService: IInstantiationService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export interface IEnvironmentVariableService {
export type ISerializableEnvironmentVariableCollection = [string, IEnvironmentVariableMutator][];

export interface IEnvironmentVariableInfo {
readonly requiresAction: boolean;
getInfo(): string;
getIcon(): string;
getActions?(): { label: string, iconClass?: string, run: () => void, commandId: string }[];
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export interface ITerminalConfiguration {
osx: { [key: string]: string };
windows: { [key: string]: string };
};
environmentChangesIndicator: 'off' | 'on' | 'warnonly';
showExitAlert: boolean;
splitCwd: 'workspaceRoot' | 'initial' | 'inherited';
windowsEnableConpty: boolean;
Expand Down Expand Up @@ -295,6 +296,7 @@ export interface ITerminalProcessManager extends IDisposable {
readonly remoteAuthority: string | undefined;
readonly os: OperatingSystem | undefined;
readonly userHome: string | undefined;
readonly environmentVariableInfo: IEnvironmentVariableInfo | undefined;

readonly onProcessReady: Event<void>;
readonly onBeforeProcessData: Event<IBeforeProcessDataEvent>;
Expand Down
11 changes: 11 additions & 0 deletions src/vs/workbench/contrib/terminal/common/terminalConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,17 @@ export const terminalConfiguration: IConfigurationNode = {
},
default: {}
},
'terminal.integrated.environmentChangesIndicator': {
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."),
type: 'string',
enum: ['off', 'on', 'warnonly'],
enumDescriptions: [
localize('terminal.integrated.environmentChangesIndicator.off', "Disable the indicator."),
localize('terminal.integrated.environmentChangesIndicator.on', "Enable the indicator."),
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."),
],
default: 'on'
},
'terminal.integrated.showExitAlert': {
description: localize('terminal.integrated.showExitAlert', "Controls whether to show the alert \"The terminal process terminated with exit code\" when exit code is non-zero."),
type: 'boolean',
Expand Down

0 comments on commit 23215fd

Please sign in to comment.