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