Skip to content

Commit

Permalink
ORFSTreeViewProvider.ts: Added current task highlighting
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Bylicki <[email protected]>
  • Loading branch information
jbylicki authored and glatosinski committed Jun 17, 2024
1 parent 5e2e536 commit a139d34
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
{
"command": "orfsTasks.refreshEntry",
"title": "Refresh"
},
{
"command": "orfsTasks.clearHighlights",
"title": "Clear Highlights"
}
],
"views": {
Expand Down
2 changes: 1 addition & 1 deletion src/ORFSTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vscode.Task[]> | undefined = undefined;
Expand Down
67 changes: 51 additions & 16 deletions src/ORFSTreeViewProvider.ts
Original file line number Diff line number Diff line change
@@ -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<TaskTreeItem> {
private commands: Promise<vscode.Task[]>;
private _onDidChangeTreeData: vscode.EventEmitter<TaskTreeItem | undefined | null | void> = new vscode.EventEmitter<TaskTreeItem | undefined | null | void>();
readonly onDidChangeTreeData: vscode.Event<TaskTreeItem | undefined | null | void> = 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)=>{
Expand All @@ -39,7 +73,7 @@ export class TaskTreeProvider implements vscode.TreeDataProvider<TaskTreeItem> {
}

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;
}

Expand All @@ -54,15 +88,15 @@ export class TaskTreeProvider implements vscode.TreeDataProvider<TaskTreeItem> {

getChildren(element?: TaskTreeItem): Thenable<TaskTreeItem[]> {
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,
Expand All @@ -73,12 +107,12 @@ export class TaskTreeProvider implements vscode.TreeDataProvider<TaskTreeItem> {
))
});
} 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,
Expand All @@ -91,7 +125,7 @@ export class TaskTreeProvider implements vscode.TreeDataProvider<TaskTreeItem> {
} 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,
Expand All @@ -101,14 +135,14 @@ export class TaskTreeProvider implements vscode.TreeDataProvider<TaskTreeItem> {
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,
Expand All @@ -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
Expand Down

0 comments on commit a139d34

Please sign in to comment.