Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/browser/labels.ts
5222 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 { localize } from '../../nls.js';
7
import { URI } from '../../base/common/uri.js';
8
import { dirname, isEqual, basenameOrAuthority } from '../../base/common/resources.js';
9
import { IconLabel, IIconLabelValueOptions, IIconLabelCreationOptions } from '../../base/browser/ui/iconLabel/iconLabel.js';
10
import { ILanguageService } from '../../editor/common/languages/language.js';
11
import { IWorkspaceContextService } from '../../platform/workspace/common/workspace.js';
12
import { IConfigurationService } from '../../platform/configuration/common/configuration.js';
13
import { IModelService } from '../../editor/common/services/model.js';
14
import { ITextFileService } from '../services/textfile/common/textfiles.js';
15
import { IDecoration, IDecorationsService, IResourceDecorationChangeEvent } from '../services/decorations/common/decorations.js';
16
import { Schemas } from '../../base/common/network.js';
17
import { FileKind, FILES_ASSOCIATIONS_CONFIG } from '../../platform/files/common/files.js';
18
import { ITextModel } from '../../editor/common/model.js';
19
import { IThemeService } from '../../platform/theme/common/themeService.js';
20
import { Event, Emitter } from '../../base/common/event.js';
21
import { ILabelService } from '../../platform/label/common/label.js';
22
import { getIconClasses } from '../../editor/common/services/getIconClasses.js';
23
import { Disposable, dispose, IDisposable, MutableDisposable } from '../../base/common/lifecycle.js';
24
import { IInstantiationService } from '../../platform/instantiation/common/instantiation.js';
25
import { normalizeDriveLetter } from '../../base/common/labels.js';
26
import { IRange } from '../../editor/common/core/range.js';
27
import { ThemeIcon } from '../../base/common/themables.js';
28
import { INotebookDocumentService, extractCellOutputDetails } from '../services/notebook/common/notebookDocumentService.js';
29
30
export interface IResourceLabelProps {
31
resource?: URI | { primary?: URI; secondary?: URI };
32
name?: string | string[];
33
range?: IRange;
34
description?: string;
35
}
36
37
function toResource(props: IResourceLabelProps | undefined): URI | undefined {
38
if (!props?.resource) {
39
return undefined;
40
}
41
42
if (URI.isUri(props.resource)) {
43
return props.resource;
44
}
45
46
return props.resource.primary;
47
}
48
49
export interface IResourceLabelOptions extends IIconLabelValueOptions {
50
51
/**
52
* A hint to the file kind of the resource.
53
*/
54
fileKind?: FileKind;
55
56
/**
57
* File decorations to use for the label.
58
*/
59
readonly fileDecorations?: { colors: boolean; badges: boolean };
60
61
/**
62
* Will take the provided label as is and e.g. not override it for untitled files.
63
*/
64
readonly forceLabel?: boolean;
65
66
/**
67
* A prefix to be added to the name of the label.
68
*/
69
readonly namePrefix?: string;
70
71
/**
72
* A suffix to be added to the name of the label.
73
*/
74
readonly nameSuffix?: string;
75
76
/**
77
* Uses the provided icon instead of deriving a resource icon.
78
*/
79
readonly icon?: ThemeIcon | URI;
80
}
81
82
export interface IFileLabelOptions extends IResourceLabelOptions {
83
hideLabel?: boolean;
84
hidePath?: boolean;
85
range?: IRange;
86
}
87
88
export interface IResourceLabel extends IDisposable {
89
90
readonly element: HTMLElement;
91
92
readonly onDidRender: Event<void>;
93
94
/**
95
* Most generic way to apply a label with raw information.
96
*/
97
setLabel(label?: string, description?: string, options?: IIconLabelValueOptions): void;
98
99
/**
100
* Convenient method to apply a label by passing a resource along.
101
*
102
* Note: for file resources consider to use the #setFile() method instead.
103
*/
104
setResource(label: IResourceLabelProps, options?: IResourceLabelOptions): void;
105
106
/**
107
* Convenient method to render a file label based on a resource.
108
*/
109
setFile(resource: URI, options?: IFileLabelOptions): void;
110
111
/**
112
* Resets the label to be empty.
113
*/
114
clear(): void;
115
}
116
117
export interface IResourceLabelsContainer {
118
readonly onDidChangeVisibility: Event<boolean>;
119
}
120
121
export const DEFAULT_LABELS_CONTAINER: IResourceLabelsContainer = {
122
onDidChangeVisibility: Event.None
123
};
124
125
export class ResourceLabels extends Disposable {
126
127
private readonly _onDidChangeDecorations = this._register(new Emitter<void>());
128
get onDidChangeDecorations() { return this._onDidChangeDecorations.event; }
129
130
private widgets: ResourceLabelWidget[] = [];
131
private labels: IResourceLabel[] = [];
132
133
constructor(
134
container: IResourceLabelsContainer,
135
@IInstantiationService private readonly instantiationService: IInstantiationService,
136
@IConfigurationService private readonly configurationService: IConfigurationService,
137
@IModelService private readonly modelService: IModelService,
138
@IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
139
@ILanguageService private readonly languageService: ILanguageService,
140
@IDecorationsService private readonly decorationsService: IDecorationsService,
141
@IThemeService private readonly themeService: IThemeService,
142
@ILabelService private readonly labelService: ILabelService,
143
@ITextFileService private readonly textFileService: ITextFileService
144
) {
145
super();
146
147
this.registerListeners(container);
148
}
149
150
private registerListeners(container: IResourceLabelsContainer): void {
151
152
// notify when visibility changes
153
this._register(container.onDidChangeVisibility(visible => {
154
this.widgets.forEach(widget => widget.notifyVisibilityChanged(visible));
155
}));
156
157
// notify when extensions are registered with potentially new languages
158
this._register(this.languageService.onDidChange(() => this.widgets.forEach(widget => widget.notifyExtensionsRegistered())));
159
160
// notify when model language changes
161
this._register(this.modelService.onModelLanguageChanged(e => {
162
if (!e.model.uri) {
163
return; // we need the resource to compare
164
}
165
166
this.widgets.forEach(widget => widget.notifyModelLanguageChanged(e.model));
167
}));
168
169
// notify when model is added
170
this._register(this.modelService.onModelAdded(model => {
171
if (!model.uri) {
172
return; // we need the resource to compare
173
}
174
175
this.widgets.forEach(widget => widget.notifyModelAdded(model));
176
}));
177
178
// notify when workspace folders changes
179
this._register(this.workspaceService.onDidChangeWorkspaceFolders(() => {
180
this.widgets.forEach(widget => widget.notifyWorkspaceFoldersChange());
181
}));
182
183
// notify when file decoration changes
184
this._register(this.decorationsService.onDidChangeDecorations(e => {
185
let notifyDidChangeDecorations = false;
186
this.widgets.forEach(widget => {
187
if (widget.notifyFileDecorationsChanges(e)) {
188
notifyDidChangeDecorations = true;
189
}
190
});
191
192
if (notifyDidChangeDecorations) {
193
this._onDidChangeDecorations.fire();
194
}
195
}));
196
197
// notify when theme changes
198
this._register(this.themeService.onDidColorThemeChange(() => this.widgets.forEach(widget => widget.notifyThemeChange())));
199
200
// notify when files.associations changes
201
this._register(this.configurationService.onDidChangeConfiguration(e => {
202
if (e.affectsConfiguration(FILES_ASSOCIATIONS_CONFIG)) {
203
this.widgets.forEach(widget => widget.notifyFileAssociationsChange());
204
}
205
}));
206
207
// notify when label formatters change
208
this._register(this.labelService.onDidChangeFormatters(e => {
209
this.widgets.forEach(widget => widget.notifyFormattersChange(e.scheme));
210
}));
211
212
// notify when untitled labels change
213
this._register(this.textFileService.untitled.onDidChangeLabel(model => {
214
this.widgets.forEach(widget => widget.notifyUntitledLabelChange(model.resource));
215
}));
216
}
217
218
get(index: number): IResourceLabel {
219
return this.labels[index];
220
}
221
222
create(container: HTMLElement, options?: IIconLabelCreationOptions): IResourceLabel {
223
const widget = this.instantiationService.createInstance(ResourceLabelWidget, container, options);
224
225
// Only expose a handle to the outside
226
const label: IResourceLabel = {
227
element: widget.element,
228
get onDidRender() { return widget.onDidRender; },
229
setLabel: (label: string, description?: string, options?: IIconLabelValueOptions) => widget.setLabel(label, description, options),
230
setResource: (label: IResourceLabelProps, options?: IResourceLabelOptions) => widget.setResource(label, options),
231
setFile: (resource: URI, options?: IFileLabelOptions) => widget.setFile(resource, options),
232
clear: () => widget.clear(),
233
dispose: () => this.disposeWidget(widget)
234
};
235
236
// Store
237
this.labels.push(label);
238
this.widgets.push(widget);
239
240
return label;
241
}
242
243
private disposeWidget(widget: ResourceLabelWidget): void {
244
const index = this.widgets.indexOf(widget);
245
if (index > -1) {
246
this.widgets.splice(index, 1);
247
this.labels.splice(index, 1);
248
}
249
250
dispose(widget);
251
}
252
253
clear(): void {
254
this.widgets = dispose(this.widgets);
255
this.labels = [];
256
}
257
258
override dispose(): void {
259
super.dispose();
260
261
this.clear();
262
}
263
}
264
265
/**
266
* Note: please consider to use `ResourceLabels` if you are in need
267
* of more than one label for your widget.
268
*/
269
export class ResourceLabel extends ResourceLabels {
270
271
private label: IResourceLabel;
272
get element(): IResourceLabel { return this.label; }
273
274
constructor(
275
container: HTMLElement,
276
options: IIconLabelCreationOptions | undefined,
277
@IInstantiationService instantiationService: IInstantiationService,
278
@IConfigurationService configurationService: IConfigurationService,
279
@IModelService modelService: IModelService,
280
@IWorkspaceContextService workspaceService: IWorkspaceContextService,
281
@ILanguageService languageService: ILanguageService,
282
@IDecorationsService decorationsService: IDecorationsService,
283
@IThemeService themeService: IThemeService,
284
@ILabelService labelService: ILabelService,
285
@ITextFileService textFileService: ITextFileService
286
) {
287
super(DEFAULT_LABELS_CONTAINER, instantiationService, configurationService, modelService, workspaceService, languageService, decorationsService, themeService, labelService, textFileService);
288
289
this.label = this._register(this.create(container, options));
290
}
291
}
292
293
enum Redraw {
294
Basic = 1,
295
Full = 2
296
}
297
298
class ResourceLabelWidget extends IconLabel {
299
300
private readonly _onDidRender = this._register(new Emitter<void>());
301
get onDidRender() { return this._onDidRender.event; }
302
303
private label: IResourceLabelProps | undefined = undefined;
304
private readonly decoration = this._register(new MutableDisposable<IDecoration>());
305
private options: IResourceLabelOptions | undefined = undefined;
306
307
private computedIconClasses: string[] | undefined = undefined;
308
private computedLanguageId: string | undefined = undefined;
309
private computedPathLabel: string | undefined = undefined;
310
private computedWorkspaceFolderLabel: string | undefined = undefined;
311
312
private needsRedraw: Redraw | undefined = undefined;
313
private isHidden: boolean = false;
314
315
constructor(
316
container: HTMLElement,
317
options: IIconLabelCreationOptions | undefined,
318
@ILanguageService private readonly languageService: ILanguageService,
319
@IModelService private readonly modelService: IModelService,
320
@IDecorationsService private readonly decorationsService: IDecorationsService,
321
@ILabelService private readonly labelService: ILabelService,
322
@ITextFileService private readonly textFileService: ITextFileService,
323
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
324
@INotebookDocumentService private readonly notebookDocumentService: INotebookDocumentService
325
) {
326
super(container, options);
327
}
328
329
notifyVisibilityChanged(visible: boolean): void {
330
if (visible === this.isHidden) {
331
this.isHidden = !visible;
332
333
if (visible && this.needsRedraw) {
334
this.render({
335
updateIcon: this.needsRedraw === Redraw.Full,
336
updateDecoration: this.needsRedraw === Redraw.Full
337
});
338
339
this.needsRedraw = undefined;
340
}
341
}
342
}
343
344
notifyModelLanguageChanged(model: ITextModel): void {
345
this.handleModelEvent(model);
346
}
347
348
notifyModelAdded(model: ITextModel): void {
349
this.handleModelEvent(model);
350
}
351
352
private handleModelEvent(model: ITextModel): void {
353
const resource = toResource(this.label);
354
if (!resource) {
355
return; // only update if resource exists
356
}
357
358
if (isEqual(model.uri, resource)) {
359
if (this.computedLanguageId !== model.getLanguageId()) {
360
this.computedLanguageId = model.getLanguageId();
361
this.render({ updateIcon: true, updateDecoration: false }); // update if the language id of the model has changed from our last known state
362
}
363
}
364
}
365
366
notifyFileDecorationsChanges(e: IResourceDecorationChangeEvent): boolean {
367
if (!this.options) {
368
return false;
369
}
370
371
const resource = toResource(this.label);
372
if (!resource) {
373
return false;
374
}
375
376
if (this.options.fileDecorations && e.affectsResource(resource)) {
377
return this.render({ updateIcon: false, updateDecoration: true });
378
}
379
380
return false;
381
}
382
383
notifyExtensionsRegistered(): void {
384
this.render({ updateIcon: true, updateDecoration: false });
385
}
386
387
notifyThemeChange(): void {
388
this.render({ updateIcon: false, updateDecoration: false });
389
}
390
391
notifyFileAssociationsChange(): void {
392
this.render({ updateIcon: true, updateDecoration: false });
393
}
394
395
notifyFormattersChange(scheme: string): void {
396
if (toResource(this.label)?.scheme === scheme) {
397
this.render({ updateIcon: false, updateDecoration: false });
398
}
399
}
400
401
notifyUntitledLabelChange(resource: URI): void {
402
if (isEqual(resource, toResource(this.label))) {
403
this.render({ updateIcon: false, updateDecoration: false });
404
}
405
}
406
407
notifyWorkspaceFoldersChange(): void {
408
if (typeof this.computedWorkspaceFolderLabel === 'string') {
409
const resource = toResource(this.label);
410
if (URI.isUri(resource) && this.label?.name === this.computedWorkspaceFolderLabel) {
411
this.setFile(resource, this.options);
412
}
413
}
414
}
415
416
setFile(resource: URI, options?: IFileLabelOptions): void {
417
const hideLabel = options?.hideLabel;
418
let name: string | undefined;
419
if (!hideLabel) {
420
if (options?.fileKind === FileKind.ROOT_FOLDER) {
421
const workspaceFolder = this.contextService.getWorkspaceFolder(resource);
422
if (workspaceFolder) {
423
name = workspaceFolder.name;
424
this.computedWorkspaceFolderLabel = name;
425
}
426
}
427
428
if (!name) {
429
name = normalizeDriveLetter(basenameOrAuthority(resource));
430
}
431
}
432
433
let description: string | undefined;
434
if (!options?.hidePath) {
435
const descriptionCandidate = this.labelService.getUriLabel(dirname(resource), { relative: true });
436
if (descriptionCandidate && descriptionCandidate !== '.') {
437
// omit description if its not significant: a relative path
438
// of '.' just indicates that there is no parent to the path
439
// https://github.com/microsoft/vscode/issues/208692
440
description = descriptionCandidate;
441
}
442
}
443
444
this.setResource({ resource, name, description, range: options?.range }, options);
445
}
446
447
setResource(label: IResourceLabelProps, options: IResourceLabelOptions = Object.create(null)): void {
448
const resource = toResource(label);
449
const isSideBySideEditor = label?.resource && !URI.isUri(label.resource);
450
451
if (!options.forceLabel && !isSideBySideEditor && resource?.scheme === Schemas.untitled) {
452
// Untitled labels are very dynamic because they may change
453
// whenever the content changes (unless a path is associated).
454
// As such we always ask the actual editor for it's name and
455
// description to get latest in case name/description are
456
// provided. If they are not provided from the label we got
457
// we assume that the client does not want to display them
458
// and as such do not override.
459
//
460
// We do not touch the label if it represents a primary-secondary
461
// because in that case we expect it to carry a proper label
462
// and description.
463
const untitledModel = this.textFileService.untitled.get(resource);
464
if (untitledModel && !untitledModel.hasAssociatedFilePath) {
465
if (typeof label.name === 'string') {
466
label.name = untitledModel.name;
467
}
468
469
if (typeof label.description === 'string') {
470
const untitledDescription = untitledModel.resource.path;
471
if (label.name !== untitledDescription) {
472
label.description = untitledDescription;
473
} else {
474
label.description = undefined;
475
}
476
}
477
478
const untitledTitle = untitledModel.resource.path;
479
if (untitledModel.name !== untitledTitle) {
480
options.title = `${untitledModel.name} • ${untitledTitle}`;
481
} else {
482
options.title = untitledTitle;
483
}
484
}
485
}
486
487
if (!options.forceLabel && !isSideBySideEditor && resource?.scheme === Schemas.vscodeNotebookCell) {
488
// Notebook cells are embeded in a notebook document
489
// As such we always ask the actual notebook document
490
// for its position in the document.
491
const notebookDocument = this.notebookDocumentService.getNotebook(resource);
492
const cellIndex = notebookDocument?.getCellIndex(resource);
493
if (notebookDocument && cellIndex !== undefined && typeof label.name === 'string') {
494
options.title = localize('notebookCellLabel', "{0} • Cell {1}", label.name, `${cellIndex + 1}`);
495
}
496
497
if (typeof label.name === 'string' && notebookDocument && cellIndex !== undefined && typeof label.name === 'string') {
498
label.name = localize('notebookCellLabel', "{0} • Cell {1}", label.name, `${cellIndex + 1}`);
499
}
500
}
501
502
if (!options.forceLabel && !isSideBySideEditor && resource?.scheme === Schemas.vscodeNotebookCellOutput) {
503
const notebookDocument = this.notebookDocumentService.getNotebook(resource);
504
const outputUriData = extractCellOutputDetails(resource);
505
if (outputUriData?.cellFragment) {
506
if (!outputUriData.notebook) {
507
return;
508
}
509
const cellUri = outputUriData.notebook.with({
510
scheme: Schemas.vscodeNotebookCell,
511
fragment: outputUriData.cellFragment
512
});
513
const cellIndex = notebookDocument?.getCellIndex(cellUri);
514
const outputIndex = outputUriData.outputIndex;
515
516
if (cellIndex !== undefined && outputIndex !== undefined && typeof label.name === 'string') {
517
label.name = localize(
518
'notebookCellOutputLabel',
519
"{0} • Cell {1} • Output {2}",
520
label.name,
521
`${cellIndex + 1}`,
522
`${outputIndex + 1}`
523
);
524
} else if (cellIndex !== undefined && typeof label.name === 'string') {
525
label.name = localize(
526
'notebookCellOutputLabelSimple',
527
"{0} • Cell {1} • Output",
528
label.name,
529
`${cellIndex + 1}`
530
);
531
}
532
}
533
}
534
535
if (options.namePrefix) {
536
if (typeof label.name === 'string') {
537
label.name = options.namePrefix + label.name;
538
} else if (Array.isArray(label.name) && label.name.length > 0) {
539
label.name = [options.namePrefix + label.name[0], ...label.name.slice(1)];
540
}
541
}
542
543
if (options.nameSuffix) {
544
if (typeof label.name === 'string') {
545
label.name = label.name + options.nameSuffix;
546
} else if (Array.isArray(label.name) && label.name.length > 0) {
547
label.name = [...label.name.slice(0, label.name.length - 1), label.name[label.name.length - 1] + options.nameSuffix];
548
}
549
}
550
551
const hasResourceChanged = this.hasResourceChanged(label);
552
const hasPathLabelChanged = hasResourceChanged || this.hasPathLabelChanged(label);
553
const hasFileKindChanged = this.hasFileKindChanged(options);
554
const hasIconChanged = this.hasIconChanged(options);
555
556
this.label = label;
557
this.options = options;
558
559
if (hasResourceChanged) {
560
this.computedLanguageId = undefined; // reset computed language since resource changed
561
}
562
563
if (hasPathLabelChanged) {
564
this.computedPathLabel = undefined; // reset path label due to resource/path-label change
565
}
566
567
this.render({
568
updateIcon: hasResourceChanged || hasFileKindChanged || hasIconChanged,
569
updateDecoration: hasResourceChanged || hasFileKindChanged
570
});
571
}
572
573
private hasFileKindChanged(newOptions?: IResourceLabelOptions): boolean {
574
const newFileKind = newOptions?.fileKind;
575
const oldFileKind = this.options?.fileKind;
576
577
return newFileKind !== oldFileKind; // same resource but different kind (file, folder)
578
}
579
580
private hasResourceChanged(newLabel: IResourceLabelProps): boolean {
581
const newResource = toResource(newLabel);
582
const oldResource = toResource(this.label);
583
584
if (newResource && oldResource) {
585
return newResource.toString() !== oldResource.toString();
586
}
587
588
if (!newResource && !oldResource) {
589
return false;
590
}
591
592
return true;
593
}
594
595
private hasPathLabelChanged(newLabel: IResourceLabelProps): boolean {
596
const newResource = toResource(newLabel);
597
598
return !!newResource && this.computedPathLabel !== this.labelService.getUriLabel(newResource);
599
}
600
601
private hasIconChanged(newOptions?: IResourceLabelOptions): boolean {
602
return this.options?.icon !== newOptions?.icon;
603
}
604
605
clear(): void {
606
this.label = undefined;
607
this.options = undefined;
608
this.computedLanguageId = undefined;
609
this.computedIconClasses = undefined;
610
this.computedPathLabel = undefined;
611
612
this.setLabel('');
613
}
614
615
private render(options: { updateIcon: boolean; updateDecoration: boolean }): boolean {
616
if (this.isHidden) {
617
if (this.needsRedraw !== Redraw.Full) {
618
this.needsRedraw = (options.updateIcon || options.updateDecoration) ? Redraw.Full : Redraw.Basic;
619
}
620
621
return false;
622
}
623
624
if (options.updateIcon) {
625
this.computedIconClasses = undefined;
626
}
627
628
if (!this.label) {
629
return false;
630
}
631
632
const iconLabelOptions: IIconLabelValueOptions & { extraClasses: string[] } = {
633
title: '',
634
bold: this.options?.bold,
635
italic: this.options?.italic,
636
strikethrough: this.options?.strikethrough,
637
matches: this.options?.matches,
638
descriptionMatches: this.options?.descriptionMatches,
639
extraClasses: [],
640
separator: this.options?.separator,
641
domId: this.options?.domId,
642
disabledCommand: this.options?.disabledCommand,
643
labelEscapeNewLines: this.options?.labelEscapeNewLines,
644
descriptionTitle: this.options?.descriptionTitle,
645
supportIcons: this.options?.supportIcons,
646
};
647
648
const resource = toResource(this.label);
649
650
if (this.options?.title !== undefined) {
651
iconLabelOptions.title = this.options.title;
652
}
653
654
if (resource && resource.scheme !== Schemas.data /* do not accidentally inline Data URIs */
655
&& (
656
(!this.options?.title)
657
|| ((typeof this.options.title !== 'string') && !this.options.title.markdownNotSupportedFallback)
658
)) {
659
660
if (!this.computedPathLabel) {
661
this.computedPathLabel = this.labelService.getUriLabel(resource);
662
}
663
664
if (!iconLabelOptions.title || (typeof iconLabelOptions.title === 'string')) {
665
iconLabelOptions.title = this.computedPathLabel;
666
} else if (!iconLabelOptions.title.markdownNotSupportedFallback) {
667
iconLabelOptions.title.markdownNotSupportedFallback = this.computedPathLabel;
668
}
669
}
670
671
if (this.options && !this.options.hideIcon) {
672
if (!this.computedIconClasses) {
673
this.computedIconClasses = getIconClasses(this.modelService, this.languageService, resource, this.options.fileKind, this.options.icon);
674
}
675
676
if (URI.isUri(this.options.icon)) {
677
iconLabelOptions.iconPath = this.options.icon;
678
}
679
680
iconLabelOptions.extraClasses = this.computedIconClasses.slice(0);
681
}
682
683
if (this.options?.extraClasses) {
684
iconLabelOptions.extraClasses.push(...this.options.extraClasses);
685
}
686
687
if (this.options?.fileDecorations && resource) {
688
if (options.updateDecoration) {
689
this.decoration.value = this.decorationsService.getDecoration(resource, this.options.fileKind !== FileKind.FILE);
690
}
691
692
const decoration = this.decoration.value;
693
if (decoration) {
694
if (decoration.tooltip) {
695
if (typeof iconLabelOptions.title === 'string') {
696
iconLabelOptions.title = `${iconLabelOptions.title} • ${decoration.tooltip}`;
697
} else if (typeof iconLabelOptions.title?.markdown === 'string') {
698
const title = `${iconLabelOptions.title.markdown} • ${decoration.tooltip}`;
699
iconLabelOptions.title = { markdown: title, markdownNotSupportedFallback: title };
700
}
701
}
702
703
if (decoration.strikethrough) {
704
iconLabelOptions.strikethrough = true;
705
}
706
707
if (this.options.fileDecorations.colors) {
708
iconLabelOptions.extraClasses.push(decoration.labelClassName);
709
}
710
711
if (this.options.fileDecorations.badges) {
712
iconLabelOptions.extraClasses.push(decoration.badgeClassName);
713
iconLabelOptions.extraClasses.push(decoration.iconClassName);
714
}
715
}
716
}
717
718
if (this.label.range) {
719
iconLabelOptions.suffix = this.label.range.startLineNumber !== this.label.range.endLineNumber ?
720
`:${this.label.range.startLineNumber}-${this.label.range.endLineNumber}` :
721
`:${this.label.range.startLineNumber}`;
722
}
723
724
this.setLabel(this.label.name ?? '', this.label.description, iconLabelOptions);
725
726
this._onDidRender.fire();
727
728
return true;
729
}
730
731
override dispose(): void {
732
super.dispose();
733
734
this.label = undefined;
735
this.options = undefined;
736
this.computedLanguageId = undefined;
737
this.computedIconClasses = undefined;
738
this.computedPathLabel = undefined;
739
this.computedWorkspaceFolderLabel = undefined;
740
}
741
}
742
743