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