@theia/scm 1.75.0-next.8 → 1.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/decorations/scm-navigator-decorator.d.ts.map +1 -1
- package/lib/browser/decorations/scm-navigator-decorator.js +1 -0
- package/lib/browser/decorations/scm-navigator-decorator.js.map +1 -1
- package/lib/browser/merge-editor/view/merge-editor-panes/merge-editor-pane-header.js +7 -10
- package/lib/browser/merge-editor/view/merge-editor-panes/merge-editor-pane-header.js.map +1 -1
- package/lib/browser/scm-action-button-widget.js +10 -15
- package/lib/browser/scm-action-button-widget.js.map +1 -1
- package/lib/browser/scm-amend-component.js +24 -57
- package/lib/browser/scm-amend-component.js.map +1 -1
- package/lib/browser/scm-commit-widget.d.ts +1 -1
- package/lib/browser/scm-commit-widget.d.ts.map +1 -1
- package/lib/browser/scm-commit-widget.js +9 -10
- package/lib/browser/scm-commit-widget.js.map +1 -1
- package/lib/browser/scm-context-key-service.d.ts +2 -0
- package/lib/browser/scm-context-key-service.d.ts.map +1 -1
- package/lib/browser/scm-context-key-service.js +4 -0
- package/lib/browser/scm-context-key-service.js.map +1 -1
- package/lib/browser/scm-context-key-service.spec.js +7 -0
- package/lib/browser/scm-context-key-service.spec.js.map +1 -1
- package/lib/browser/scm-frontend-module.d.ts.map +1 -1
- package/lib/browser/scm-frontend-module.js +6 -0
- package/lib/browser/scm-frontend-module.js.map +1 -1
- package/lib/browser/scm-history-graph-contribution.d.ts +49 -0
- package/lib/browser/scm-history-graph-contribution.d.ts.map +1 -0
- package/lib/browser/scm-history-graph-contribution.js +280 -0
- package/lib/browser/scm-history-graph-contribution.js.map +1 -0
- package/lib/browser/scm-history-graph-contribution.spec.d.ts +2 -0
- package/lib/browser/scm-history-graph-contribution.spec.d.ts.map +1 -0
- package/lib/browser/scm-history-graph-contribution.spec.js +119 -0
- package/lib/browser/scm-history-graph-contribution.spec.js.map +1 -0
- package/lib/browser/scm-history-graph-helpers.d.ts +59 -6
- package/lib/browser/scm-history-graph-helpers.d.ts.map +1 -1
- package/lib/browser/scm-history-graph-helpers.js +129 -5
- package/lib/browser/scm-history-graph-helpers.js.map +1 -1
- package/lib/browser/scm-history-graph-helpers.spec.d.ts +2 -0
- package/lib/browser/scm-history-graph-helpers.spec.d.ts.map +1 -0
- package/lib/browser/scm-history-graph-helpers.spec.js +154 -0
- package/lib/browser/scm-history-graph-helpers.spec.js.map +1 -0
- package/lib/browser/scm-history-graph-lanes.d.ts +19 -5
- package/lib/browser/scm-history-graph-lanes.d.ts.map +1 -1
- package/lib/browser/scm-history-graph-lanes.js +25 -9
- package/lib/browser/scm-history-graph-lanes.js.map +1 -1
- package/lib/browser/scm-history-graph-lanes.spec.js +62 -25
- package/lib/browser/scm-history-graph-lanes.spec.js.map +1 -1
- package/lib/browser/scm-history-graph-model.d.ts +75 -6
- package/lib/browser/scm-history-graph-model.d.ts.map +1 -1
- package/lib/browser/scm-history-graph-model.js +155 -10
- package/lib/browser/scm-history-graph-model.js.map +1 -1
- package/lib/browser/scm-history-graph-model.spec.js +299 -4
- package/lib/browser/scm-history-graph-model.spec.js.map +1 -1
- package/lib/browser/scm-history-graph-tooltip.d.ts +27 -2
- package/lib/browser/scm-history-graph-tooltip.d.ts.map +1 -1
- package/lib/browser/scm-history-graph-tooltip.js +113 -22
- package/lib/browser/scm-history-graph-tooltip.js.map +1 -1
- package/lib/browser/scm-history-graph-tooltip.spec.d.ts +2 -0
- package/lib/browser/scm-history-graph-tooltip.spec.d.ts.map +1 -0
- package/lib/browser/scm-history-graph-tooltip.spec.js +213 -0
- package/lib/browser/scm-history-graph-tooltip.spec.js.map +1 -0
- package/lib/browser/scm-history-graph-widget.d.ts +36 -2
- package/lib/browser/scm-history-graph-widget.d.ts.map +1 -1
- package/lib/browser/scm-history-graph-widget.js +174 -67
- package/lib/browser/scm-history-graph-widget.js.map +1 -1
- package/lib/browser/scm-history-graph-widget.spec.d.ts +2 -0
- package/lib/browser/scm-history-graph-widget.spec.d.ts.map +1 -0
- package/lib/browser/scm-history-graph-widget.spec.js +273 -0
- package/lib/browser/scm-history-graph-widget.spec.js.map +1 -0
- package/lib/browser/scm-provider.d.ts +9 -1
- package/lib/browser/scm-provider.d.ts.map +1 -1
- package/lib/browser/scm-provider.js.map +1 -1
- package/lib/browser/scm-repositories-widget.js +12 -21
- package/lib/browser/scm-repositories-widget.js.map +1 -1
- package/lib/browser/scm-tree-widget.js +35 -53
- package/lib/browser/scm-tree-widget.js.map +1 -1
- package/lib/common/scm-preferences.d.ts +3 -0
- package/lib/common/scm-preferences.d.ts.map +1 -1
- package/lib/common/scm-preferences.js +24 -0
- package/lib/common/scm-preferences.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/decorations/scm-navigator-decorator.ts +3 -2
- package/src/browser/scm-context-key-service.spec.ts +9 -0
- package/src/browser/scm-context-key-service.ts +6 -0
- package/src/browser/scm-frontend-module.ts +7 -1
- package/src/browser/scm-history-graph-contribution.spec.ts +148 -0
- package/src/browser/scm-history-graph-contribution.ts +273 -0
- package/src/browser/scm-history-graph-helpers.spec.ts +193 -0
- package/src/browser/scm-history-graph-helpers.ts +180 -6
- package/src/browser/scm-history-graph-lanes.spec.ts +70 -25
- package/src/browser/scm-history-graph-lanes.ts +48 -11
- package/src/browser/scm-history-graph-model.spec.ts +378 -12
- package/src/browser/scm-history-graph-model.ts +181 -13
- package/src/browser/scm-history-graph-tooltip.spec.ts +254 -0
- package/src/browser/scm-history-graph-tooltip.ts +144 -24
- package/src/browser/scm-history-graph-widget.spec.ts +322 -0
- package/src/browser/scm-history-graph-widget.tsx +199 -39
- package/src/browser/scm-provider.ts +9 -1
- package/src/browser/style/scm-history-graph.css +53 -2
- package/src/common/scm-preferences.ts +27 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 Safi Seid-Ahmad, K2view and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable, inject, named, optional } from '@theia/core/shared/inversify';
|
|
18
|
+
import { ILogger } from '@theia/core';
|
|
19
|
+
import { Command, CommandContribution, CommandRegistry } from '@theia/core/lib/common/command';
|
|
20
|
+
import { MenuContribution, MenuModelRegistry } from '@theia/core/lib/common/menu';
|
|
21
|
+
import { nls } from '@theia/core/lib/common/nls';
|
|
22
|
+
import { CancellationTokenSource } from '@theia/core/lib/common/cancellation';
|
|
23
|
+
import { QuickInputService } from '@theia/core/lib/browser';
|
|
24
|
+
import { QuickPickItem, QuickPickSeparator } from '@theia/core/lib/common/quick-pick-service';
|
|
25
|
+
import { codicon } from '@theia/core/lib/browser/widgets/widget';
|
|
26
|
+
import { ScmHistoryGraphModel, ScmHistoryGraphModelProvider } from './scm-history-graph-model';
|
|
27
|
+
import { ScmService } from './scm-service';
|
|
28
|
+
import { ScmContextKeyService } from './scm-context-key-service';
|
|
29
|
+
import { ScmHistoryItemRef, ScmHistoryProvider } from './scm-provider';
|
|
30
|
+
import { SCM_HISTORY_TITLE_MENU } from './scm-history-graph-widget';
|
|
31
|
+
import { getRefBadgeClass } from './scm-history-graph-helpers';
|
|
32
|
+
|
|
33
|
+
export namespace ScmHistoryGraphCommands {
|
|
34
|
+
export const REFRESH = Command.toDefaultLocalizedCommand({
|
|
35
|
+
id: 'scmHistoryGraph.refresh',
|
|
36
|
+
category: 'Source Control',
|
|
37
|
+
label: 'Refresh',
|
|
38
|
+
iconClass: codicon('refresh')
|
|
39
|
+
});
|
|
40
|
+
export const PICK_HISTORY_ITEM_REFS = Command.toLocalizedCommand({
|
|
41
|
+
id: 'scmHistoryGraph.pickHistoryItemRefs',
|
|
42
|
+
category: 'Source Control',
|
|
43
|
+
label: 'Pick History Item Reference...',
|
|
44
|
+
iconClass: codicon('git-branch')
|
|
45
|
+
}, 'theia/scm/pickHistoryItemRefs');
|
|
46
|
+
export const REVEAL_CURRENT_HISTORY_ITEM = Command.toDefaultLocalizedCommand({
|
|
47
|
+
id: 'scmHistoryGraph.revealCurrentHistoryItem',
|
|
48
|
+
category: 'Source Control',
|
|
49
|
+
label: 'Go to Current History Item',
|
|
50
|
+
iconClass: codicon('target')
|
|
51
|
+
});
|
|
52
|
+
export const SET_LIST_VIEW_MODE = Command.toDefaultLocalizedCommand({
|
|
53
|
+
id: 'scmHistoryGraph.setListViewMode',
|
|
54
|
+
category: 'Source Control',
|
|
55
|
+
label: 'View as List'
|
|
56
|
+
});
|
|
57
|
+
export const SET_TREE_VIEW_MODE = Command.toDefaultLocalizedCommand({
|
|
58
|
+
id: 'scmHistoryGraph.setTreeViewMode',
|
|
59
|
+
category: 'Source Control',
|
|
60
|
+
label: 'View as Tree'
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type RefPickItem = QuickPickItem & { refId?: string; auto?: boolean };
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Contributes the native toolbar actions of the SCM history graph: the
|
|
68
|
+
* history item reference filter picker (VS Code's "Auto" dropdown) and the
|
|
69
|
+
* refresh action. Extension actions (e.g. fetch/pull/push from vscode.git)
|
|
70
|
+
* are contributed separately via the `scm/history/title` menu.
|
|
71
|
+
*/
|
|
72
|
+
@injectable()
|
|
73
|
+
export class ScmHistoryGraphContribution implements CommandContribution, MenuContribution {
|
|
74
|
+
|
|
75
|
+
@inject(ScmService) protected readonly scmService: ScmService;
|
|
76
|
+
@inject(ScmHistoryGraphModelProvider) protected readonly modelProvider: ScmHistoryGraphModelProvider;
|
|
77
|
+
@inject(QuickInputService) @optional() protected readonly quickInputService: QuickInputService;
|
|
78
|
+
@inject(ILogger) @named('scm:ScmHistoryGraphContribution') protected readonly logger: ILogger;
|
|
79
|
+
@inject(ScmContextKeyService) protected readonly scmContextKeys: ScmContextKeyService;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The graph model, resolved lazily: instantiating it starts loading
|
|
83
|
+
* history, so it must only be resolved when a graph command actually
|
|
84
|
+
* runs or the graph toolbar renders (the widget has created the model
|
|
85
|
+
* by then). In particular, `isEnabled`/`isVisible` are also queried by
|
|
86
|
+
* the command palette and therefore consult the `ScmService` instead.
|
|
87
|
+
*/
|
|
88
|
+
protected get model(): ScmHistoryGraphModel {
|
|
89
|
+
return this.modelProvider();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
protected get historyProvider(): ScmHistoryProvider | undefined {
|
|
93
|
+
return this.scmService.selectedRepository?.provider.historyProvider;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
registerCommands(commands: CommandRegistry): void {
|
|
97
|
+
commands.registerCommand(ScmHistoryGraphCommands.REFRESH, {
|
|
98
|
+
isEnabled: () => !!this.historyProvider,
|
|
99
|
+
isVisible: () => !!this.historyProvider,
|
|
100
|
+
execute: () => this.model.refresh()
|
|
101
|
+
});
|
|
102
|
+
commands.registerCommand(ScmHistoryGraphCommands.PICK_HISTORY_ITEM_REFS, {
|
|
103
|
+
isEnabled: () => !!this.historyProvider && !!this.quickInputService,
|
|
104
|
+
isVisible: () => !!this.historyProvider,
|
|
105
|
+
isToggled: () => !!this.model.historyItemRefFilter,
|
|
106
|
+
execute: () => this.pickHistoryItemRefs()
|
|
107
|
+
});
|
|
108
|
+
commands.registerCommand(ScmHistoryGraphCommands.REVEAL_CURRENT_HISTORY_ITEM, {
|
|
109
|
+
// There is nothing to reveal while the filter excludes the current ref,
|
|
110
|
+
// mirroring VS Code's precondition for this action.
|
|
111
|
+
isEnabled: () => !!this.historyProvider && this.scmContextKeys.scmCurrentHistoryItemRefInFilter.get() === true,
|
|
112
|
+
isVisible: () => !!this.historyProvider,
|
|
113
|
+
execute: () => this.model.revealCurrentHistoryItem()
|
|
114
|
+
});
|
|
115
|
+
commands.registerCommand(ScmHistoryGraphCommands.SET_LIST_VIEW_MODE, {
|
|
116
|
+
isEnabled: () => !!this.historyProvider,
|
|
117
|
+
isVisible: () => !!this.historyProvider,
|
|
118
|
+
isToggled: () => this.model.viewMode === 'list',
|
|
119
|
+
execute: () => this.model.setViewMode('list')
|
|
120
|
+
});
|
|
121
|
+
commands.registerCommand(ScmHistoryGraphCommands.SET_TREE_VIEW_MODE, {
|
|
122
|
+
isEnabled: () => !!this.historyProvider,
|
|
123
|
+
isVisible: () => !!this.historyProvider,
|
|
124
|
+
isToggled: () => this.model.viewMode === 'tree',
|
|
125
|
+
execute: () => this.model.setViewMode('tree')
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
registerMenus(menus: MenuModelRegistry): void {
|
|
130
|
+
// Extension actions from vscode.git sit at order 900-902; the picker
|
|
131
|
+
// goes before them and refresh last, matching VS Code's graph toolbar.
|
|
132
|
+
menus.registerMenuAction([...SCM_HISTORY_TITLE_MENU, 'navigation'], {
|
|
133
|
+
commandId: ScmHistoryGraphCommands.PICK_HISTORY_ITEM_REFS.id,
|
|
134
|
+
order: '100'
|
|
135
|
+
});
|
|
136
|
+
menus.registerMenuAction([...SCM_HISTORY_TITLE_MENU, 'navigation'], {
|
|
137
|
+
commandId: ScmHistoryGraphCommands.REVEAL_CURRENT_HISTORY_ITEM.id,
|
|
138
|
+
order: '200'
|
|
139
|
+
});
|
|
140
|
+
menus.registerMenuAction([...SCM_HISTORY_TITLE_MENU, 'navigation'], {
|
|
141
|
+
commandId: ScmHistoryGraphCommands.REFRESH.id,
|
|
142
|
+
order: '999'
|
|
143
|
+
});
|
|
144
|
+
// Groups other than 'navigation' are rendered in the toolbar's overflow menu,
|
|
145
|
+
// which is where VS Code places the view mode toggles as well.
|
|
146
|
+
menus.registerMenuAction([...SCM_HISTORY_TITLE_MENU, '9_viewmode'], {
|
|
147
|
+
commandId: ScmHistoryGraphCommands.SET_LIST_VIEW_MODE.id,
|
|
148
|
+
order: '1'
|
|
149
|
+
});
|
|
150
|
+
menus.registerMenuAction([...SCM_HISTORY_TITLE_MENU, '9_viewmode'], {
|
|
151
|
+
commandId: ScmHistoryGraphCommands.SET_TREE_VIEW_MODE.id,
|
|
152
|
+
order: '2'
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected async pickHistoryItemRefs(): Promise<void> {
|
|
157
|
+
if (!this.quickInputService) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const model = this.model;
|
|
161
|
+
const provider = model.provider;
|
|
162
|
+
if (!provider) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const picker = this.quickInputService.createQuickPick<RefPickItem>();
|
|
166
|
+
const cts = new CancellationTokenSource();
|
|
167
|
+
try {
|
|
168
|
+
picker.placeholder = nls.localize('theia/scm/pickHistoryItemRefsPlaceholder', 'Select one or more history item references');
|
|
169
|
+
picker.canSelectMany = true;
|
|
170
|
+
picker.matchOnDescription = true;
|
|
171
|
+
// Show the picker right away and populate it once the refs arrive,
|
|
172
|
+
// so that a slow ref lookup surfaces as a busy picker instead of a
|
|
173
|
+
// command that appears to do nothing.
|
|
174
|
+
picker.busy = true;
|
|
175
|
+
|
|
176
|
+
const selection = await new Promise<readonly RefPickItem[] | undefined>(resolve => {
|
|
177
|
+
picker.onDidAccept(() => {
|
|
178
|
+
resolve(picker.selectedItems);
|
|
179
|
+
picker.hide();
|
|
180
|
+
});
|
|
181
|
+
// Also cancels a still-running ref lookup when the picker is dismissed.
|
|
182
|
+
picker.onDidHide(() => {
|
|
183
|
+
cts.cancel();
|
|
184
|
+
resolve(undefined);
|
|
185
|
+
});
|
|
186
|
+
picker.show();
|
|
187
|
+
|
|
188
|
+
provider.provideHistoryItemRefs(undefined, cts.token).then(refs => {
|
|
189
|
+
if (cts.token.isCancellationRequested) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const currentFilter = model.historyItemRefFilter;
|
|
193
|
+
const items = this.createRefPickItems(refs ?? [], provider);
|
|
194
|
+
picker.items = items;
|
|
195
|
+
picker.selectedItems = items.filter((item): item is RefPickItem => !QuickPickSeparator.is(item)
|
|
196
|
+
&& (currentFilter ? !!item.refId && currentFilter.includes(item.refId) : item.auto === true));
|
|
197
|
+
|
|
198
|
+
// "Auto" is exclusive: checking it unchecks everything else and vice versa
|
|
199
|
+
let lastSelection: readonly RefPickItem[] = picker.selectedItems;
|
|
200
|
+
picker.onDidChangeSelection(newSelection => {
|
|
201
|
+
const autoNow = newSelection.some(item => item.auto);
|
|
202
|
+
if (autoNow && newSelection.length > 1) {
|
|
203
|
+
const autoBefore = lastSelection.some(item => item.auto);
|
|
204
|
+
picker.selectedItems = autoBefore ? newSelection.filter(item => !item.auto) : newSelection.filter(item => item.auto);
|
|
205
|
+
}
|
|
206
|
+
lastSelection = picker.selectedItems;
|
|
207
|
+
});
|
|
208
|
+
picker.busy = false;
|
|
209
|
+
}, err => {
|
|
210
|
+
if (!cts.token.isCancellationRequested) {
|
|
211
|
+
this.logger.error('Failed to load history item refs', err);
|
|
212
|
+
}
|
|
213
|
+
picker.hide();
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
if (!selection) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
// The selected repository may have changed while the picker was open;
|
|
221
|
+
// the picked refs belong to the old provider and must not be applied
|
|
222
|
+
// to the new one.
|
|
223
|
+
if (model.provider !== provider) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const refIds = selection.filter(item => item.refId !== undefined).map(item => item.refId!);
|
|
227
|
+
const auto = selection.some(item => item.auto) || refIds.length === 0;
|
|
228
|
+
model.setHistoryItemRefFilter(auto ? undefined : refIds);
|
|
229
|
+
} finally {
|
|
230
|
+
picker.dispose();
|
|
231
|
+
cts.dispose();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
protected createRefPickItems(refs: readonly ScmHistoryItemRef[], provider: ScmHistoryProvider): (RefPickItem | QuickPickSeparator)[] {
|
|
236
|
+
const autoRefs = [provider.currentHistoryItemRef, provider.currentHistoryItemRemoteRef, provider.currentHistoryItemBaseRef]
|
|
237
|
+
.filter((ref): ref is ScmHistoryItemRef => !!ref);
|
|
238
|
+
const items: (RefPickItem | QuickPickSeparator)[] = [{
|
|
239
|
+
label: nls.localizeByDefault('Auto'),
|
|
240
|
+
description: autoRefs.map(ref => ref.name).join(', '),
|
|
241
|
+
auto: true
|
|
242
|
+
}];
|
|
243
|
+
|
|
244
|
+
const groups: { label: string; badgeClass: string }[] = [
|
|
245
|
+
{ label: nls.localize('theia/scm/refPickerBranches', 'branches'), badgeClass: 'head' },
|
|
246
|
+
{ label: nls.localize('theia/scm/refPickerRemoteBranches', 'remote branches'), badgeClass: 'remote' },
|
|
247
|
+
{ label: nls.localize('theia/scm/refPickerTags', 'tags'), badgeClass: 'tag' }
|
|
248
|
+
];
|
|
249
|
+
const grouped = new Set<ScmHistoryItemRef>();
|
|
250
|
+
for (const group of groups) {
|
|
251
|
+
const groupRefs = refs.filter(ref => getRefBadgeClass(ref) === group.badgeClass);
|
|
252
|
+
if (groupRefs.length > 0) {
|
|
253
|
+
groupRefs.forEach(ref => grouped.add(ref));
|
|
254
|
+
items.push({ type: 'separator', label: group.label });
|
|
255
|
+
items.push(...groupRefs.map(ref => this.toRefPickItem(ref)));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const remaining = refs.filter(ref => !grouped.has(ref));
|
|
259
|
+
if (remaining.length > 0) {
|
|
260
|
+
items.push({ type: 'separator' });
|
|
261
|
+
items.push(...remaining.map(ref => this.toRefPickItem(ref)));
|
|
262
|
+
}
|
|
263
|
+
return items;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
protected toRefPickItem(ref: ScmHistoryItemRef): RefPickItem {
|
|
267
|
+
return {
|
|
268
|
+
label: ref.name,
|
|
269
|
+
description: ref.description,
|
|
270
|
+
refId: ref.id
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 Safi Seid-Ahmad, K2view and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import {
|
|
19
|
+
buildChangeTreeRows, ChangeTreeFileRow, ChangeTreeRow, filterRefsForBadges, getFileName, getRefBadgePresentation, getRefColorIndex
|
|
20
|
+
} from './scm-history-graph-helpers';
|
|
21
|
+
import { ScmHistoryItemChange, ScmHistoryItemRef, ScmHistoryProvider } from './scm-provider';
|
|
22
|
+
|
|
23
|
+
describe('getRefColorIndex', () => {
|
|
24
|
+
|
|
25
|
+
const mainRef: ScmHistoryItemRef = { id: 'refs/heads/main', name: 'main' };
|
|
26
|
+
const remoteRef: ScmHistoryItemRef = { id: 'refs/remotes/origin/main', name: 'origin/main' };
|
|
27
|
+
const baseRef: ScmHistoryItemRef = { id: 'refs/remotes/origin/develop', name: 'origin/develop' };
|
|
28
|
+
const otherRef: ScmHistoryItemRef = { id: 'refs/heads/feature', name: 'feature' };
|
|
29
|
+
|
|
30
|
+
const provider = {
|
|
31
|
+
currentHistoryItemRef: mainRef,
|
|
32
|
+
currentHistoryItemRemoteRef: remoteRef,
|
|
33
|
+
currentHistoryItemBaseRef: baseRef,
|
|
34
|
+
} as ScmHistoryProvider;
|
|
35
|
+
|
|
36
|
+
it('returns 0 for the current history item ref', () => {
|
|
37
|
+
expect(getRefColorIndex(mainRef, provider)).to.equal(0);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('returns 1 for the current remote ref', () => {
|
|
41
|
+
expect(getRefColorIndex(remoteRef, provider)).to.equal(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('returns 2 for the current base ref', () => {
|
|
45
|
+
expect(getRefColorIndex(baseRef, provider)).to.equal(2);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('returns undefined for any other ref', () => {
|
|
49
|
+
expect(getRefColorIndex(otherRef, provider)).to.be.undefined;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('returns undefined without a provider', () => {
|
|
53
|
+
expect(getRefColorIndex(mainRef, undefined)).to.be.undefined;
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('getRefBadgePresentation', () => {
|
|
58
|
+
|
|
59
|
+
const mainRef: ScmHistoryItemRef = { id: 'refs/heads/main', name: 'main' };
|
|
60
|
+
const remoteRef: ScmHistoryItemRef = { id: 'refs/remotes/origin/main', name: 'origin/main' };
|
|
61
|
+
|
|
62
|
+
const provider = {
|
|
63
|
+
currentHistoryItemRef: mainRef,
|
|
64
|
+
currentHistoryItemRemoteRef: remoteRef,
|
|
65
|
+
} as ScmHistoryProvider;
|
|
66
|
+
|
|
67
|
+
it('prefers the codicon icon transferred from the provider', () => {
|
|
68
|
+
const ref: ScmHistoryItemRef = { ...mainRef, icon: 'codicon codicon-target' };
|
|
69
|
+
expect(getRefBadgePresentation(ref, undefined).iconClass).to.equal('codicon-target');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('falls back to the target icon for the current ref', () => {
|
|
73
|
+
expect(getRefBadgePresentation(mainRef, provider).iconClass).to.equal('codicon-target');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('falls back to category icons for remote, tag, and other local refs', () => {
|
|
77
|
+
expect(getRefBadgePresentation(remoteRef, provider).iconClass).to.equal('codicon-cloud');
|
|
78
|
+
expect(getRefBadgePresentation({ id: 'refs/tags/v1', name: 'v1' }, provider).iconClass).to.equal('codicon-tag');
|
|
79
|
+
expect(getRefBadgePresentation({ id: 'refs/heads/feature', name: 'feature' }, provider).iconClass).to.equal('codicon-git-branch');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('carries the ref color index', () => {
|
|
83
|
+
expect(getRefBadgePresentation(mainRef, provider).colorIndex).to.equal(0);
|
|
84
|
+
expect(getRefBadgePresentation(remoteRef, provider).colorIndex).to.equal(1);
|
|
85
|
+
expect(getRefBadgePresentation({ id: 'refs/heads/feature', name: 'feature' }, provider).colorIndex).to.be.undefined;
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('filterRefsForBadges', () => {
|
|
90
|
+
|
|
91
|
+
const mainRef: ScmHistoryItemRef = { id: 'refs/heads/main', name: 'main' };
|
|
92
|
+
const remoteRef: ScmHistoryItemRef = { id: 'refs/remotes/origin/main', name: 'origin/main' };
|
|
93
|
+
const featureRef: ScmHistoryItemRef = { id: 'refs/heads/feature', name: 'feature' };
|
|
94
|
+
const refs = [mainRef, remoteRef, featureRef];
|
|
95
|
+
|
|
96
|
+
const provider = {
|
|
97
|
+
currentHistoryItemRef: mainRef,
|
|
98
|
+
currentHistoryItemRemoteRef: remoteRef,
|
|
99
|
+
} as ScmHistoryProvider;
|
|
100
|
+
|
|
101
|
+
it("returns all refs in 'all' mode", () => {
|
|
102
|
+
expect(filterRefsForBadges(refs, provider, 'all')).to.deep.equal(refs);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("keeps only the refs used as a filter in 'filter' mode", () => {
|
|
106
|
+
expect(filterRefsForBadges(refs, provider, 'filter')).to.deep.equal([mainRef, remoteRef]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("returns all refs in 'filter' mode when no provider is available", () => {
|
|
110
|
+
expect(filterRefsForBadges(refs, undefined, 'filter')).to.deep.equal(refs);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("keeps only the explicitly picked refs in 'filter' mode with an explicit filter", () => {
|
|
114
|
+
expect(filterRefsForBadges(refs, provider, 'filter', ['refs/heads/feature'])).to.deep.equal([featureRef]);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("ignores an explicit filter in 'all' mode", () => {
|
|
118
|
+
expect(filterRefsForBadges(refs, provider, 'all', ['refs/heads/feature'])).to.deep.equal(refs);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('buildChangeTreeRows', () => {
|
|
123
|
+
|
|
124
|
+
const rootUri = 'file:///repo';
|
|
125
|
+
|
|
126
|
+
function change(path: string): ScmHistoryItemChange {
|
|
127
|
+
return { uri: `${rootUri}/${path}`, modifiedUri: `${rootUri}/${path}` };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Renders the rows as indented lines, so the expectations read like a tree. */
|
|
131
|
+
function describeRows(rows: readonly ChangeTreeRow[]): string[] {
|
|
132
|
+
return rows.map(row => `${' '.repeat(row.depth)}${row.type === 'folder' ? row.label + '/' : getFileName(row.path)}`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
it('keeps files at the root at depth 0', () => {
|
|
136
|
+
const rows = buildChangeTreeRows([change('a.ts'), change('b.ts')], rootUri, new Set());
|
|
137
|
+
expect(describeRows(rows)).to.deep.equal(['a.ts', 'b.ts']);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('groups files under their folder', () => {
|
|
141
|
+
const rows = buildChangeTreeRows([change('src/a.ts'), change('src/b.ts')], rootUri, new Set());
|
|
142
|
+
expect(describeRows(rows)).to.deep.equal(['src/', ' a.ts', ' b.ts']);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('compacts folder chains that hold a single child folder', () => {
|
|
146
|
+
const rows = buildChangeTreeRows([change('src/browser/a.ts')], rootUri, new Set());
|
|
147
|
+
expect(describeRows(rows)).to.deep.equal(['src/browser/', ' a.ts']);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('stops compacting where a folder chain branches', () => {
|
|
151
|
+
const rows = buildChangeTreeRows([change('src/browser/a.ts'), change('src/node/b.ts')], rootUri, new Set());
|
|
152
|
+
expect(describeRows(rows)).to.deep.equal(['src/', ' browser/', ' a.ts', ' node/', ' b.ts']);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('does not compact a folder that also holds files', () => {
|
|
156
|
+
const rows = buildChangeTreeRows([change('src/a.ts'), change('src/browser/b.ts')], rootUri, new Set());
|
|
157
|
+
expect(describeRows(rows)).to.deep.equal(['src/', ' browser/', ' b.ts', ' a.ts']);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('sorts folders before files, each alphabetically', () => {
|
|
161
|
+
const rows = buildChangeTreeRows([change('z.ts'), change('a.ts'), change('src/b.ts')], rootUri, new Set());
|
|
162
|
+
expect(describeRows(rows)).to.deep.equal(['src/', ' b.ts', 'a.ts', 'z.ts']);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('hides the descendants of a collapsed folder', () => {
|
|
166
|
+
const rows = buildChangeTreeRows([change('src/a.ts'), change('b.ts')], rootUri, new Set(['src']));
|
|
167
|
+
expect(describeRows(rows)).to.deep.equal(['src/', 'b.ts']);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('addresses a compacted folder by its full path', () => {
|
|
171
|
+
const rows = buildChangeTreeRows([change('src/browser/a.ts')], rootUri, new Set(['src/browser']));
|
|
172
|
+
expect(describeRows(rows)).to.deep.equal(['src/browser/']);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('carries the original change on each file row', () => {
|
|
176
|
+
const first = change('src/a.ts');
|
|
177
|
+
const rows = buildChangeTreeRows([first], rootUri, new Set());
|
|
178
|
+
expect(rows[1].type).to.equal('file');
|
|
179
|
+
expect((rows[1] as ChangeTreeFileRow).change).to.equal(first);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('keeps the index of the change in the original list, so row keys stay stable', () => {
|
|
183
|
+
const rows = buildChangeTreeRows([change('z.ts'), change('src/a.ts')], rootUri, new Set());
|
|
184
|
+
// Sorted as: src/, src/a.ts (index 1), z.ts (index 0).
|
|
185
|
+
expect(rows.filter(row => row.type === 'file').map(row => (row as ChangeTreeFileRow).index)).to.deep.equal([1, 0]);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('falls back to the full path when the change is outside the repository root', () => {
|
|
189
|
+
const outside: ScmHistoryItemChange = { uri: 'file:///elsewhere/x.ts', modifiedUri: 'file:///elsewhere/x.ts' };
|
|
190
|
+
const rows = buildChangeTreeRows([outside], rootUri, new Set());
|
|
191
|
+
expect(describeRows(rows)).to.deep.equal(['elsewhere/', ' x.ts']);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import { ScmHistoryItemRef, ScmHistoryItemChange } from './scm-provider';
|
|
17
|
+
import { ScmHistoryItemRef, ScmHistoryItemChange, ScmHistoryProvider } from './scm-provider';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Returns the CSS color variable for the given
|
|
20
|
+
* Returns the CSS color variable for the given color index.
|
|
21
21
|
* Uses Theia's `--theia-scmGraph-*` variables, mirroring the VS Code
|
|
22
22
|
* scm graph color scheme:
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* 0 (current ref) → historyItemRefColor
|
|
24
|
+
* 1 (remote ref) → historyItemRemoteRefColor
|
|
25
|
+
* 2 (base ref) → historyItemBaseRefColor
|
|
26
|
+
* 3–7 (default rotation) → foreground1–5
|
|
27
27
|
*/
|
|
28
28
|
export function laneColor(index: number): string {
|
|
29
29
|
switch (index % 8) {
|
|
@@ -83,6 +83,180 @@ export function getRepoRelativePath(uri: string, rootUri: string | undefined): s
|
|
|
83
83
|
return fullPath;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
export interface ChangeTreeRowBase {
|
|
87
|
+
/** Repo-relative path of the row; the expansion key for folders. */
|
|
88
|
+
readonly path: string;
|
|
89
|
+
/** Nesting level, used for indentation. */
|
|
90
|
+
readonly depth: number;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface ChangeTreeFolderRow extends ChangeTreeRowBase {
|
|
94
|
+
readonly type: 'folder';
|
|
95
|
+
/** Segments rendered for this row; a compacted chain shows `browser/model`. */
|
|
96
|
+
readonly label: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface ChangeTreeFileRow extends ChangeTreeRowBase {
|
|
100
|
+
readonly type: 'file';
|
|
101
|
+
readonly change: ScmHistoryItemChange;
|
|
102
|
+
/** Position of the change in the list it came from, so row keys stay stable. */
|
|
103
|
+
readonly index: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type ChangeTreeRow = ChangeTreeFolderRow | ChangeTreeFileRow;
|
|
107
|
+
|
|
108
|
+
interface ChangeTreeFolder {
|
|
109
|
+
readonly folders: Map<string, ChangeTreeFolder>;
|
|
110
|
+
readonly files: { change: ScmHistoryItemChange; index: number; name: string }[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Arranges history item changes into the rows of a file tree: folders before
|
|
115
|
+
* files, each sorted by name, with single-child folder chains compacted into
|
|
116
|
+
* one row (`src/browser`) the way VS Code's SCM tree renders them. Folders
|
|
117
|
+
* listed in `collapsedFolders` (by their full path) hide their descendants.
|
|
118
|
+
*/
|
|
119
|
+
export function buildChangeTreeRows(
|
|
120
|
+
changes: readonly ScmHistoryItemChange[],
|
|
121
|
+
rootUri: string | undefined,
|
|
122
|
+
collapsedFolders: ReadonlySet<string>
|
|
123
|
+
): ChangeTreeRow[] {
|
|
124
|
+
const root: ChangeTreeFolder = { folders: new Map(), files: [] };
|
|
125
|
+
changes.forEach((change, index) => {
|
|
126
|
+
const relativePath = getRepoRelativePath(change.modifiedUri ?? change.originalUri ?? change.uri, rootUri);
|
|
127
|
+
const segments = relativePath.split('/').filter(segment => segment.length > 0);
|
|
128
|
+
const name = segments.pop() ?? relativePath;
|
|
129
|
+
let folder = root;
|
|
130
|
+
for (const segment of segments) {
|
|
131
|
+
let child = folder.folders.get(segment);
|
|
132
|
+
if (!child) {
|
|
133
|
+
child = { folders: new Map(), files: [] };
|
|
134
|
+
folder.folders.set(segment, child);
|
|
135
|
+
}
|
|
136
|
+
folder = child;
|
|
137
|
+
}
|
|
138
|
+
folder.files.push({ change, index, name });
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const rows: ChangeTreeRow[] = [];
|
|
142
|
+
collectChangeTreeRows(root, '', '', 0, collapsedFolders, rows);
|
|
143
|
+
return rows;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function collectChangeTreeRows(
|
|
147
|
+
folder: ChangeTreeFolder,
|
|
148
|
+
path: string,
|
|
149
|
+
label: string,
|
|
150
|
+
depth: number,
|
|
151
|
+
collapsedFolders: ReadonlySet<string>,
|
|
152
|
+
rows: ChangeTreeRow[]
|
|
153
|
+
): void {
|
|
154
|
+
for (const name of [...folder.folders.keys()].sort(compareNames)) {
|
|
155
|
+
let child = folder.folders.get(name)!;
|
|
156
|
+
let childPath = path ? `${path}/${name}` : name;
|
|
157
|
+
let childLabel = label ? `${label}/${name}` : name;
|
|
158
|
+
// Compact a chain of folders that each hold nothing but one folder.
|
|
159
|
+
while (child.files.length === 0 && child.folders.size === 1) {
|
|
160
|
+
const [onlyName, onlyChild] = [...child.folders][0];
|
|
161
|
+
child = onlyChild;
|
|
162
|
+
childPath = `${childPath}/${onlyName}`;
|
|
163
|
+
childLabel = `${childLabel}/${onlyName}`;
|
|
164
|
+
}
|
|
165
|
+
rows.push({ type: 'folder', path: childPath, label: childLabel, depth });
|
|
166
|
+
if (!collapsedFolders.has(childPath)) {
|
|
167
|
+
collectChangeTreeRows(child, childPath, '', depth + 1, collapsedFolders, rows);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const file of [...folder.files].sort((left, right) => compareNames(left.name, right.name))) {
|
|
171
|
+
rows.push({
|
|
172
|
+
type: 'file',
|
|
173
|
+
path: path ? `${path}/${file.name}` : file.name,
|
|
174
|
+
depth,
|
|
175
|
+
change: file.change,
|
|
176
|
+
index: file.index
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function compareNames(left: string, right: string): number {
|
|
182
|
+
return left.localeCompare(right);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Returns the ref-based color index of the given ref (0 = current ref,
|
|
187
|
+
* 1 = remote ref, 2 = base ref), or `undefined` when the ref is none of
|
|
188
|
+
* the provider's current history item refs. Mirrors VS Code's scm graph
|
|
189
|
+
* color map.
|
|
190
|
+
*/
|
|
191
|
+
export function getRefColorIndex(ref: ScmHistoryItemRef, provider: ScmHistoryProvider | undefined): number | undefined {
|
|
192
|
+
if (!provider) {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
if (ref.id === provider.currentHistoryItemRef?.id) {
|
|
196
|
+
return 0;
|
|
197
|
+
}
|
|
198
|
+
if (ref.id === provider.currentHistoryItemRemoteRef?.id) {
|
|
199
|
+
return 1;
|
|
200
|
+
}
|
|
201
|
+
if (ref.id === provider.currentHistoryItemBaseRef?.id) {
|
|
202
|
+
return 2;
|
|
203
|
+
}
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Filters which refs get badges in the graph, following VS Code's
|
|
209
|
+
* `scm.graph.badges` setting: `'all'` shows every ref, `'filter'` shows only
|
|
210
|
+
* the refs used as the graph's filter — the explicitly picked ref ids, or,
|
|
211
|
+
* without an explicit filter (auto mode), the current, remote, and base refs.
|
|
212
|
+
* Without provider information all refs are kept.
|
|
213
|
+
*/
|
|
214
|
+
export function filterRefsForBadges(
|
|
215
|
+
refs: readonly ScmHistoryItemRef[],
|
|
216
|
+
provider: ScmHistoryProvider | undefined,
|
|
217
|
+
badges: 'all' | 'filter',
|
|
218
|
+
filter?: readonly string[]
|
|
219
|
+
): readonly ScmHistoryItemRef[] {
|
|
220
|
+
if (badges === 'all') {
|
|
221
|
+
return refs;
|
|
222
|
+
}
|
|
223
|
+
if (filter) {
|
|
224
|
+
return refs.filter(ref => filter.includes(ref.id));
|
|
225
|
+
}
|
|
226
|
+
if (!provider) {
|
|
227
|
+
return refs;
|
|
228
|
+
}
|
|
229
|
+
return refs.filter(ref => getRefColorIndex(ref, provider) !== undefined);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface RefBadgePresentation {
|
|
233
|
+
/** Icon class for the badge icon, e.g. 'codicon-git-branch'. */
|
|
234
|
+
iconClass: string;
|
|
235
|
+
/** Ref-based color index (0-2), or `undefined` to use the row color. */
|
|
236
|
+
colorIndex?: number;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Resolves how a ref badge is presented: the provider-supplied codicon icon
|
|
241
|
+
* when available (VS Code renders `ref.icon` unconditionally), otherwise a
|
|
242
|
+
* category fallback with the `target` icon marking the current ref; plus the
|
|
243
|
+
* ref-based color index.
|
|
244
|
+
*/
|
|
245
|
+
export function getRefBadgePresentation(ref: ScmHistoryItemRef, provider: ScmHistoryProvider | undefined): RefBadgePresentation {
|
|
246
|
+
const colorIndex = getRefColorIndex(ref, provider);
|
|
247
|
+
let iconClass: string;
|
|
248
|
+
if (ref.icon && ref.icon.startsWith('codicon ')) {
|
|
249
|
+
iconClass = ref.icon.substring('codicon '.length);
|
|
250
|
+
} else if (isTagRef(ref)) {
|
|
251
|
+
iconClass = 'codicon-tag';
|
|
252
|
+
} else if (isRemoteRef(ref)) {
|
|
253
|
+
iconClass = 'codicon-cloud';
|
|
254
|
+
} else {
|
|
255
|
+
iconClass = colorIndex === 0 ? 'codicon-target' : 'codicon-git-branch';
|
|
256
|
+
}
|
|
257
|
+
return { iconClass, colorIndex };
|
|
258
|
+
}
|
|
259
|
+
|
|
86
260
|
export function getRefBadgeClass(ref: ScmHistoryItemRef): string {
|
|
87
261
|
const cat = (ref.category ?? '').toLowerCase();
|
|
88
262
|
if (cat === 'heads' || cat === 'head' || ref.id.startsWith('refs/heads/')) {
|