Skip to content

Commit

Permalink
feat(tree-view): add icon support
Browse files Browse the repository at this point in the history
Icons can be defined for events shown in the tree-view.
The icon parameter can use any string from the vscode codicon icon set.
  • Loading branch information
mbehr1 committed Dec 28, 2020
1 parent a4b0696 commit 5149b4d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ This Visual Studio Code(tm) extension adds **analysis** and **visualization** fe

- Configurable **event tree-view** (todo picture):
- Helps quickly to understand the structure or to highlight events (errors/warnings,...).
- Icons can be added to the tree-view.
- Quickly jump to the event by selecting the item in the tree-view.
- Open a text document with the full set of events or the selected event and its leaves.
- Compare two tree events quickly (select/click one tree event and then click on the diff icon on the 2nd event)

![Icons in tree-view](https://github.com/mbehr1/smart-log/raw/master/images/smart-log_tree-view_1.png)

- Configurable **decorations** (todo picture).
- **Time sync** feature (todo movie...):
- Detects time for each line.
Expand Down
Binary file added images/smart-log_tree-view_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
"type": "string",
"description": "Identifier of the decoration to use. Defaults to none."
},
"icon": {
"type": "string",
"description": "Optional name of a codicon icon. E.g. warning or bug. See https://microsoft.github.io/vscode-codicons/dist/codicon.html for a full list."
},
"timeSyncId": {
"type": "string",
"description": "Optional identifier of a 'time sync event'. This gets broadcasted to other documents with the time and the last regex capture in lower case as value."
Expand Down Expand Up @@ -179,7 +183,8 @@
"level": 2,
"label": "{2} {1}",
"decorationId": "warning",
"regex": "^\\S+ \\S+ \\S+ \\[[^\\]]+\\] \"([A-Z]+ [^ \"]+? HTTP/[0-9.]+)\" (4[0-9]{2}) "
"regex": "^\\S+ \\S+ \\S+ \\[[^\\]]+\\] \"([A-Z]+ [^ \"]+? HTTP/[0-9.]+)\" (4[0-9]{2}) ",
"icon": "warning"
}
]
},
Expand Down
11 changes: 6 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface EventNode {
parent: EventNode | null;
children: EventNode[];
contextValue?: string;
icon?: vscode.ThemeIcon;
};

interface DataPerDocument {
Expand Down Expand Up @@ -741,12 +742,12 @@ export default class SmartLogs implements vscode.TreeDataProvider<EventNode>, vs

const events: any | undefined = identifiedFileConfig.events;
// create the RegExps here to have them compiled and not created line by line
let rEvents = new Array<{ regex: RegExp, label: string, level: number, decorationId?: string, timeSyncId?: string, timeSyncPrio?: number }>();
let rEvents = new Array<{ regex: RegExp, label: string, level: number, decorationId?: string, timeSyncId?: string, timeSyncPrio?: number, icon?: vscode.ThemeIcon }>();
if (events) {
for (let i = 0; i < events.length; ++i) {
const event: any | undefined = events[i];
if (event.regex) { // level, label and decorationId are optional
rEvents.push({ regex: new RegExp(event.regex), label: event.label, level: event.level ? event.level : 0, decorationId: event.decorationId, timeSyncId: event.timeSyncId, timeSyncPrio: event.timeSyncPrio });
if (event.regex) { // level, label, icon and decorationId are optional
rEvents.push({ regex: new RegExp(event.regex), label: event.label, level: event.level ? event.level : 0, decorationId: event.decorationId, timeSyncId: event.timeSyncId, timeSyncPrio: event.timeSyncPrio, icon: event.icon ? new vscode.ThemeIcon(event.icon) : undefined });
}
}
}
Expand Down Expand Up @@ -791,7 +792,7 @@ export default class SmartLogs implements vscode.TreeDataProvider<EventNode>, vs
let label: string = ev.label ? util.stringFormat(ev.label, match) : `${match[0]}`;
if (ev.level > 0) {
const parentNode = getParent(ev.level);
parentNode.children.push({ id: util.createUniqueId(), label: label, uri: doc.uri.with({ fragment: `${line.lineNumber}` }), parent: parentNode, children: [] });
parentNode.children.push({ id: util.createUniqueId(), label: label, uri: doc.uri.with({ fragment: `${line.lineNumber}` }), parent: parentNode, children: [], icon: ev.icon });
}
if (ev.decorationId) {
if (this._decorationTypes.has(ev.decorationId)) {
Expand Down Expand Up @@ -888,7 +889,7 @@ export default class SmartLogs implements vscode.TreeDataProvider<EventNode>, vs
label: element.label.length ? element.label : "<no events>",
collapsibleState: element.children.length ? vscode.TreeItemCollapsibleState.Collapsed : void 0,
contextValue: element.contextValue,
iconPath: /* (element.children.length === 0 && element.label.startsWith("xy")) ? path.join(__filename, '..', '..', 'media', 'root-folder.svg') : */ undefined // todo!
iconPath: element.icon
};
}

Expand Down

0 comments on commit 5149b4d

Please sign in to comment.