Mind_Reader/src/commandNodeProvider.ts
Jake Grossman b3984daad5
Hub communication (#12)
* Add persistent accessibility pane

This will facilitate more extensive usage of the menu than the
context menu.

* Fixed missing files

* Add missing semicolon

* Implement HubController

* Parse messages on arrival

Rather than queuing inbound messages, the HubController now saves
pending promises/rejects for each pending request. Each inbound packet
is checked at the time of arrival, and if the ID matches a pending
response, the corresponding promise is called.

This fixes a problem where the longer the time between reads, the more
garbage responses queue up that are guaranteed to get thrown away the
next time the next response was gathered.

* Add clarification comment to send

* Add logger, output

* Use stat+stream instead of reading entire file on upload

* Split MindReader view into accessability and hub sub-views

* Add missing comma from conflict resolution

* Fix issues, split commands into sub-lists

* Add rebuild instructions

* More accurate

* Add tools for native modules instructions to README.md

* Move commands to correct spot

* Remove automatic connection

I did not heed the warning where 'only the path is guaranteed' when
listing open serial ports and made the assumption that the manufacturer
would be known (hint: it wasn't).

* Use device specific language for output title
2021-12-01 21:40:01 -06:00

44 lines
1.2 KiB
TypeScript

import * as vscode from 'vscode';
import { CommandEntry } from './commands';
export class CommandItem extends vscode.TreeItem {
constructor(
public readonly label: string,
public readonly command: vscode.Command
) {
super(label, vscode.TreeItemCollapsibleState.None);
}
};
export default class CommandNodeProvider implements vscode.TreeDataProvider<CommandItem> {
private items: CommandItem[] = [];
public constructor(commands: CommandEntry[]) {
// build and cache command items
for (const c of commands) {
let humanReadable = c.name.replace(/^mind-reader\./, ''); // strip extensions name
// Convert camelCaseText to Title Case Text
humanReadable = humanReadable.replace(/([A-Z])/g, ' $1');
humanReadable = humanReadable.charAt(0).toUpperCase() + humanReadable.slice(1);
this.items.push(new CommandItem(
humanReadable,
{
title: humanReadable,
command: c.name,
tooltip: humanReadable
}
));
}
}
public getTreeItem(item: CommandItem): vscode.TreeItem {
return item;
}
public async getChildren(): Promise<CommandItem[]> {
return Promise.resolve(this.items);
}
}