diff --git a/media/dep.svg b/media/dep.svg new file mode 100644 index 0000000..53e5be5 --- /dev/null +++ b/media/dep.svg @@ -0,0 +1,14 @@ + + + + Slice + Created with Sketch. + + + + + + + + + diff --git a/src/accessNodeProvider.ts b/src/accessNodeProvider.ts new file mode 100644 index 0000000..0f4ae59 --- /dev/null +++ b/src/accessNodeProvider.ts @@ -0,0 +1,47 @@ +import * as vscode from 'vscode'; + +// list of all actions +let actions: AccessAction[] = []; + +class AccessAction extends vscode.TreeItem { + constructor( + public readonly label: string, + public readonly command: vscode.Command + ) { + super(label, vscode.TreeItemCollapsibleState.None) + } +}; + +export default class AccessNodeProvider implements vscode.TreeDataProvider { + public getTreeItem(a: AccessAction): vscode.TreeItem { + return a; + } + + public async getChildren(): Promise { + if (actions.length === 0) { + // fetch and cache mind-reader options + let cmds: string[] = await vscode.commands.getCommands(true); // get non-builtin commands + cmds = cmds.filter(x => x.startsWith('mind-reader')); // filter mind-reader commands + + cmds.forEach(c => { + let humanReadable = c.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); + + // add item to actions + actions.push(new AccessAction( + humanReadable, + { + title: humanReadable, + command: c, + tooltip: humanReadable + } + )); + }); + } + + return Promise.resolve(actions); + } +} diff --git a/src/extension.ts b/src/extension.ts index 167b54b..ffeab0f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; import * as pl from './pylex'; import commands from './commands'; -import { AccessNodeProvider } from './accessNodeProvider' +import AccessNodeProvider from './accessNodeProvider' let parser: pl.Parser = new pl.Parser();