Skip to content

Commit

Permalink
basic communication between talon and the extension for the tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric Halbronn committed Dec 13, 2023
1 parent 6ecaf87 commit 016e4d8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
18 changes: 17 additions & 1 deletion cursorless-talon/src/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

regex = re.compile(r"\{(\w+):([^}]+)\}")
tutorial_dir = Path(
"/Users/pokey/src/cursorless-vscode/src/test/suite/fixtures/recorded/tutorial/unit-2-basic-coding"
r"C:\work\tools\voicecoding\cursorless_fork\packages\cursorless-vscode-e2e\src\suite\fixtures\recorded\tutorial\unit-2-basic-coding"
)


Expand All @@ -29,8 +29,24 @@ def process_scope_type(argument: str):


def process_cursorless_command_step(argument: str):
print(f"{argument=}")
step_fixture = yaml.safe_load((tutorial_dir / argument).read_text())
print(f"{step_fixture['command']=}")
result = actions.user.private_cursorless_run_rpc_command_get(
"cursorless.tutorial.create",
{
"version": 0,
"stepFixture": step_fixture,
},
)
print(f"{result=}")
return f"<cmd@{cursorless_command_to_spoken_form(step_fixture['command'])}/>"
# return f"<cmd@{result}/>"


# TODO get this information from the extension
def cursorless_command_to_spoken_form(command: dict[str, str]):
return command["spokenForm"]


interpolation_processor_map: dict[str, Callable[[str], str]] = {
Expand Down
35 changes: 35 additions & 0 deletions packages/cursorless-engine/src/core/Tutorial.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// import { readFile, writeFile } from "fs/promises";
// import { parse } from "node-html-parser";
// import produce from "immer";
// import { sortBy } from "lodash";
// import { ide } from "../singletons/ide.singleton";
// import path from "path";
// import { getCursorlessRepoRoot } from "@cursorless/common";

import { Dictionary } from "lodash";

/**
* The argument expected by the tutorial command.
*/
interface TutorialCommandArg {
/**
* The version of the tutorial command.
*/
version: 0;

/**
* A representation of the yaml file
*/
stepFixture: Dictionary<string>;
}

export async function tutorialCreate({
version,
stepFixture,
}: TutorialCommandArg) {
if (version !== 0) {
throw new Error(`Unsupported tutorial api version: ${version}`);
}

return stepFixture;
}
1 change: 1 addition & 0 deletions packages/cursorless-engine/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./testUtil/plainObjectToTarget";
export * from "./core/Cheatsheet";
export * from "./core/Tutorial";
export * from "./testUtil/takeSnapshot";
export * from "./testCaseRecorder/TestCaseRecorder";
export * from "./core/StoredTargets";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ interface NearleyToken {
};

interface NearleyLexer {
reset: (chunk: any, info: any) => void;
reset: (chunk: string, info: any) => void;
next: () => NearleyToken | undefined;
save: () => any;
formatError: (token: any, message: string) => string;
has: (tokenType: any) => boolean;
formatError: (token: never) => string;
has: (tokenType: string) => boolean;
};

interface NearleyRule {
Expand Down
5 changes: 5 additions & 0 deletions packages/cursorless-vscode/src/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TestCaseRecorder,
showCheatsheet,
updateDefaults,
tutorialCreate,
} from "@cursorless/cursorless-engine";
import * as vscode from "vscode";
import { showDocumentation, showQuickPick } from "./commands";
Expand Down Expand Up @@ -88,6 +89,10 @@ export function registerCommands(
["cursorless.keyboard.modal.modeOn"]: keyboardCommands.modal.modeOn,
["cursorless.keyboard.modal.modeOff"]: keyboardCommands.modal.modeOff,
["cursorless.keyboard.modal.modeToggle"]: keyboardCommands.modal.modeToggle,

// Tutorial commands
["cursorless.tutorial.create"]: tutorialCreate,
// ["cursorless.tutorial.create"]: tutorialCommands.create,
};

extensionContext.subscriptions.push(
Expand Down

0 comments on commit 016e4d8

Please sign in to comment.