Skip to content

Commit b879d03

Browse files
authored
Mark quick input button and classlist arrays as readonly (microsoft#163891)
1 parent 1c78193 commit b879d03

File tree

7 files changed

+30
-25
lines changed

7 files changed

+30
-25
lines changed

src/vs/base/browser/ui/highlightedlabel/highlightedLabel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class HighlightedLabel {
3333
private readonly domNode: HTMLElement;
3434
private text: string = '';
3535
private title: string = '';
36-
private highlights: IHighlight[] = [];
36+
private highlights: readonly IHighlight[] = [];
3737
private supportIcons: boolean;
3838
private didEverRender: boolean = false;
3939

@@ -63,7 +63,7 @@ export class HighlightedLabel {
6363
* @param escapeNewLines Whether to escape new lines.
6464
* @returns
6565
*/
66-
set(text: string | undefined, highlights: IHighlight[] = [], title: string = '', escapeNewLines?: boolean) {
66+
set(text: string | undefined, highlights: readonly IHighlight[] = [], title: string = '', escapeNewLines?: boolean) {
6767
if (!text) {
6868
text = '';
6969
}
@@ -126,7 +126,7 @@ export class HighlightedLabel {
126126
this.didEverRender = true;
127127
}
128128

129-
static escapeNewLines(text: string, highlights: IHighlight[]): string {
129+
static escapeNewLines(text: string, highlights: readonly IHighlight[]): string {
130130
let total = 0;
131131
let extra = 0;
132132

src/vs/base/browser/ui/iconLabel/iconLabel.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ import { equals } from 'vs/base/common/objects';
1414
import { Range } from 'vs/base/common/range';
1515

1616
export interface IIconLabelCreationOptions {
17-
supportHighlights?: boolean;
18-
supportDescriptionHighlights?: boolean;
19-
supportIcons?: boolean;
20-
hoverDelegate?: IHoverDelegate;
17+
readonly supportHighlights?: boolean;
18+
readonly supportDescriptionHighlights?: boolean;
19+
readonly supportIcons?: boolean;
20+
readonly hoverDelegate?: IHoverDelegate;
2121
}
2222

2323
export interface IIconLabelValueOptions {
2424
title?: string | ITooltipMarkdownString;
2525
descriptionTitle?: string;
2626
hideIcon?: boolean;
27-
extraClasses?: string[];
27+
extraClasses?: readonly string[];
2828
italic?: boolean;
2929
strikethrough?: boolean;
30-
matches?: IMatch[];
30+
matches?: readonly IMatch[];
3131
labelEscapeNewLines?: boolean;
32-
descriptionMatches?: IMatch[];
32+
descriptionMatches?: readonly IMatch[];
3333
disabledCommand?: boolean;
3434
readonly separator?: string;
3535
readonly domId?: string;
@@ -241,7 +241,7 @@ class Label {
241241
}
242242
}
243243

244-
function splitMatches(labels: string[], separator: string, matches: IMatch[] | undefined): IMatch[][] | undefined {
244+
function splitMatches(labels: string[], separator: string, matches: readonly IMatch[] | undefined): IMatch[][] | undefined {
245245
if (!matches) {
246246
return undefined;
247247
}

src/vs/base/parts/quickinput/common/quickInput.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export interface IQuickPickItem {
3434
* keyboard shortcut.
3535
*/
3636
keybinding?: ResolvedKeybinding;
37-
iconClasses?: string[];
37+
iconClasses?: readonly string[];
3838
italic?: boolean;
3939
strikethrough?: boolean;
4040
highlights?: IQuickPickItemHighlights;
41-
buttons?: IQuickInputButton[];
41+
buttons?: readonly IQuickInputButton[];
4242
picked?: boolean;
4343
alwaysShow?: boolean;
4444
}
@@ -48,7 +48,7 @@ export interface IQuickPickSeparator {
4848
id?: string;
4949
label?: string;
5050
ariaLabel?: string;
51-
buttons?: IQuickInputButton[];
51+
buttons?: readonly IQuickInputButton[];
5252
}
5353

5454
export interface IKeyMods {
@@ -59,7 +59,7 @@ export interface IKeyMods {
5959
export const NO_KEY_MODS: IKeyMods = { ctrlCmd: false, alt: false };
6060

6161
export interface IQuickNavigateConfiguration {
62-
keybindings: ResolvedKeybinding[];
62+
keybindings: readonly ResolvedKeybinding[];
6363
}
6464

6565
export interface IPickOptions<T extends IQuickPickItem> {

src/vs/platform/quickinput/browser/quickPickPin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ function updateButtons(item: QuickPickItem, removePin: boolean): void {
7777
if (item.type === 'separator') {
7878
return;
7979
}
80+
8081
// remove button classes before adding the new one
81-
item.buttons = item.buttons ? item.buttons?.filter(button => button.iconClass && !buttonClasses.includes(button.iconClass)) : [];
82-
item.buttons.unshift({
82+
const newButtons = item.buttons?.filter(button => button.iconClass && !buttonClasses.includes(button.iconClass)) ?? [];
83+
newButtons.unshift({
8384
iconClass: removePin ? pinButtonClass : pinnedButtonClass,
8485
tooltip: removePin ? localize('pinCommand', "Pin command") : localize('pinnedCommand', "Pinned command"),
8586
alwaysVisible: false
8687
});
88+
item.buttons = newButtons;
8789
}
8890

8991
function itemsMatch(itemA: QuickPickItem, itemB: QuickPickItem): boolean {

src/vs/workbench/contrib/codeEditor/browser/outline/documentSymbolsTree.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,11 @@ export class DocumentSymbolRenderer implements ITreeRenderer<OutlineElement, Fuz
133133

134134
renderElement(node: ITreeNode<OutlineElement, FuzzyScore>, _index: number, template: DocumentSymbolTemplate): void {
135135
const { element } = node;
136+
const extraClasses = ['nowrap'];
136137
const options: IIconLabelValueOptions = {
137138
matches: createMatches(node.filterData),
138139
labelEscapeNewLines: true,
139-
extraClasses: ['nowrap'],
140+
extraClasses,
140141
title: localize('title.template', "{0} ({1})", element.symbol.name, DocumentSymbolRenderer._symbolKindNames[element.symbol.kind])
141142
};
142143
if (this._configurationService.getValue(OutlineConfigKeys.icons)) {
@@ -145,7 +146,7 @@ export class DocumentSymbolRenderer implements ITreeRenderer<OutlineElement, Fuz
145146
template.iconClass.classList.add('outline-element-icon', 'inline', ...CSSIcon.asClassNameArray(SymbolKinds.toIcon(element.symbol.kind)));
146147
}
147148
if (element.symbol.tags.indexOf(SymbolTag.Deprecated) >= 0) {
148-
options.extraClasses!.push(`deprecated`);
149+
extraClasses.push(`deprecated`);
149150
options.matches = [];
150151
}
151152
template.iconLabel.setLabel(element.symbol.name, element.symbol.detail, options);

src/vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,16 @@ class NotebookOutlineRenderer implements ITreeRenderer<OutlineEntry, FuzzyScore,
168168
}
169169

170170
renderElement(node: ITreeNode<OutlineEntry, FuzzyScore>, _index: number, template: NotebookOutlineTemplate, _height: number | undefined): void {
171+
const extraClasses: string[] = [];
171172
const options: IIconLabelValueOptions = {
172173
matches: createMatches(node.filterData),
173174
labelEscapeNewLines: true,
174-
extraClasses: []
175+
extraClasses,
175176
};
176177

177178
if (node.element.cell.cellKind === CellKind.Code && this._themeService.getFileIconTheme().hasFileIcons && !node.element.isExecuting) {
178179
template.iconClass.className = '';
179-
options.extraClasses?.push(...getIconClassesForLanguageId(node.element.cell.language ?? ''));
180+
extraClasses.push(...getIconClassesForLanguageId(node.element.cell.language ?? ''));
180181
} else {
181182
template.iconClass.className = 'element-icon ' + ThemeIcon.asClassNameArray(node.element.icon).join(' ');
182183
}

src/vs/workbench/contrib/tasks/browser/taskQuickPick.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ export class TaskQuickPick extends Disposable {
9999
}
100100
}
101101

102-
private _createTaskEntry(task: Task | ConfiguringTask, extraButtons: IQuickInputButton[] = []): ITaskTwoLevelQuickPickEntry {
102+
private _createTaskEntry(task: Task | ConfiguringTask, extraButtons: readonly IQuickInputButton[] = []): ITaskTwoLevelQuickPickEntry {
103103
const entry: ITaskTwoLevelQuickPickEntry = { label: TaskQuickPick.getTaskLabelWithIcon(task, this._guessTaskLabel(task)), description: this._taskService.getTaskDescription(task), task, detail: this._showDetail() ? task.configurationProperties.detail : undefined };
104-
entry.buttons = [];
105-
entry.buttons.push({ iconClass: ThemeIcon.asClassName(configureTaskIcon), tooltip: nls.localize('configureTask', "Configure Task") });
106-
entry.buttons.push(...extraButtons);
104+
entry.buttons = [
105+
{ iconClass: ThemeIcon.asClassName(configureTaskIcon), tooltip: nls.localize('configureTask', "Configure Task") },
106+
...extraButtons,
107+
];
107108
TaskQuickPick.applyColorStyles(task, entry, this._themeService);
108109
return entry;
109110
}

0 commit comments

Comments
 (0)