Skip to content

Commit 69ae30c

Browse files
committed
Remove whole logic related to x / ! / ? merge symbols and add decorator N
1 parent ee4b43e commit 69ae30c

8 files changed

Lines changed: 98 additions & 54 deletions

src/views/solution-outline/tree-structure/solution-outline-file-item.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,13 @@ describe('FileItem', () => {
9595

9696
// check attributes and merge features for each file node
9797
const fileLabels = ['RTX_Config.c', 'RTX_Config.h'];
98-
const fileStatuses = ['- (X) \'RTX_Config.c\' is incompatible. A file update is mandatory.', '- (?) \'RTX_Config.h\' has corrections. A file update is suggested.'];
99-
const fileDescriptions = ['(X)', '(?)'];
98+
const fileStatuses = ["- 'RTX_Config.c' is incompatible. A file update is mandatory.", "- 'RTX_Config.h' has corrections. A file update is suggested."];
10099
createdChildren.forEach((child, idx) => {
101100
expect(child.getTag()).toBe('file');
102101
expect(child.getAttribute('label')).toContain(fileLabels[idx]);
103102
expect(child.getAttribute('update')).toContain('update');
104103
expect(child.getAttribute('base')).toContain('base');
105-
expect(child.getAttribute('description')).toContain(fileDescriptions[idx]);
104+
expect(child.getAttribute('description')).toBeUndefined();
106105
expect(child.getAttribute('tooltip')).toContain(fileStatuses[idx]);
107106
});
108107

src/views/solution-outline/tree-structure/solution-outline-file-item.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import path from 'path';
1818
import { CTreeItem, ITreeItem } from '../../../generic/tree-item';
1919
import { FILE_TAGS } from '../../../solutions/constants';
2020
import { COutlineItem } from './solution-outline-item';
21-
import { getStatusTooltip, setContextMenuAttributes, setHeaderContext, setMergeDescription, setMergeFileContext } from './solution-outline-utils';
21+
import { getStatusTooltip, setContextMenuAttributes, setHeaderContext, setMergeFileContext } from './solution-outline-utils';
2222
import { matchesContext } from '../../../utils/context-utils';
2323
import { SolutionOutlineItemBuilder } from './solution-outline-item-builder';
2424
import { CSolution } from '../../../solutions/csolution';
@@ -132,9 +132,6 @@ export class FileItemBuilder extends SolutionOutlineItemBuilder {
132132
// assign merge context
133133
setMergeFileContext(cfileItem);
134134

135-
// assign description
136-
setMergeDescription(cfileItem, fileStatus);
137-
138135
// set tooltip
139136
const existingTooltip = cfileItem.getValue('tooltip');
140137
const label = cfileItem.getValue('label');

src/views/solution-outline/tree-structure/solution-outline-hardware-item.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('HardwareItemBuilder', () => {
108108
const wantBase = 'Hello+CS300.dbgconf.base@0.0.1';
109109
expect(gotBase).toEqual(wantBase);
110110

111-
expect(device?.getAttribute('tooltip')).toContain('- (?) \'Hello+CS300.dbgconf\' has corrections. A file update is suggested.');
111+
expect(device?.getAttribute('tooltip')).toContain("- 'Hello+CS300.dbgconf' has corrections. A file update is suggested.");
112112
});
113113

114114
});

src/views/solution-outline/tree-structure/solution-outline-project-items.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { FileItemBuilder } from './solution-outline-file-item';
2121
import { COutlineItem } from './solution-outline-item';
2222
import * as manifest from '../../../manifest';
2323
import { CSolution } from '../../../solutions/csolution';
24-
import { getMapFilePath, getStatusTooltip, setDocContext, setHeaderContext, setLinkerContext, setMergeDescription, setMergeUpdate } from './solution-outline-utils';
24+
import { getMapFilePath, getStatusTooltip, setDocContext, setHeaderContext, setLinkerContext } from './solution-outline-utils';
2525
import { CProjectYamlFile } from '../../../solutions/files/cproject-yaml-file';
2626
import { SolutionOutlineItemBuilder } from './solution-outline-item-builder';
2727

@@ -227,18 +227,14 @@ export class ProjectItemsBuilder extends SolutionOutlineItemBuilder {
227227
const components = Array.from(componentNodes.values());
228228
const fileStatus = this.getMergeDescriptionAtParentComponentLevel(components);
229229
if (fileStatus) {
230-
// assign description
231-
setMergeDescription(componentsItem, fileStatus);
232-
233230
// assign tooltip with component ids
234231
const prioritizedList = this._lastPrioritizedComponentList;
235232
let newTooltip = 'Components with updated configuration files:';
236233
for (const comp of prioritizedList) {
237234
const compId = comp.getAttribute('label');
238235
const compStatus = comp.getAttribute('status');
239236
if (compId && compStatus) {
240-
const update = comp.getAttribute('update');
241-
newTooltip += `\n- ${update} ${compId}: ${compStatus}`;
237+
newTooltip += `\n- ${compId}: ${compStatus}`;
242238
}
243239
}
244240
componentsItem.setAttribute('tooltip', newTooltip);
@@ -438,12 +434,6 @@ export class ProjectItemsBuilder extends SolutionOutlineItemBuilder {
438434
// set status at component level
439435
node.setAttribute('status', fileStatus);
440436

441-
// assign description
442-
setMergeDescription(node, fileStatus);
443-
444-
// assign status symbol for merge update action
445-
setMergeUpdate(node, fileStatus);
446-
447437
// set tooltip
448438
const prevTooltip = node.getValue('tooltip');
449439
let newTooltip: string = '';

src/views/solution-outline/tree-structure/solution-outline-tree.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import * as manifest from '../../../manifest';
2323
import { HardwareItemBuilder } from './solution-outline-hardware-item';
2424
import { ProjectItemsBuilder } from './solution-outline-project-items';
2525
import { getFileNameNoExt } from '../../../utils/path-utils';
26-
import { setMergeDescription } from './solution-outline-utils';
2726
import { CProjectYamlFile } from '../../../solutions/files/cproject-yaml-file';
2827
import { SolutionOutlineItemBuilder } from './solution-outline-item-builder';
2928

@@ -128,12 +127,9 @@ export class SolutionOutlineTree extends SolutionOutlineItemBuilder {
128127
if (prioritizedList && prioritizedList.length > 0) {
129128
const fileStatus = prioritizedList[0].getAttribute('status');
130129
if (fileStatus) {
131-
setMergeDescription(cprojectItem, fileStatus);
132-
133130
// set tooltip
134131
const existingTooltip = cprojectItem.getAttribute('tooltip');
135-
const description = cprojectItem.getAttribute('description');
136-
const newTooltip = `- ${description} Component config files: ${fileStatus}`;
132+
const newTooltip = `- Component config files: ${fileStatus}`;
137133

138134
if (existingTooltip) {
139135
cprojectItem.setAttribute('tooltip', existingTooltip + '\n' + newTooltip);

src/views/solution-outline/tree-structure/solution-outline-utils.ts

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ export function setMergeFiles(component: COutlineItem, file: ITreeItem<CTreeItem
5555
export function getStatusTooltip(label: string, status: string): string | undefined {
5656
switch (status) {
5757
case 'update suggested':
58-
return `- (?) '${label}' has corrections. A file update is suggested.`;
58+
return `- '${label}' has corrections. A file update is suggested.`;
5959
case 'update recommended':
60-
return `- (!) '${label}' has new features. A file update is recommended.`;
60+
return `- '${label}' has new features. A file update is recommended.`;
6161
case 'update required':
62-
return `- (X) '${label}' is incompatible. A file update is mandatory.`;
62+
return `- '${label}' is incompatible. A file update is mandatory.`;
6363
default:
6464
return undefined;
6565
}
@@ -83,20 +83,6 @@ export function getMapFilePath(cbuild: CTreeItem): string | undefined {
8383
return mapFile ? path.join(outDirPath, mapFile) : findFirstMapFile(outDirPath);
8484
}
8585

86-
export function setMergeDescription(node: COutlineItem, fileStatus: string): void {
87-
const desc = getMergeStatusSymbol(fileStatus);
88-
if (desc !== undefined) {
89-
node.setAttribute('description', desc);
90-
}
91-
}
92-
93-
export function setMergeUpdate(node: COutlineItem, fileStatus: string): void {
94-
const update = getMergeStatusSymbol(fileStatus);
95-
if (update !== undefined) {
96-
node.setAttribute('update', update);
97-
}
98-
}
99-
10086
function getOutdirPath(cbuild: CTreeItem): string | undefined {
10187
const outputDirs = cbuild.getChild('output-dirs');
10288
const outdir = outputDirs?.getValue('outdir');
@@ -128,15 +114,3 @@ function findFirstMapFile(dirPath: string): string | undefined {
128114
return undefined;
129115
}
130116

131-
function getMergeStatusSymbol(fileStatus: string): string | undefined {
132-
switch (fileStatus) {
133-
case 'update required':
134-
return '(X)';
135-
case 'update recommended':
136-
return '(!)';
137-
case 'update suggested':
138-
return '(?)';
139-
default:
140-
return undefined;
141-
}
142-
}

src/views/solution-outline/treeview-decoration-provider.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,77 @@ describe('provideFileDecoration', () => {
182182

183183
expect(refreshSpy).toHaveBeenCalled();
184184
});
185+
186+
it('should return merge decoration for files with merge feature', () => {
187+
const filePath = path.join('src', 'merge', 'file.c');
188+
const uri = URI.file(filePath);
189+
190+
const root = new COutlineItem('root');
191+
const project = root.createChild('project');
192+
const group = project.createChild('group');
193+
const file = group.createChild('file');
194+
file.setTag('file');
195+
file.setAttribute('resourcePath', uri.fsPath);
196+
file.addFeature('mergeFile:');
197+
198+
treeViewDecorationProvider.setTreeRoot(root);
199+
200+
const result = treeViewDecorationProvider.provideFileDecoration(uri);
201+
202+
expect(result).toEqual({
203+
badge: TreeViewFileDecorationProvider.mergeBadge,
204+
tooltip: TreeViewFileDecorationProvider.mergeTooltip,
205+
color: { id: TreeViewFileDecorationProvider.mergeColor },
206+
});
207+
});
208+
209+
it('should prioritize excluded decoration over merge decoration', () => {
210+
const filePath = path.join('src', 'merge', 'excluded.c');
211+
const uri = URI.file(filePath);
212+
213+
const root = new COutlineItem('root');
214+
const project = root.createChild('project');
215+
const group = project.createChild('group');
216+
const file = group.createChild('file');
217+
file.setTag('file');
218+
file.setAttribute('resourcePath', uri.fsPath);
219+
file.addFeature('mergeFile:');
220+
file.setAttribute('excluded', '1');
221+
222+
treeViewDecorationProvider.setTreeRoot(root);
223+
224+
const result = treeViewDecorationProvider.provideFileDecoration(uri);
225+
226+
expect(result).toEqual({
227+
badge: TreeViewFileDecorationProvider.excludedBadge,
228+
tooltip: TreeViewFileDecorationProvider.excludedTooltip,
229+
color: { id: TreeViewFileDecorationProvider.excludedColor },
230+
});
231+
});
232+
233+
it('should prioritize merge decoration over pack-sourced decoration', () => {
234+
const packCachePath = 'MOCKED_CMSIS_PACK_ROOT';
235+
jest.spyOn(path_utils, 'getCmsisPackRoot').mockReturnValue(packCachePath);
236+
237+
const filePath = path.join(packCachePath, 'root', 'merge.c');
238+
const uri = URI.file(filePath);
239+
240+
const root = new COutlineItem('root');
241+
const project = root.createChild('project');
242+
const group = project.createChild('group');
243+
const file = group.createChild('file');
244+
file.setTag('file');
245+
file.setAttribute('resourcePath', uri.fsPath);
246+
file.addFeature('mergeFile:');
247+
248+
treeViewDecorationProvider.setTreeRoot(root);
249+
250+
const result = treeViewDecorationProvider.provideFileDecoration(uri);
251+
252+
expect(result).toEqual({
253+
badge: TreeViewFileDecorationProvider.mergeBadge,
254+
tooltip: TreeViewFileDecorationProvider.mergeTooltip,
255+
color: { id: TreeViewFileDecorationProvider.mergeColor },
256+
});
257+
});
185258
});

src/views/solution-outline/treeview-decoration-provider.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ import { ThemeProvider } from '../../vscode-api/theme-provider';
2020
import { URI } from 'vscode-uri';
2121
import { getCmsisPackRoot } from '../../utils/path-utils';
2222
import { COutlineItem } from './tree-structure/solution-outline-item';
23+
import * as manifest from '../../manifest';
2324

2425
export class TreeViewFileDecorationProvider implements vscode.FileDecorationProvider {
2526
static readonly badge: string = 'P';
2627
static readonly tooltip: string = 'Pack sourced';
2728
static readonly themeColor: string = 'descriptionForeground';
2829

30+
static readonly mergeBadge: string = 'N';
31+
static readonly mergeTooltip: string = 'Merge update available';
32+
static readonly mergeColor: string = 'charts.green';
33+
2934
static readonly excludedBadge: string = 'X';
3035
static readonly excludedTooltip: string = 'Excluded from build';
3136
static readonly excludedColor: string = 'errorForeground';
@@ -60,6 +65,16 @@ export class TreeViewFileDecorationProvider implements vscode.FileDecorationProv
6065
};
6166
}
6267

68+
// Merge-enabled files have higher priority than pack-sourced files
69+
const features = fileItem?.getFeatures().split(';') ?? [];
70+
if (features.includes(manifest.MERGE_FILE_CONTEXT)) {
71+
return {
72+
badge: TreeViewFileDecorationProvider.mergeBadge,
73+
tooltip: TreeViewFileDecorationProvider.mergeTooltip,
74+
color: this.themeProvider.getThemeColor(TreeViewFileDecorationProvider.mergeColor),
75+
};
76+
}
77+
6378
// Check for pack-sourced files
6479
const cmsisPackRoot = getCmsisPackRoot();
6580
const cmsisPackRootUri = URI.file(cmsisPackRoot);

0 commit comments

Comments
 (0)