Skip to content

Commit 4b5b1b0

Browse files
authored
Merge branch 'main' into refactor/184refactor/184
2 parents 6bdf49f + c7b53e4 commit 4b5b1b0

2 files changed

Lines changed: 51 additions & 16 deletions

File tree

src/solutions/solution-problems.test.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ describe('SolutionProblems', () => {
245245
logMessages: {
246246
success: true,
247247
errors: [],
248-
warnings: ["mylayer.clayer.yml - file '/packs/Component/config.c' update required from component 'Arm::Device@2.3.4'"],
248+
warnings: ["mylayer.clayer.yml - update required for file '/packs/Component/config.c' from component 'Arm::Device@2.3.4'"],
249249
info: [],
250250
},
251251
});
@@ -272,7 +272,7 @@ describe('SolutionProblems', () => {
272272

273273
it('creates merge diagnostic action for merge messages with component context', () => {
274274
const result = solutionProblems['createMergeDiagnosticAction'](
275-
"file '/packs/Component/config.c' update required from component 'Arm::Device@2.3.4'",
275+
"update required for file '/packs/Component/config.c' from component 'Arm::Device@2.3.4'",
276276
layerPath,
277277
);
278278

@@ -285,6 +285,27 @@ describe('SolutionProblems', () => {
285285
});
286286
});
287287

288+
it('creates merge diagnostic action for current toolbox message wording', () => {
289+
const configPath = 'C:/CubeMX/CubeMX/RTE/CMSIS/RTX_Config.c';
290+
const result = solutionProblems['createMergeDiagnosticAction'](
291+
`update recommended for file '${configPath}' from component 'CMSIS:RTOS2:Keil RTX5&Source'.\nMerge content from update file, rename update file to base file and remove previous base file`,
292+
layerPath,
293+
);
294+
295+
expect(result).toEqual({
296+
message: "update recommended for config file 'RTX_Config.c' from component 'CMSIS:RTOS2:Keil RTX5&Source'.",
297+
code: {
298+
value: 'Open in Merge View',
299+
target: vscode.Uri.parse(`command:${MERGE_FILE_COMMAND_ID}?${encodeURIComponent(JSON.stringify([configPath]))}`),
300+
},
301+
});
302+
});
303+
304+
it('treats Windows-style merge paths as absolute', () => {
305+
expect(solutionProblems['isAbsoluteFilePath']('C:/CubeMX/CubeMX/RTE/CMSIS/RTX_Config.c')).toBe(true);
306+
expect(solutionProblems['isAbsoluteFilePath']('relative-config.c')).toBe(false);
307+
});
308+
288309
it('returns undefined merge diagnostic action for non-merge messages', () => {
289310
const result = solutionProblems['createMergeDiagnosticAction'](
290311
"component 'Arm::Device@2.3.4' is missing",
@@ -304,7 +325,7 @@ describe('SolutionProblems', () => {
304325
logMessages: {
305326
success: true,
306327
errors: [],
307-
warnings: ["mylayer.clayer.yml - file 'relative-config.c' update recommended"],
328+
warnings: ["mylayer.clayer.yml - update recommended for file 'relative-config.c'"],
308329
info: [],
309330
},
310331
});
@@ -323,7 +344,7 @@ describe('SolutionProblems', () => {
323344
});
324345

325346
it.each(['required', 'recommended', 'suggested', 'mandatory'] as const)(
326-
'renders merge diagnostics for %s update levels',
347+
'renders merge diagnostics for current toolbox wording with %s update levels',
327348
async updateLevel => {
328349
await solutionProblems.activate({ subscriptions: [] } as unknown as ExtensionContext);
329350
const setSpy = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'set');
@@ -334,7 +355,7 @@ describe('SolutionProblems', () => {
334355
logMessages: {
335356
success: true,
336357
errors: [],
337-
warnings: [`mylayer.clayer.yml - file '/packs/Component/${updateLevel}.c' update ${updateLevel}`],
358+
warnings: [`mylayer.clayer.yml - update ${updateLevel} for file '/packs/Component/${updateLevel}.c'; merge content from update file, rename update file to base file and remove previous base file`],
338359
info: [],
339360
},
340361
});

src/solutions/solution-problems.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ export const enrichLogMessagesFromToolOutput = async (logMessages: LogMessages,
103103

104104
export const MERGE_VIEW_LINK_LABEL = 'Open in Merge View';
105105
export type MergeUpdateLevel = 'required' | 'recommended' | 'suggested' | 'mandatory';
106-
const mergeMessageRegex = /file\s+'([^']+)'\s+update\s+(required|recommended|suggested|mandatory)/i;
106+
const mergeMessagePatterns = [
107+
{
108+
pattern: /update\s+(required|recommended|suggested|mandatory)\s+for\s+file\s+'([^']+)'/i,
109+
getLocalPath: (match: RegExpExecArray) => match[2],
110+
getUpdateLevel: (match: RegExpExecArray) => match[1],
111+
},
112+
] as const;
107113
const mergeComponentRegex = /(?:for|from)\s+component\s+'([^']+)'/i;
108114
export interface MergeMessageMatch {
109115
localPath: string;
@@ -323,17 +329,21 @@ export class SolutionProblemsImpl implements SolutionProblems {
323329
}
324330

325331
private parseMergeMessage(line: string): MergeMessageMatch | undefined {
326-
const match = mergeMessageRegex.exec(line);
327-
if (!match || match.index === undefined) {
328-
return undefined;
332+
for (const item of mergeMessagePatterns) {
333+
const match = item.pattern.exec(line);
334+
if (!match || match.index === undefined) {
335+
continue;
336+
}
337+
338+
return {
339+
localPath: item.getLocalPath(match),
340+
updateLevel: item.getUpdateLevel(match).toLowerCase() as MergeUpdateLevel,
341+
matchStart: match.index,
342+
matchLength: match[0].length,
343+
};
329344
}
330345

331-
return {
332-
localPath: match[1],
333-
updateLevel: match[2].toLowerCase() as MergeUpdateLevel,
334-
matchStart: match.index,
335-
matchLength: match[0].length,
336-
};
346+
return undefined;
337347
}
338348

339349
private createMergeDiagnosticMessage(localPath: string, updateLevel: MergeUpdateLevel, componentId: string | undefined): string {
@@ -352,14 +362,18 @@ export class SolutionProblemsImpl implements SolutionProblems {
352362
return vscode.Uri.parse(`command:${MERGE_FILE_COMMAND_ID}?${args}`);
353363
}
354364

365+
private isAbsoluteFilePath(filePath: string): boolean {
366+
return path.isAbsolute(filePath) || path.win32.isAbsolute(filePath);
367+
}
368+
355369
private createMergeDiagnosticAction(message: string, diagnosticFilePath: string): { message: string; code: NonNullable<vscode.Diagnostic['code']> } | undefined {
356370
const merge = this.parseMergeMessage(message);
357371
if (!merge) {
358372
return undefined;
359373
}
360374

361375
const componentId = mergeComponentRegex.exec(message)?.[1];
362-
const localPath = path.isAbsolute(merge.localPath) ? merge.localPath : diagnosticFilePath;
376+
const localPath = this.isAbsoluteFilePath(merge.localPath) ? merge.localPath : diagnosticFilePath;
363377
const formattedMessage = this.createMergeDiagnosticMessage(localPath, merge.updateLevel, componentId);
364378

365379
return {

0 commit comments

Comments
 (0)