From 73ba1f74e664a22449143646c9818a8dc4d04dea Mon Sep 17 00:00:00 2001 From: shmck Date: Sat, 1 Aug 2020 21:30:16 -0700 Subject: [PATCH] setup vscode commands Signed-off-by: shmck --- src/services/hooks/index.ts | 4 +++ src/services/hooks/utils/runCommands.ts | 2 +- src/services/hooks/utils/runVSCodeCommands.ts | 26 +++++++++++++++++++ typings/tutorial.d.ts | 3 +++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/services/hooks/utils/runVSCodeCommands.ts diff --git a/src/services/hooks/index.ts b/src/services/hooks/index.ts index 4422cc08..91d58810 100644 --- a/src/services/hooks/index.ts +++ b/src/services/hooks/index.ts @@ -4,12 +4,14 @@ import loadCommits from './utils/loadCommits' import loadWatchers from './utils/loadWatchers' import openFiles from './utils/openFiles' import runCommands from './utils/runCommands' +import runVSCodeCommands from './utils/runVSCodeCommands' import { onError as telemetryOnError } from '../telemetry' import { onRunTest } from '../../actions/onTest' export const onInit = async (actions: TT.StepActions): Promise => { await loadCommits(actions.commits) await runCommands(actions.commands) + await runVSCodeCommands(actions.vscodeCommands) } export const onLevelEnter = async (actions: TT.StepActions): Promise => { @@ -23,6 +25,7 @@ export const onSetupEnter = async (actions: TT.StepActions): Promise => { await openFiles(actions.files) await loadWatchers(actions.watchers) await runCommands(actions.commands) + await runVSCodeCommands(actions.vscodeCommands) } export const onSolutionEnter = async (actions: TT.StepActions): Promise => { @@ -31,6 +34,7 @@ export const onSolutionEnter = async (actions: TT.StepActions): Promise => await loadCommits(actions.commits) await openFiles(actions.files) await runCommands(actions.commands) + await runVSCodeCommands(actions.vscodeCommands) await onRunTest() } diff --git a/src/services/hooks/utils/runCommands.ts b/src/services/hooks/utils/runCommands.ts index 88f60b9b..ed3b871d 100644 --- a/src/services/hooks/utils/runCommands.ts +++ b/src/services/hooks/utils/runCommands.ts @@ -16,7 +16,7 @@ const runCommands = async (commands: string[] = []): Promise => { result = await exec({ command }) console.log(result) } catch (error) { - console.error(`Test failed: ${error.message}`) + console.error(`Command failed: ${error.message}`) send({ type: 'COMMAND_FAIL', payload: { process: { ...process, status: 'FAIL' } } }) return } diff --git a/src/services/hooks/utils/runVSCodeCommands.ts b/src/services/hooks/utils/runVSCodeCommands.ts new file mode 100644 index 00000000..6e4e9b0e --- /dev/null +++ b/src/services/hooks/utils/runVSCodeCommands.ts @@ -0,0 +1,26 @@ +import * as vscode from 'vscode' +import * as TT from 'typings/tutorial' + +// what are VSCode commands? +// - https://code.visualstudio.com/api/references/vscode-api#commands +// a list of commands: +// - https://code.visualstudio.com/api/references/commands (note many take params) +// - https://code.visualstudio.com/docs/getstarted/keybindings (anything keybound is a command) + +const runVSCodeCommands = async (commands: TT.VSCodeCommand[] = []): Promise => { + if (!commands.length) { + return + } + for (const command of commands) { + if (typeof command === 'string') { + // string named commands + await vscode.commands.executeCommand(command) + } else if (Array.isArray(command)) { + // array commands with params + const [name, params] = command + await vscode.commands.executeCommand(name, params) + } + } +} + +export default runVSCodeCommands diff --git a/typings/tutorial.d.ts b/typings/tutorial.d.ts index 12a1e20b..aaa357bb 100644 --- a/typings/tutorial.d.ts +++ b/typings/tutorial.d.ts @@ -61,6 +61,7 @@ export type StepActions = { files?: string[] watchers?: string[] filter?: string + vscodeCommands?: VSCodeCommand[] } export interface TestRunnerArgs { @@ -88,3 +89,5 @@ export interface TutorialDependency { export interface TutorialAppVersions { vscode: string } + +export type VSCodeCommand = string | [string, any]