-
-
Notifications
You must be signed in to change notification settings - Fork 88
Cursorless tutorial ced #2131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Cursorless tutorial ced #2131
Changes from 9 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
466fe64
Initial tutorial work
pokey 617ea7c
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] ef66688
Update spoken forms
pokey ae958d3
Upgrade commands
pokey 1b4cae3
Fix extension tests
pokey bb303aa
whoops
pokey 6ecaf87
Merge branch 'main' into cursorless-tutorial
pokey 016e4d8
basic communication between talon and the extension for the tutorial
f761306
initial way to populate a window even if not really the right way
d4b8aa6
use the injected ide
9673f52
remove dependencies unneeded now
8b95e02
moved tutorial to a class
b0e2f8c
Merge remote-tracking branch 'upstream/main' into cursorless-tutorial…
25be0ca
start parsing things from the extension side
a7c7fa2
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 203bdd2
refactor and parse literalStep
1bbfe44
finished converting all the spoken forms
f3a3bf3
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 1436353
document functions and use a tutorial directory
43734e7
initial working version of the tutorial
171abdd
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] cd5bfc6
tweaks
pokey e022e69
change function
pokey e0f3c02
more cleanup
pokey 142ec58
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] 7ed3aac
fix
pokey a5ed0ff
More cleanup
pokey f789d24
More cleanup
pokey f607f16
Tweak imports
pokey 01fc505
More tweaks# Please enter the commit message for your changes. Lines …
pokey af491e9
More cleanup
pokey 06025d4
more tweaks
pokey 55b596d
Remove comment
pokey 6e101de
Bugfixes
pokey 0e1cf6b
More fixes
pokey 179098b
Merge branch 'main' into pr/saidelike/2131
pokey 46be1bd
run meta-updater
pokey 20bd5ed
Initial cursorless-vscode-tutorial scaffolding
pokey ea0481c
cursorless-vscode-tutorial => cursorless-vscode-tutorial-webview
pokey 47fd057
more tutorial hacking
pokey 69bd66b
Tweak package.json
pokey e9d8dbe
Update adding-a-new-package.md (#2247)
pokey 5cbc8e1
bump pnpm => 8.15.3 (#2248)
pokey 6dc5a2d
Update adding-a-new-package.md (#2249)
pokey 5cd2c12
{grand, every} rephrasings for clarity and consistency (#2250)
jmegner ed7ae67
Update adding-a-new-package.md (#2255)
pokey 401cb10
Get actual js from our webview package
pokey d5dddff
Initial React scaffolding
pokey ff3f0cd
Fix tsconfig
pokey 419d830
more cleanup
pokey 571a979
fix:meta
pokey 2f1d786
more cleanup
pokey dce7d96
Merge branch 'main' into pr/saidelike/2131
pokey db75743
Add tailwind
pokey 4d63d67
Let VscodeTutorial own tutorial state
pokey 04c5653
Clean up some TutorialImpl stuff
pokey b59cccb
More PR feedback
pokey ac51e1f
Initial step content and step init code connected to webview
pokey 26a2cd9
tweaks
pokey 1f07077
tweaks
pokey 0dbbfcd
some more tweaks
pokey 32ab372
Merge branch 'main' into pr/saidelike/2131
pokey c9f56b3
more tweaks
pokey e8a66f8
Merge branch 'main' into pr/saidelike/2131
pokey ad8a152
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from talon import registry | ||
|
||
from .actions.actions import ACTION_LIST_NAMES | ||
from .conventions import get_cursorless_list_name | ||
|
||
|
||
def make_cursorless_list_reverse_look_up(*raw_list_names: str): | ||
return make_list_reverse_look_up( | ||
*[get_cursorless_list_name(raw_list_name) for raw_list_name in raw_list_names] | ||
) | ||
|
||
|
||
def make_list_reverse_look_up(*list_names: str): | ||
""" | ||
Given a list of talon list names, returns a function that does a reverse | ||
look-up in all lists to find the spoken form for its input. | ||
""" | ||
|
||
def return_func(argument: str): | ||
for list_name in list_names: | ||
for spoken_form, value in registry.lists[list_name][-1].items(): | ||
if value == argument: | ||
return list_name, spoken_form | ||
|
||
raise LookupError(f"Unknown identifier `{argument}`") | ||
|
||
return return_func | ||
|
||
|
||
lookup_action = make_cursorless_list_reverse_look_up(*ACTION_LIST_NAMES) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import json | ||
import re | ||
from pathlib import Path | ||
from typing import Callable | ||
|
||
import yaml | ||
from talon import actions, app | ||
|
||
from .get_action_spoken_form import lookup_action | ||
|
||
regex = re.compile(r"\{(\w+):([^}]+)\}") | ||
tutorial_dir = Path( | ||
r"C:\work\tools\voicecoding\cursorless_fork\packages\cursorless-vscode-e2e\src\suite\fixtures\recorded\tutorial\unit-2-basic-coding" | ||
) | ||
|
||
|
||
def process_literal_step(argument: str): | ||
return f"<cmd@{argument}/>" | ||
|
||
|
||
def process_action(argument: str): | ||
_, spoken_form = lookup_action(argument) | ||
return f'<*"{spoken_form}"/>' | ||
|
||
|
||
def process_scope_type(argument: str): | ||
# TODO not sure what we are trying to achieve here | ||
_, spoken_form = lookup_scope_type(argument) | ||
return f'<*"{spoken_form}"/>' | ||
|
||
|
||
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, | ||
"yamlFilename": argument, | ||
}, | ||
) | ||
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]] = { | ||
"literalStep": process_literal_step, | ||
"action": process_action, | ||
"scopeType": process_scope_type, | ||
"step": process_cursorless_command_step, | ||
} | ||
|
||
|
||
def process_tutorial_step(raw: str): | ||
print(f"{raw=}") | ||
current_index = 0 | ||
content = "" | ||
for match in regex.finditer(raw): | ||
content += raw[current_index : match.start()] | ||
content += interpolation_processor_map[match.group(1)](match.group(2)) | ||
current_index = match.end() | ||
content += raw[current_index : len(raw)] | ||
print(f"{content=}") | ||
|
||
return { | ||
"content": content, | ||
"restore_callback": print, | ||
"modes": ["command"], | ||
"app": "Code", | ||
"context_hint": "Please open VSCode and enter command mode", | ||
} | ||
|
||
|
||
def get_basic_coding_walkthrough(): | ||
with open(tutorial_dir / "script.json") as f: | ||
script = json.load(f) | ||
|
||
return [ | ||
actions.user.hud_create_walkthrough_step(**process_tutorial_step(step)) | ||
for step in script | ||
] | ||
|
||
|
||
def on_ready(): | ||
actions.user.hud_add_lazy_walkthrough( | ||
"Cursorless basic coding", get_basic_coding_walkthrough | ||
) | ||
|
||
|
||
app.register("ready", on_ready) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from talon import Context, Module | ||
|
||
mod = Module() | ||
ctx = Context() | ||
|
||
mod.list("cursorless_walkthrough_list", desc="My tutorial list") | ||
ctx.list["user.cursorless_walkthrough_list"] = { | ||
"spoken form": "whatever", | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
================================================== | ||
========== ========== | ||
========== Welcome to Cursorless! ========== | ||
========== ========== | ||
========== Let's start using marks ========== | ||
========== ========== | ||
========== so we can navigate around ========== | ||
========== ========== | ||
========== without lifting a finger! ========== | ||
========== ========== | ||
================================================== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
def print_color(color, invert=False): | ||
if invert: | ||
print(invert_color(color)) | ||
else: | ||
print(color) | ||
|
||
|
||
def invert_color(color): | ||
if color == "black": | ||
return "white" | ||
|
||
|
||
print_color("black") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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"; | ||
|
||
// TODO the engine is editor agnostic so we shouldn't really import that | ||
// TODO Editor specific features are accessed via the injected ide instance. | ||
// TODO packages\cursorless-engine\src\singletons\ide.singleton.ts | ||
import { openNewEditor } from "@cursorless/vscode-common"; | ||
|
||
import * as yaml from "js-yaml"; | ||
import { promises as fsp } from "node:fs"; | ||
|
||
import { TestCaseFixture } from "@cursorless/common"; | ||
import { Dictionary } from "lodash"; | ||
|
||
const tutorial_dir = | ||
"C:\\work\\tools\\voicecoding\\cursorless_fork\\packages\\cursorless-vscode-e2e\\src\\suite\\fixtures\\recorded\\tutorial\\unit-2-basic-coding"; | ||
|
||
/** | ||
* 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>; | ||
|
||
/** | ||
* The yaml file for the current step | ||
*/ | ||
yamlFilename: string; | ||
} | ||
|
||
export async function tutorialCreate({ | ||
version, | ||
stepFixture, | ||
yamlFilename, | ||
}: TutorialCommandArg) { | ||
if (version !== 0) { | ||
throw new Error(`Unsupported tutorial api version: ${version}`); | ||
} | ||
|
||
// const fixture = stepFixture as TestCaseFixture; | ||
createEnvironment(yamlFilename); | ||
// TODO need to answer to the talon side only what is necessary | ||
return stepFixture; | ||
} | ||
|
||
async function createEnvironment(yamlFilename: string) { | ||
const buffer = await fsp.readFile(path.join(tutorial_dir, yamlFilename)); | ||
const fixture = yaml.load(buffer.toString()) as TestCaseFixture; | ||
|
||
const editor = await openNewEditor(fixture.initialState.documentContents, { | ||
languageId: fixture.languageId, | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...de-e2e/src/suite/fixtures/recorded/tutorial/extra-cloning-a-talon-list/bringBlockMade.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
languageId: python | ||
command: | ||
version: 6 | ||
spokenForm: bring block made | ||
action: | ||
name: replaceWithTarget | ||
source: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: paragraph} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: m} | ||
destination: {type: implicit} | ||
usePrePhraseSnapshot: false | ||
initialState: | ||
documentContents: |+ | ||
from talon import Context, Module | ||
mod = Module() | ||
ctx = Context() | ||
mod.list("cursorless_walkthrough_list", desc="My tutorial list") | ||
ctx.list['user.cursorless_walkthrough_list'] = { | ||
"spoken form": "whatever", | ||
} | ||
selections: | ||
- anchor: {line: 10, character: 0} | ||
active: {line: 10, character: 0} | ||
marks: | ||
default.m: | ||
start: {line: 5, character: 0} | ||
end: {line: 5, character: 3} | ||
finalState: | ||
documentContents: |- | ||
from talon import Context, Module | ||
mod = Module() | ||
ctx = Context() | ||
mod.list("cursorless_walkthrough_list", desc="My tutorial list") | ||
ctx.list['user.cursorless_walkthrough_list'] = { | ||
"spoken form": "whatever", | ||
} | ||
mod.list("cursorless_walkthrough_list", desc="My tutorial list") | ||
ctx.list['user.cursorless_walkthrough_list'] = { | ||
"spoken form": "whatever", | ||
} | ||
selections: | ||
- anchor: {line: 13, character: 1} | ||
active: {line: 13, character: 1} |
56 changes: 56 additions & 0 deletions
56
...code-e2e/src/suite/fixtures/recorded/tutorial/extra-cloning-a-talon-list/clearCoreSun.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
languageId: python | ||
command: | ||
version: 6 | ||
spokenForm: change inside pair sun | ||
action: | ||
name: clearAndSetSelection | ||
target: | ||
type: primitive | ||
modifiers: | ||
- {type: interiorOnly} | ||
- type: containingScope | ||
scopeType: {type: surroundingPair, delimiter: any} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: s} | ||
usePrePhraseSnapshot: false | ||
initialState: | ||
documentContents: |- | ||
from talon import Context, Module | ||
mod = Module() | ||
ctx = Context() | ||
mod.list("cursorless_walkthrough_list", desc="My tutorial list") | ||
ctx.list['user.cursorless_walkthrough_list'] = { | ||
"spoken form": "whatever", | ||
} | ||
mod.list("emoji", desc="Emojis") | ||
ctx.list['user.emoji'] = { | ||
"spoken form": "whatever", | ||
} | ||
selections: | ||
- anchor: {line: 10, character: 30} | ||
active: {line: 10, character: 30} | ||
marks: | ||
default.s: | ||
start: {line: 12, character: 5} | ||
end: {line: 12, character: 11} | ||
finalState: | ||
documentContents: |- | ||
from talon import Context, Module | ||
mod = Module() | ||
ctx = Context() | ||
mod.list("cursorless_walkthrough_list", desc="My tutorial list") | ||
ctx.list['user.cursorless_walkthrough_list'] = { | ||
"spoken form": "whatever", | ||
} | ||
mod.list("emoji", desc="Emojis") | ||
ctx.list['user.emoji'] = { | ||
"": "whatever", | ||
} | ||
selections: | ||
- anchor: {line: 12, character: 5} | ||
active: {line: 12, character: 5} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.