Path: blob/main/src/vs/workbench/browser/parts/editor/breadcrumbs.ts
5283 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 SymbolPathSeparator = BreadcrumbsConfig._stub<string>('breadcrumbs.symbolPathSeparator');74static readonly Icons = BreadcrumbsConfig._stub<boolean>('breadcrumbs.icons');75static readonly TitleScrollbarSizing = BreadcrumbsConfig._stub<IEditorPartOptions['titleScrollbarSizing']>('workbench.editor.titleScrollbarSizing');76static readonly TitleScrollbarVisibility = BreadcrumbsConfig._stub<IEditorPartOptions['titleScrollbarVisibility']>('workbench.editor.titleScrollbarVisibility');7778static readonly FileExcludes = BreadcrumbsConfig._stub<glob.IExpression>('files.exclude');7980private static _stub<T>(name: string): { bindTo(service: IConfigurationService): BreadcrumbsConfig<T> } {81return {82bindTo(service) {83const onDidChange = new Emitter<void>();8485const listener = service.onDidChangeConfiguration(e => {86if (e.affectsConfiguration(name)) {87onDidChange.fire(undefined);88}89});9091return new class implements BreadcrumbsConfig<T> {92readonly name = name;93readonly onDidChange = onDidChange.event;94getValue(overrides?: IConfigurationOverrides): T {95if (overrides) {96return service.getValue(name, overrides);97} else {98return service.getValue(name);99}100}101updateValue(newValue: T, overrides?: IConfigurationOverrides): Promise<void> {102if (overrides) {103return service.updateValue(name, newValue, overrides);104} else {105return service.updateValue(name, newValue);106}107}108dispose(): void {109listener.dispose();110onDidChange.dispose();111}112};113}114};115}116}117118Registry.as<IConfigurationRegistry>(Extensions.Configuration).registerConfiguration({119id: 'breadcrumbs',120title: localize('title', "Breadcrumb Navigation"),121order: 101,122type: 'object',123properties: {124'breadcrumbs.enabled': {125description: localize('enabled', "Enable/disable navigation breadcrumbs."),126type: 'boolean',127default: true128},129'breadcrumbs.filePath': {130description: localize('filepath', "Controls whether and how file paths are shown in the breadcrumbs view."),131type: 'string',132default: 'on',133enum: ['on', 'off', 'last'],134enumDescriptions: [135localize('filepath.on', "Show the file path in the breadcrumbs view."),136localize('filepath.off', "Do not show the file path in the breadcrumbs view."),137localize('filepath.last', "Only show the last element of the file path in the breadcrumbs view."),138]139},140'breadcrumbs.symbolPath': {141description: localize('symbolpath', "Controls whether and how symbols are shown in the breadcrumbs view."),142type: 'string',143default: 'on',144enum: ['on', 'off', 'last'],145enumDescriptions: [146localize('symbolpath.on', "Show all symbols in the breadcrumbs view."),147localize('symbolpath.off', "Do not show symbols in the breadcrumbs view."),148localize('symbolpath.last', "Only show the current symbol in the breadcrumbs view."),149]150},151'breadcrumbs.symbolSortOrder': {152description: localize('symbolSortOrder', "Controls how symbols are sorted in the breadcrumbs outline view."),153type: 'string',154default: 'position',155scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,156enum: ['position', 'name', 'type'],157enumDescriptions: [158localize('symbolSortOrder.position', "Show symbol outline in file position order."),159localize('symbolSortOrder.name', "Show symbol outline in alphabetical order."),160localize('symbolSortOrder.type', "Show symbol outline in symbol type order."),161]162},163'breadcrumbs.icons': {164description: localize('icons', "Render breadcrumb items with icons."),165type: 'boolean',166default: true167},168'breadcrumbs.symbolPathSeparator': {169description: localize('symbolPathSeparator', "The separator used when copying the breadcrumb symbol path."),170type: 'string',171default: '.',172scope: ConfigurationScope.LANGUAGE_OVERRIDABLE173},174'breadcrumbs.showFiles': {175type: 'boolean',176default: true,177scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,178markdownDescription: localize('filteredTypes.file', "When enabled breadcrumbs show `file`-symbols.")179},180'breadcrumbs.showModules': {181type: 'boolean',182default: true,183scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,184markdownDescription: localize('filteredTypes.module', "When enabled breadcrumbs show `module`-symbols.")185},186'breadcrumbs.showNamespaces': {187type: 'boolean',188default: true,189scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,190markdownDescription: localize('filteredTypes.namespace', "When enabled breadcrumbs show `namespace`-symbols.")191},192'breadcrumbs.showPackages': {193type: 'boolean',194default: true,195scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,196markdownDescription: localize('filteredTypes.package', "When enabled breadcrumbs show `package`-symbols.")197},198'breadcrumbs.showClasses': {199type: 'boolean',200default: true,201scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,202markdownDescription: localize('filteredTypes.class', "When enabled breadcrumbs show `class`-symbols.")203},204'breadcrumbs.showMethods': {205type: 'boolean',206default: true,207scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,208markdownDescription: localize('filteredTypes.method', "When enabled breadcrumbs show `method`-symbols.")209},210'breadcrumbs.showProperties': {211type: 'boolean',212default: true,213scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,214markdownDescription: localize('filteredTypes.property', "When enabled breadcrumbs show `property`-symbols.")215},216'breadcrumbs.showFields': {217type: 'boolean',218default: true,219scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,220markdownDescription: localize('filteredTypes.field', "When enabled breadcrumbs show `field`-symbols.")221},222'breadcrumbs.showConstructors': {223type: 'boolean',224default: true,225scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,226markdownDescription: localize('filteredTypes.constructor', "When enabled breadcrumbs show `constructor`-symbols.")227},228'breadcrumbs.showEnums': {229type: 'boolean',230default: true,231scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,232markdownDescription: localize('filteredTypes.enum', "When enabled breadcrumbs show `enum`-symbols.")233},234'breadcrumbs.showInterfaces': {235type: 'boolean',236default: true,237scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,238markdownDescription: localize('filteredTypes.interface', "When enabled breadcrumbs show `interface`-symbols.")239},240'breadcrumbs.showFunctions': {241type: 'boolean',242default: true,243scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,244markdownDescription: localize('filteredTypes.function', "When enabled breadcrumbs show `function`-symbols.")245},246'breadcrumbs.showVariables': {247type: 'boolean',248default: true,249scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,250markdownDescription: localize('filteredTypes.variable', "When enabled breadcrumbs show `variable`-symbols.")251},252'breadcrumbs.showConstants': {253type: 'boolean',254default: true,255scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,256markdownDescription: localize('filteredTypes.constant', "When enabled breadcrumbs show `constant`-symbols.")257},258'breadcrumbs.showStrings': {259type: 'boolean',260default: true,261scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,262markdownDescription: localize('filteredTypes.string', "When enabled breadcrumbs show `string`-symbols.")263},264'breadcrumbs.showNumbers': {265type: 'boolean',266default: true,267scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,268markdownDescription: localize('filteredTypes.number', "When enabled breadcrumbs show `number`-symbols.")269},270'breadcrumbs.showBooleans': {271type: 'boolean',272default: true,273scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,274markdownDescription: localize('filteredTypes.boolean', "When enabled breadcrumbs show `boolean`-symbols.")275},276'breadcrumbs.showArrays': {277type: 'boolean',278default: true,279scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,280markdownDescription: localize('filteredTypes.array', "When enabled breadcrumbs show `array`-symbols.")281},282'breadcrumbs.showObjects': {283type: 'boolean',284default: true,285scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,286markdownDescription: localize('filteredTypes.object', "When enabled breadcrumbs show `object`-symbols.")287},288'breadcrumbs.showKeys': {289type: 'boolean',290default: true,291scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,292markdownDescription: localize('filteredTypes.key', "When enabled breadcrumbs show `key`-symbols.")293},294'breadcrumbs.showNull': {295type: 'boolean',296default: true,297scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,298markdownDescription: localize('filteredTypes.null', "When enabled breadcrumbs show `null`-symbols.")299},300'breadcrumbs.showEnumMembers': {301type: 'boolean',302default: true,303scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,304markdownDescription: localize('filteredTypes.enumMember', "When enabled breadcrumbs show `enumMember`-symbols.")305},306'breadcrumbs.showStructs': {307type: 'boolean',308default: true,309scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,310markdownDescription: localize('filteredTypes.struct', "When enabled breadcrumbs show `struct`-symbols.")311},312'breadcrumbs.showEvents': {313type: 'boolean',314default: true,315scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,316markdownDescription: localize('filteredTypes.event', "When enabled breadcrumbs show `event`-symbols.")317},318'breadcrumbs.showOperators': {319type: 'boolean',320default: true,321scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,322markdownDescription: localize('filteredTypes.operator', "When enabled breadcrumbs show `operator`-symbols.")323},324'breadcrumbs.showTypeParameters': {325type: 'boolean',326default: true,327scope: ConfigurationScope.LANGUAGE_OVERRIDABLE,328markdownDescription: localize('filteredTypes.typeParameter', "When enabled breadcrumbs show `typeParameter`-symbols.")329}330}331});332333//#endregion334335336