Skip to content

Commit fae8d1f

Browse files
authored
enable opt-out of contributed profiles (microsoft#135791)
1 parent e3fbb0a commit fae8d1f

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
88
import { URI } from 'vs/base/common/uri';
99
import { FindReplaceState } from 'vs/editor/contrib/find/findState';
1010
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
11-
import { IShellLaunchConfig, ITerminalChildProcess, ITerminalDimensions, ITerminalLaunchError, ITerminalProfile, ITerminalTabLayoutInfoById, TerminalIcon, TitleEventSource, TerminalShellType, IExtensionTerminalProfile, ITerminalProfileType, TerminalLocation, ICreateContributedTerminalProfileOptions, ProcessPropertyType, ProcessCapability } from 'vs/platform/terminal/common/terminal';
11+
import { IShellLaunchConfig, ITerminalChildProcess, ITerminalDimensions, ITerminalLaunchError, ITerminalProfile, ITerminalTabLayoutInfoById, TerminalIcon, TitleEventSource, TerminalShellType, IExtensionTerminalProfile, TerminalLocation, ICreateContributedTerminalProfileOptions, ProcessPropertyType, ProcessCapability } from 'vs/platform/terminal/common/terminal';
1212
import { ICommandTracker, INavigationMode, IOffProcessTerminalService, IRemoteTerminalAttachTarget, IStartExtensionTerminalRequest, ITerminalConfigHelper, ITerminalProcessExtHostProxy } from 'vs/workbench/contrib/terminal/common/terminal';
1313
import type { Terminal as XTermTerminal } from 'xterm';
1414
import type { SearchAddon as XTermSearchAddon } from 'xterm-addon-search';
@@ -109,7 +109,7 @@ export interface ITerminalService extends ITerminalInstanceHost {
109109
isProcessSupportRegistered: boolean;
110110
readonly connectionState: TerminalConnectionState;
111111
readonly availableProfiles: ITerminalProfile[];
112-
readonly allProfiles: ITerminalProfileType[] | undefined;
112+
readonly contributedProfiles: IExtensionTerminalProfile[];
113113
readonly profilesReady: Promise<void>;
114114
readonly defaultLocation: TerminalLocation;
115115

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/termi
2424
import { TerminalFindWidget } from 'vs/workbench/contrib/terminal/browser/terminalFindWidget';
2525
import { getTerminalActionBarArgs } from 'vs/workbench/contrib/terminal/browser/terminalMenus';
2626
import { ITerminalProfileResolverService, TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
27-
import { ITerminalContributionService } from 'vs/workbench/contrib/terminal/common/terminalExtensionPoints';
2827
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
2928
import { isLinux, isMacintosh } from 'vs/base/common/platform';
3029
import { BrowserFeatures } from 'vs/base/browser/canIUse';
@@ -63,7 +62,6 @@ export class TerminalEditor extends EditorPane {
6362
@IStorageService storageService: IStorageService,
6463
@ITerminalEditorService private readonly _terminalEditorService: ITerminalEditorService,
6564
@ITerminalProfileResolverService private readonly _terminalProfileResolverService: ITerminalProfileResolverService,
66-
@ITerminalContributionService private readonly _terminalContributionService: ITerminalContributionService,
6765
@ITerminalService private readonly _terminalService: ITerminalService,
6866
@IInstantiationService instantiationService: IInstantiationService,
6967
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
@@ -203,7 +201,7 @@ export class TerminalEditor extends EditorPane {
203201
switch (action.id) {
204202
case TerminalCommandId.CreateWithProfileButton: {
205203
const location = { viewColumn: ACTIVE_GROUP };
206-
const actions = getTerminalActionBarArgs(location, this._terminalService.availableProfiles, this._getDefaultProfileName(), this._terminalContributionService.terminalProfiles, this._instantiationService, this._terminalService, this._contextKeyService, this._commandService, this._dropdownMenu);
204+
const actions = getTerminalActionBarArgs(location, this._terminalService.availableProfiles, this._getDefaultProfileName(), this._terminalService.contributedProfiles, this._instantiationService, this._terminalService, this._contextKeyService, this._commandService, this._dropdownMenu);
207205
const button = this._instantiationService.createInstance(DropdownWithPrimaryActionViewItem, actions.primaryAction, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, {});
208206
return button;
209207
}

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { ILabelService } from 'vs/platform/label/common/label';
2323
import { INotificationService } from 'vs/platform/notification/common/notification';
2424
import { IKeyMods, IPickOptions, IQuickInputButton, IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
2525
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
26-
import { ICreateContributedTerminalProfileOptions, IExtensionTerminalProfile, IShellLaunchConfig, ITerminalLaunchError, ITerminalProfile, ITerminalProfileObject, ITerminalProfileType, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, TerminalLocation, TerminalLocationString, TerminalSettingId, TerminalSettingPrefix } from 'vs/platform/terminal/common/terminal';
26+
import { ICreateContributedTerminalProfileOptions, IExtensionTerminalProfile, IShellLaunchConfig, ITerminalLaunchError, ITerminalProfile, ITerminalProfileObject, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, TerminalLocation, TerminalLocationString, TerminalSettingId, TerminalSettingPrefix } from 'vs/platform/terminal/common/terminal';
2727
import { registerTerminalDefaultProfileConfiguration } from 'vs/platform/terminal/common/terminalPlatformConfiguration';
2828
import { iconForeground } from 'vs/platform/theme/common/colorRegistry';
2929
import { IconDefinition } from 'vs/platform/theme/common/iconRegistry';
@@ -72,7 +72,7 @@ export class TerminalService implements ITerminalService {
7272
private _defaultProfileName?: string;
7373
private _profilesReadyBarrier: AutoOpenBarrier;
7474
private _availableProfiles: ITerminalProfile[] | undefined;
75-
private _contributedProfiles: IExtensionTerminalProfile[] | undefined;
75+
private _contributedProfiles: IExtensionTerminalProfile[] = [];
7676
private _configHelper: TerminalConfigHelper;
7777
private _remoteTerminalsInitPromise: Promise<void> | undefined;
7878
private _localTerminalsInitPromise: Promise<void> | undefined;
@@ -89,14 +89,8 @@ export class TerminalService implements ITerminalService {
8989
this._refreshAvailableProfiles();
9090
return this._availableProfiles || [];
9191
}
92-
get allProfiles(): ITerminalProfileType[] | undefined {
93-
if (this._availableProfiles) {
94-
const profiles: ITerminalProfileType[] = [];
95-
profiles.concat(this._availableProfiles);
96-
profiles.concat(this._terminalContributionService.terminalProfiles);
97-
return profiles;
98-
}
99-
return undefined;
92+
get contributedProfiles(): IExtensionTerminalProfile[] {
93+
return this._contributedProfiles || [];
10094
}
10195
get configHelper(): ITerminalConfigHelper { return this._configHelper; }
10296
get instances(): ITerminalInstance[] {
@@ -511,9 +505,19 @@ export class TerminalService implements ITerminalService {
511505
}
512506

513507
private async _refreshAvailableProfilesNow(): Promise<void> {
508+
const platformKey = await this._getPlatformKey();
514509
const profiles = await this._detectProfiles();
515510
const profilesChanged = !equals(profiles, this._availableProfiles);
516-
const contributedProfilesChanged = !equals(this._terminalContributionService.terminalProfiles, this._contributedProfiles);
511+
const excludedContributedProfiles: string[] = [];
512+
const configProfiles: { [key: string]: any } = this._configurationService.getValue(TerminalSettingPrefix.Profiles + platformKey);
513+
for (const [profileName, value] of Object.entries(configProfiles)) {
514+
if (value === null) {
515+
excludedContributedProfiles.push(profileName);
516+
}
517+
}
518+
const filteredContributedProfiles = Array.from(this._terminalContributionService.terminalProfiles.filter(p => !excludedContributedProfiles.includes(p.title)));
519+
const contributedProfilesChanged = !equals(filteredContributedProfiles, this._contributedProfiles);
520+
517521
if (profiles.length === 0 && this._ifNoProfilesTryAgain) {
518522
// available profiles get updated when a terminal is created
519523
// or relevant config changes.
@@ -525,7 +529,7 @@ export class TerminalService implements ITerminalService {
525529
}
526530
if (profilesChanged || contributedProfilesChanged) {
527531
this._availableProfiles = profiles;
528-
this._contributedProfiles = Array.from(this._terminalContributionService.terminalProfiles);
532+
this._contributedProfiles = filteredContributedProfiles;
529533
this._onDidChangeAvailableProfiles.fire(this._availableProfiles);
530534
this._profilesReadyBarrier.open();
531535
this._updateWebContextKey();
@@ -534,12 +538,12 @@ export class TerminalService implements ITerminalService {
534538
}
535539

536540
private _updateWebContextKey(): void {
537-
this._webExtensionContributedProfileContextKey.set(isWeb && this._terminalContributionService.terminalProfiles.length > 0);
541+
this._webExtensionContributedProfileContextKey.set(isWeb && this._contributedProfiles.length > 0);
538542
}
539543

540544
private async _refreshPlatformConfig(profiles: ITerminalProfile[]) {
541545
const env = await this._remoteAgentService.getEnvironment();
542-
registerTerminalDefaultProfileConfiguration({ os: env?.os || OS, profiles }, this._terminalContributionService.terminalProfiles);
546+
registerTerminalDefaultProfileConfiguration({ os: env?.os || OS, profiles }, this._contributedProfiles);
543547
refreshTerminalActions(profiles);
544548
}
545549

@@ -987,7 +991,7 @@ export class TerminalService implements ITerminalService {
987991

988992
quickPickItems.push({ type: 'separator', label: nls.localize('ICreateContributedTerminalProfileOptions', "contributed") });
989993
const contributedProfiles: IProfileQuickPickItem[] = [];
990-
for (const contributed of this._terminalContributionService.terminalProfiles) {
994+
for (const contributed of this.contributedProfiles) {
991995
if (typeof contributed.icon === 'string' && contributed.icon.startsWith('$(')) {
992996
contributed.icon = contributed.icon.substring(2, contributed.icon.length - 1);
993997
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { IMenu, IMenuService, MenuId, MenuItemAction } from 'vs/platform/actions
2525
import { ITerminalProfileResolverService, TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
2626
import { TerminalSettingId, ITerminalProfile, TerminalLocation } from 'vs/platform/terminal/common/terminal';
2727
import { ActionViewItem, SelectActionViewItem } from 'vs/base/browser/ui/actionbar/actionViewItems';
28-
import { ITerminalContributionService } from 'vs/workbench/contrib/terminal/common/terminalExtensionPoints';
2928
import { attachSelectBoxStyler, attachStylerCallback } from 'vs/platform/theme/common/styler';
3029
import { selectBorder } from 'vs/platform/theme/common/colorRegistry';
3130
import { ISelectOptionItem } from 'vs/base/browser/ui/selectBox/selectBox';
@@ -75,8 +74,7 @@ export class TerminalViewPane extends ViewPane {
7574
@IOpenerService openerService: IOpenerService,
7675
@IMenuService private readonly _menuService: IMenuService,
7776
@ICommandService private readonly _commandService: ICommandService,
78-
@ITerminalContributionService private readonly _terminalContributionService: ITerminalContributionService,
79-
@ITerminalProfileResolverService private readonly _terminalProfileResolverService: ITerminalProfileResolverService,
77+
@ITerminalProfileResolverService private readonly _terminalProfileResolverService: ITerminalProfileResolverService
8078
) {
8179
super(options, keybindingService, _contextMenuService, configurationService, _contextKeyService, viewDescriptorService, _instantiationService, openerService, themeService, telemetryService);
8280
this._terminalService.onDidRegisterProcessSupport(() => {
@@ -204,7 +202,7 @@ export class TerminalViewPane extends ViewPane {
204202
this._tabButtons.dispose();
205203
}
206204

207-
const actions = getTerminalActionBarArgs(TerminalLocation.Panel, this._terminalService.availableProfiles, this._getDefaultProfileName(), this._terminalContributionService.terminalProfiles, this._instantiationService, this._terminalService, this._contextKeyService, this._commandService, this._dropdownMenu);
205+
const actions = getTerminalActionBarArgs(TerminalLocation.Panel, this._terminalService.availableProfiles, this._getDefaultProfileName(), this._terminalService.contributedProfiles, this._instantiationService, this._terminalService, this._contextKeyService, this._commandService, this._dropdownMenu);
208206
this._tabButtons = new DropdownWithPrimaryActionViewItem(actions.primaryAction, actions.dropdownAction, actions.dropdownMenuActions, actions.className, this._contextMenuService, {}, this._keybindingService, this._notificationService, this._contextKeyService);
209207
this._updateTabActionBar(this._terminalService.availableProfiles);
210208
return this._tabButtons;
@@ -228,7 +226,7 @@ export class TerminalViewPane extends ViewPane {
228226
}
229227

230228
private _updateTabActionBar(profiles: ITerminalProfile[]): void {
231-
const actions = getTerminalActionBarArgs(TerminalLocation.Panel, profiles, this._getDefaultProfileName(), this._terminalContributionService.terminalProfiles, this._instantiationService, this._terminalService, this._contextKeyService, this._commandService, this._dropdownMenu);
229+
const actions = getTerminalActionBarArgs(TerminalLocation.Panel, profiles, this._getDefaultProfileName(), this._terminalService.contributedProfiles, this._instantiationService, this._terminalService, this._contextKeyService, this._commandService, this._dropdownMenu);
232230
this._tabButtons?.update(actions.dropdownAction, actions.dropdownMenuActions);
233231
}
234232

0 commit comments

Comments
 (0)