Skip to content

Commit 5eeb977

Browse files
committed
feat: enhance LogItem with dynamic icon assignment based on report content
1 parent 1a01324 commit 5eeb977

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/logViewer.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,13 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
251251
}
252252
} else if (fs.lstatSync(filePath).isFile()) {
253253
const title = this.parseReportTitle(filePath);
254-
items.push(new LogItem(title, vscode.TreeItemCollapsibleState.None, {
254+
const logFile = new LogItem(title, vscode.TreeItemCollapsibleState.None, {
255255
command: 'magento-log-viewer.openFile',
256256
title: 'Open Log File',
257257
arguments: [filePath]
258-
}));
258+
});
259+
logFile.iconPath = this.getIconForReport(filePath);
260+
items.push(logFile);
259261
}
260262
});
261263

@@ -268,7 +270,9 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
268270
const report = JSON.parse(fileContent);
269271

270272
if (filePath.includes('/api/')) {
271-
return report;
273+
const folderName = path.basename(path.dirname(filePath));
274+
const capitalizedFolderName = folderName.charAt(0).toUpperCase() + folderName.slice(1);
275+
return `${capitalizedFolderName}: ${report}`;
272276
}
273277

274278
return report['0'] || path.basename(filePath);
@@ -277,6 +281,25 @@ export class ReportViewerProvider implements vscode.TreeDataProvider<LogItem>, v
277281
}
278282
}
279283

284+
private getIconForReport(filePath: string): vscode.ThemeIcon {
285+
try {
286+
const fileContent = fs.readFileSync(filePath, 'utf-8');
287+
const report = JSON.parse(fileContent);
288+
289+
if (filePath.includes('/api/')) {
290+
return new vscode.ThemeIcon('warning');
291+
}
292+
293+
if (report['0'] && report['0'].toLowerCase().includes('error')) {
294+
return new vscode.ThemeIcon('error');
295+
}
296+
297+
return new vscode.ThemeIcon('file');
298+
} catch (error) {
299+
return new vscode.ThemeIcon('file');
300+
}
301+
}
302+
280303
getLogFilesWithoutUpdatingBadge(dir: string): LogItem[] {
281304
if (pathExists(dir)) {
282305
const files = fs.readdirSync(dir);
@@ -307,15 +330,14 @@ export class LogItem extends vscode.TreeItem {
307330
public readonly label: string,
308331
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
309332
public readonly command?: vscode.Command,
310-
public children?: LogItem[]
333+
public children?: LogItem[],
334+
public iconPath?: vscode.ThemeIcon
311335
) {
312336
super(label, collapsibleState as vscode.TreeItemCollapsibleState);
313337
this.description = this.label.match(/\(\d+\)/)?.[0] || '';
314338
this.label = this.label.replace(/\(\d+\)/, '').trim();
315339
}
316340

317-
iconPath = new vscode.ThemeIcon('list');
318-
319341
contextValue = 'logItem';
320342
description = '';
321343
}

0 commit comments

Comments
 (0)