From a139d34db20587be748b0bd0968a6b631884cae9 Mon Sep 17 00:00:00 2001 From: Jan Bylicki Date: Mon, 10 Jun 2024 17:53:17 +0200 Subject: [PATCH] ORFSTreeViewProvider.ts: Added current task highlighting Signed-off-by: Jan Bylicki --- package.json | 4 +++ src/ORFSTaskProvider.ts | 2 +- src/ORFSTreeViewProvider.ts | 67 ++++++++++++++++++++++++++++--------- 3 files changed, 56 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index eec6cab..3b9f3bc 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,10 @@ { "command": "orfsTasks.refreshEntry", "title": "Refresh" + }, + { + "command": "orfsTasks.clearHighlights", + "title": "Clear Highlights" } ], "views": { diff --git a/src/ORFSTaskProvider.ts b/src/ORFSTaskProvider.ts index 57cd1ca..7815d9b 100644 --- a/src/ORFSTaskProvider.ts +++ b/src/ORFSTaskProvider.ts @@ -10,7 +10,7 @@ interface ORFSTaskDefinition extends vscode.TaskDefinition { export class ORFSTaskProvider implements vscode.TaskProvider { private logchannel: vscode.OutputChannel; private config: vscode.WorkspaceConfiguration; - private flowHome: string | undefined; + public flowHome: string | undefined; private configMkPath: string; private designconf: string | undefined; private resultPromise: Thenable | undefined = undefined; diff --git a/src/ORFSTreeViewProvider.ts b/src/ORFSTreeViewProvider.ts index 909813c..fa1f1eb 100644 --- a/src/ORFSTreeViewProvider.ts +++ b/src/ORFSTreeViewProvider.ts @@ -1,22 +1,56 @@ import * as vscode from 'vscode'; import { ORFSTaskProvider } from './ORFSTaskProvider'; import * as path from 'path'; +import { addAbortListener } from 'events'; export class TaskTreeProvider implements vscode.TreeDataProvider { private commands: Promise; private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; + private highlighted_tasks: string[] = []; private static leafItemNames = ["2_floorplan_debug_macros", "6_report", "6_gds", "6_final"]; + //TODO(jbylicki): Make highlight a command + private logWatchPath: string = ""; + private lastUri: string = ""; constructor(private orfsTaskProvider: ORFSTaskProvider) { vscode.commands.registerCommand('orfsTasks.item_clicked', item => this.clicked(item)); vscode.commands.registerCommand('orfsTasks.item_log', item => this.showLog(item)); vscode.commands.registerCommand('orfsTasks.item_clean', item => this.runClean(item)); vscode.commands.registerCommand('orfsTasks.item_gui', item => this.runGUI(item)); + vscode.commands.registerCommand('orfsTasks.clearHighlights', () => + this.clearHighlights() + ); + vscode.tasks.onDidEndTask(()=>vscode.commands.executeCommand("orfsTasks.clearHighlights")); this.commands = Promise.resolve(this.orfsTaskProvider.provideTasks()!.then((tasklist)=>{ + this.logWatchPath = path.join( + this.orfsTaskProvider.flowHome!, + "logs", + this.orfsTaskProvider.platform!, + this.orfsTaskProvider.nickname!, + "base" + ); + + let watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(this.logWatchPath, "**/*.log")); + watcher.onDidChange(uri => this.addHighlight(uri.toString())); + watcher.onDidCreate(uri => this.addHighlight(uri.toString())); return tasklist; })) } + addHighlight(uri: string) { + if (uri === this.lastUri) return; + this.clearHighlights(); + if(!this.highlighted_tasks.includes(path.basename(uri).at(0)!)) { + this.highlighted_tasks.push(path.basename(uri).at(0)!); + this._onDidChangeTreeData.fire(); + this.lastUri = uri; + } + } + clearHighlights() { + this.highlighted_tasks = []; + this.lastUri = ""; + this._onDidChangeTreeData.fire(); + } refresh(): void { this.commands = Promise.resolve(this.orfsTaskProvider.provideTasks()!.then((tasklist)=>{ @@ -39,7 +73,7 @@ export class TaskTreeProvider implements vscode.TreeDataProvider { } getTreeItem(element: TaskTreeItem): vscode.TreeItem { - element.command = {command: 'orfsTasks.item_clicked', title: element.label, arguments: [element]} + element.command = {command: 'orfsTasks.item_clicked', title: element.label.label, arguments: [element]}; return element; } @@ -54,15 +88,15 @@ export class TaskTreeProvider implements vscode.TreeDataProvider { getChildren(element?: TaskTreeItem): Thenable { return Promise.resolve(this.commands.then((tasks)=>{ - const items : TaskTreeItem[] = [] - if (element && element.label === `${this.orfsTaskProvider.platform}/${this.orfsTaskProvider.nickname}`) { // stages + const items : TaskTreeItem[] = []; + if (element && element.label.label === `${this.orfsTaskProvider.platform}/${this.orfsTaskProvider.nickname}`) { // stages tasks.filter((el)=> el.name.match(/^[0-9]_[a-zA-Z].*/) && !TaskTreeProvider.leafItemNames.includes(el.name)).forEach((el)=>{ const stage = el.name.split('_')[1]; const clean_stage = tasks.find((t) => t.name === `clean_${stage}`); const logTask = tasks.find((t) => t.name === `log ${el.name}`); const guiTask = tasks.find((t) => t.name === `gui_${stage}`); items.push(new TaskTreeItem( - el.name, + {label: el.name, highlights: this.highlighted_tasks.some((e) => el.name.startsWith(e)) ? [[0, el.name.length]] : []}, vscode.workspace.name!, (el.name === "1_synth") ? vscode.TreeItemCollapsibleState.None : vscode.TreeItemCollapsibleState.Collapsed, el, @@ -73,12 +107,12 @@ export class TaskTreeProvider implements vscode.TreeDataProvider { )) }); } else if (element) { // leafs - const prefix = element.label.slice(0, 2); // prefix like [0-9]_ - tasks.filter((el) => el.name !== element.label && el.name.startsWith(prefix)).forEach((el)=> { + const prefix = element.label.label.slice(0, 2); // prefix like [0-9]_ + tasks.filter((el) => el.name !== element.label.label && el.name.startsWith(prefix)).forEach((el)=> { const logTask = tasks.find((t) => t.name.startsWith(`log ${el.name}`)); const guiTask = tasks.find((t) => t.name.startsWith(`gui_${el.name}`)); items.push(new TaskTreeItem( - el.name, + {label: el.name, highlights: []}, vscode.workspace.name!, vscode.TreeItemCollapsibleState.None, el, @@ -91,7 +125,7 @@ export class TaskTreeProvider implements vscode.TreeDataProvider { } else { // root const clean_stage = tasks.find((t) => t.name === "clean_all"); items.push(new TaskTreeItem( - `${this.orfsTaskProvider.platform}/${this.orfsTaskProvider.nickname}`, + {label: `${this.orfsTaskProvider.platform}/${this.orfsTaskProvider.nickname}`, highlights: []}, vscode.workspace.name!, vscode.TreeItemCollapsibleState.Expanded, undefined, @@ -101,14 +135,14 @@ export class TaskTreeProvider implements vscode.TreeDataProvider { this.createContextView(undefined, undefined, clean_stage, undefined), )) } - return items.sort((a, b)=>a.label > b.label ? 1 : -1) + return items.sort((a, b)=>a.label.label > b.label.label? 1 : -1) })) } } class TaskTreeItem extends vscode.TreeItem { constructor( - public readonly label: string, + public readonly label: vscode.TreeItemLabel, private version: string, public readonly collapsibleState: vscode.TreeItemCollapsibleState, private task: vscode.Task | undefined, @@ -123,24 +157,25 @@ class TaskTreeItem extends vscode.TreeItem { this.description = this.version; } public run() { - if(this.task) - return vscode.tasks.executeTask(this.task) - return undefined + if(this.task) { + return Promise.resolve(vscode.tasks.executeTask(this.task)) + } + return undefined; } public showLogs() { if(this.logTask) return vscode.tasks.executeTask(this.logTask) - return undefined + return undefined; } public runClean() { if(this.cleanTask) return vscode.tasks.executeTask(this.cleanTask) - return undefined + return undefined; } public runGUI() { if(this.guiTask) return vscode.tasks.executeTask(this.guiTask) - return undefined + return undefined; } //TODO(jbylicki): This was in the manual, but we'll need it at some point