Path: blob/main/src/vs/workbench/browser/parts/editor/breadcrumbs.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { BreadcrumbsWidget } from '../../../../base/browser/ui/breadcrumbs/breadcrumbsWidget.js';6import { Emitter, Event } from '../../../../base/common/event.js';7import * as glob from '../../../../base/common/glob.js';8import { IDisposable } from '../../../../base/common/lifecycle.js';9import { localize } from '../../../../nls.js';10import { IConfigurationOverrides, IConfigurationService } from '../../../../platform/configuration/common/configuration.js';11import { Extensions, IConfigurationRegistry, ConfigurationScope } from '../../../../platform/configuration/common/configurationRegistry.js';12import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';13import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';14import { Registry } from '../../../../platform/registry/common/platform.js';15import { GroupIdentifier, IEditorPartOptions } from '../../../common/editor.js';1617export const IBreadcrumbsService = createDecorator<IBreadcrumbsService>('IEditorBreadcrumbsService');1819export interface IBreadcrumbsService {2021readonly _serviceBrand: undefined;2223register(group: GroupIdentifier, widget: BreadcrumbsWidget): IDisposable;2425getWidget(group: GroupIdentifier): BreadcrumbsWidget | undefined;26}272829export class BreadcrumbsService implements IBreadcrumbsService {3031declare readonly _serviceBrand: undefined;3233private readonly _map = new Map<number, BreadcrumbsWidget>();3435register(group: number, widget: BreadcrumbsWidget): IDisposable {36if (this._map.has(group)) {37throw new Error(`group (${group}) has already a widget`);38}39this._map.set(group, widget);40return {41dispose: () => this._map.delete(group)42};43}4445getWidget(group: number): BreadcrumbsWidget | undefined {46return this._map.get(group);47}48}4950registerSingleton(IBreadcrumbsService, BreadcrumbsService, InstantiationType.Delayed);515253//#region config5455export abstract class BreadcrumbsConfig<T> {5657abstract get name(): string;58abstract get onDidChange(): Event<void>;5960abstract getValue(overrides?: IConfigurationOverrides): T;61abstract updateValue(value: T, overrides?: IConfigurationOverrides): Promise<void>;62abstract dispose(): void;6364private constructor() {65// internal66}6768static readonly IsEnabled = BreadcrumbsConfig._stub<boolean>('breadcrumbs.enabled');69static readonly UseQuickPick = BreadcrumbsConfig._stub<boolean>('breadcrumbs.useQuickPick');70static readonly FilePath = BreadcrumbsConfig._stub<'on' | 'off' | 'last'>('breadcrumbs.filePath');71static readonly SymbolPath = BreadcrumbsConfig._stub<'on' | 'off' | 'last'>('breadcrumbs.symbolPath');72static readonly SymbolSortOrder = BreadcrumbsConfig._stub<'position' | 'name' | 'type'>('breadcrumbs.symbolSortOrder');73static readonly Icons = BreadcrumbsConfig._stub<boolean>('breadcrumbs.icons');74static readonly TitleScrollbarSizing = BreadcrumbsConfig._stub<IEditorPartOptions['titleScrollbarSizing']>('workbench.editor.titleScrollbarSizing');75static readonly TitleScrollbarVisibility = BreadcrumbsConfig._stub<IEditorPartOptions['titleScrollbarVisibility']>('workbench.editor.titleScrollbarVisibility');7677static readonly FileExcludes = BreadcrumbsConfig._stub<glob.IExpression>('files.exclude');7879private static _stub<T>(name: string): { bindTo(service: IConfigurationService): BreadcrumbsConfig<T> } {80return {81bindTo(service) {82const onDidChange = new Emitter<void>();8384const listener = service.onDidChangeConfiguration(e => {85if (e.affectsConfiguration(name)) {86onDidChange.fire(undefined);87}88});8990return new class implements BreadcrumbsConfig<T> {91readonly name = name;92readonly onDidChange = onDidChange.event;93getValue(overrides?: IConfigurationOverrides): T {94if (overrides) {95return service.getValue(name, overrides);96} else {97return service.getValue(name);98}99}100updateValue(newValue: T, overrides?: IConfigurationOverrides): Promise<void> {101if (overrides) {102return service.updateValue(name, newValue, overrides);103} else {104return service.updateValue(name, newValue);105}106}107dispose(): void {108listener.dispose();109onDidChange.dispose();110}111};112}113};114}115}116117Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({118id: 'breadcrumbs',119title: localize('title', "Breadcrumb Navigation"),120order: 101,121type: 'object',122properties: {123'breadcrumbs.enabled': {124description: localize('enabled', "Enable/disable navigation breadcrumbs."),125type: 'boolean',126default: true127},128'breadcrumbs.filePath': {129description: localize('filepath', "Controls whether and how file paths are shown in the breadcrumbs view."),130type: 'string',131default: 'on',132enum: ['on', 'off', 'last'],133enumDescriptions: [134localize('filepath.on', "Show the file path in the breadcrumbs view."),135localize('filepath.off', "Do not show the file path in the breadcrumbs view."),136localize('filepath.last', "Only show the last element of the file path in the breadcrumbs view."),137]138},139'breadcrumbs.symbolPath': {140description: localize('symbolpath', "Controls whether and how symbols are shown in the breadcrumbs view."),141type: 'string',142default: 'on',143enum: ['on', 'off', 'last'],144enumDescriptions: [145localize('symbolpath.on', "Show all symbols in the breadcrumbs view."),146localize('symbolpath.off', "Do not show symbols in the breadcrumbs view."),147localize('symbolpath.last', "Only show the current symbol in the breadcrumbs view."),148]149},150'breadcrumbs.symbolSortOrder': {151description: localize('symbolSortOrder', "Controls how symbols are sorted in the breadcrumbs outline view."),152type: 'string',153default: 'position',154scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,155enum: ['position', 'name', 'type'],156enumDescriptions: [157localize('symbolSortOrder.position', "Show symbol outline in file position order."),158localize('symbolSortOrder.name', "Show symbol outline in alphabetical order."),159localize('symbolSortOrder.type', "Show symbol outline in symbol type order."),160]161},162'breadcrumbs.icons': {163description: localize('icons', "Render breadcrumb items with icons."),164type: 'boolean',165default: true166},167'breadcrumbs.showFiles': {168type: 'boolean',169default: true,170scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,171markdownDescription: localize('filteredTypes.file', "When enabled breadcrumbs show `file`-symbols.")172},173'breadcrumbs.showModules': {174type: 'boolean',175default: true,176scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,177markdownDescription: localize('filteredTypes.module', "When enabled breadcrumbs show `module`-symbols.")178},179'breadcrumbs.showNamespaces': {180type: 'boolean',181default: true,182scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,183markdownDescription: localize('filteredTypes.namespace', "When enabled breadcrumbs show `namespace`-symbols.")184},185'breadcrumbs.showPackages': {186type: 'boolean',187default: true,188scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,189markdownDescription: localize('filteredTypes.package', "When enabled breadcrumbs show `package`-symbols.")190},191'breadcrumbs.showClasses': {192type: 'boolean',193default: true,194scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,195markdownDescription: localize('filteredTypes.class', "When enabled breadcrumbs show `class`-symbols.")196},197'breadcrumbs.showMethods': {198type: 'boolean',199default: true,200scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,201markdownDescription: localize('filteredTypes.method', "When enabled breadcrumbs show `method`-symbols.")202},203'breadcrumbs.showProperties': {204type: 'boolean',205default: true,206scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,207markdownDescription: localize('filteredTypes.property', "When enabled breadcrumbs show `property`-symbols.")208},209'breadcrumbs.showFields': {210type: 'boolean',211default: true,212scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,213markdownDescription: localize('filteredTypes.field', "When enabled breadcrumbs show `field`-symbols.")214},215'breadcrumbs.showConstructors': {216type: 'boolean',217default: true,218scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,219markdownDescription: localize('filteredTypes.constructor', "When enabled breadcrumbs show `constructor`-symbols.")220},221'breadcrumbs.showEnums': {222type: 'boolean',223default: true,224scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,225markdownDescription: localize('filteredTypes.enum', "When enabled breadcrumbs show `enum`-symbols.")226},227'breadcrumbs.showInterfaces': {228type: 'boolean',229default: true,230scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,231markdownDescription: localize('filteredTypes.interface', "When enabled breadcrumbs show `interface`-symbols.")232},233'breadcrumbs.showFunctions': {234type: 'boolean',235default: true,236scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,237markdownDescription: localize('filteredTypes.function', "When enabled breadcrumbs show `function`-symbols.")238},239'breadcrumbs.showVariables': {240type: 'boolean',241default: true,242scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,243markdownDescription: localize('filteredTypes.variable', "When enabled breadcrumbs show `variable`-symbols.")244},245'breadcrumbs.showConstants': {246type: 'boolean',247default: true,248scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,249markdownDescription: localize('filteredTypes.constant', "When enabled breadcrumbs show `constant`-symbols.")250},251'breadcrumbs.showStrings': {252type: 'boolean',253default: true,254scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,255markdownDescription: localize('filteredTypes.string', "When enabled breadcrumbs show `string`-symbols.")256},257'breadcrumbs.showNumbers': {258type: 'boolean',259default: true,260scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,261markdownDescription: localize('filteredTypes.number', "When enabled breadcrumbs show `number`-symbols.")262},263'breadcrumbs.showBooleans': {264type: 'boolean',265default: true,266scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,267markdownDescription: localize('filteredTypes.boolean', "When enabled breadcrumbs show `boolean`-symbols.")268},269'breadcrumbs.showArrays': {270type: 'boolean',271default: true,272scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,273markdownDescription: localize('filteredTypes.array', "When enabled breadcrumbs show `array`-symbols.")274},275'breadcrumbs.showObjects': {276type: 'boolean',277default: true,278scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,279markdownDescription: localize('filteredTypes.object', "When enabled breadcrumbs show `object`-symbols.")280},281'breadcrumbs.showKeys': {282type: 'boolean',283default: true,284scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,285markdownDescription: localize('filteredTypes.key', "When enabled breadcrumbs show `key`-symbols.")286},287'breadcrumbs.showNull': {288type: 'boolean',289default: true,290scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,291markdownDescription: localize('filteredTypes.null', "When enabled breadcrumbs show `null`-symbols.")292},293'breadcrumbs.showEnumMembers': {294type: 'boolean',295default: true,296scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,297markdownDescription: localize('filteredTypes.enumMember', "When enabled breadcrumbs show `enumMember`-symbols.")298},299'breadcrumbs.showStructs': {300type: 'boolean',301default: true,302scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,303markdownDescription: localize('filteredTypes.struct', "When enabled breadcrumbs show `struct`-symbols.")304},305'breadcrumbs.showEvents': {306type: 'boolean',307default: true,308scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,309markdownDescription: localize('filteredTypes.event', "When enabled breadcrumbs show `event`-symbols.")310},311'breadcrumbs.showOperators': {312type: 'boolean',313default: true,314scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,315markdownDescription: localize('filteredTypes.operator', "When enabled breadcrumbs show `operator`-symbols.")316},317'breadcrumbs.showTypeParameters': {318type: 'boolean',319default: true,320scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,321markdownDescription: localize('filteredTypes.typeParameter', "When enabled breadcrumbs show `typeParameter`-symbols.")322}323}324});325326//#endregion327328329