Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cursorless-talon-dev/src/cursorless_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ def cursorless_record_silent_test():
def private_cursorless_make_snippet_test(target: Any):
"""Test generating a snippet"""
actions.user.private_cursorless_command_no_wait(
{"name": "generateSnippet", "snippetName": "testSnippet", "target": target}
{
"name": "generateSnippet",
"dirPath": "",
"snippetName": "testSnippet",
"target": target,
}
)
3 changes: 2 additions & 1 deletion cursorless-talon/src/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
)
from .bring_move import BringMoveTargets
from .execute_command import cursorless_execute_command_action
from .generate_snippet import cursorless_generate_snippet_action
from .homophones import cursorless_homophones_action
from .replace import cursorless_replace_action

Expand Down Expand Up @@ -50,12 +51,12 @@
]

callback_actions: dict[str, Callable[[CursorlessExplicitTarget], None]] = {
"generateSnippet": cursorless_generate_snippet_action,
"nextHomophone": cursorless_homophones_action,
}

# Don't wait for these actions to finish, usually because they hang on some kind of user interaction
no_wait_actions = [
"generateSnippet",
"rename",
]

Expand Down
50 changes: 50 additions & 0 deletions cursorless-talon/src/actions/generate_snippet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import glob
from pathlib import Path

from talon import actions, settings

from ..targets.target_types import CursorlessExplicitTarget


def cursorless_generate_snippet_action(target: CursorlessExplicitTarget):
actions.user.private_cursorless_command_no_wait(
{
"name": "generateSnippet",
"target": target,
"dirPath": get_dir_path(),
}
)


def get_dir_path() -> str:
settings_dir = get_setting_dir()
if settings_dir is not None:
return settings_dir
return get_community_snippets_dir()


def get_community_snippets_dir() -> str:
files = glob.iglob(
f"{actions.path.talon_user()}/**/snippets/snippets/*.snippet",
recursive=True,
)
for file in files:
return str(Path(file).parent)
raise ValueError("Could not find community snippets directory")


def get_setting_dir() -> str | None:
try:
setting_dir = settings.get("user.snippets_dir")
if not setting_dir:
return None

dir = Path(setting_dir)

if not dir.is_absolute():
user_dir = Path(actions.path.talon_user())
dir = user_dir / dir

return str(dir.resolve())
except Exception:
return None
2 changes: 1 addition & 1 deletion cursorless-talon/src/versions.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
COMMAND_VERSION = 7
COMMAND_VERSION = 8
47 changes: 17 additions & 30 deletions data/fixtures/recorded/actions/snippets/snipMakeFunk.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
languageId: typescript
command:
version: 6
version: 8
spokenForm: snippet make funk
action:
name: generateSnippet
dirPath: ""
snippetName: snippetTest1
target:
type: primitive
Expand All @@ -28,37 +29,23 @@ initialState:
active: {line: 5, character: 9}
marks: {}
finalState:
documentContents: |-
{
"snippetTest1": {
"definitions": [
{
"scope": {
"langIds": [
"typescript"
]
},
"body": [
"function $variable1() {",
"\tconst whatever = \"hello\";",
"",
"\t$variable2",
"}"
]
}
],
"description": "",
"variables": {
"variable1": {},
"variable2": {}
}
}
documentContents: |
name: snippetTest1
language: typescript
phrase:

$1.wrapperPhrase:
$0.wrapperPhrase:
-
function $1() {
const whatever = "hello";

$0
}
---
selections:
- anchor: {line: 10, character: 21}
active: {line: 10, character: 30}
- anchor: {line: 20, character: 7}
active: {line: 20, character: 16}
- anchor: {line: 2, character: 8}
active: {line: 2, character: 8}
thatMark:
- type: UntypedTarget
contentRange:
Expand Down
41 changes: 14 additions & 27 deletions data/fixtures/recorded/actions/snippets/snipMakeState.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
languageId: typescript
command:
version: 6
version: 8
spokenForm: snippet make state
action:
name: generateSnippet
dirPath: ""
snippetName: snippetTest1
target:
type: primitive
Expand All @@ -22,34 +23,20 @@ initialState:
active: {line: 0, character: 4}
marks: {}
finalState:
documentContents: |-
{
"snippetTest1": {
"definitions": [
{
"scope": {
"langIds": [
"typescript"
]
},
"body": [
"if ($variable1) {",
"\tconsole.log(\"hello\")",
"}"
]
}
],
"description": "",
"variables": {
"variable1": {}
}
}
documentContents: |
name: snippetTest1
language: typescript
phrase:

$0.wrapperPhrase:
-
if ($0) {
console.log("hello")
}
---
selections:
- anchor: {line: 10, character: 16}
active: {line: 10, character: 25}
- anchor: {line: 18, character: 7}
active: {line: 18, character: 16}
- anchor: {line: 2, character: 8}
active: {line: 2, character: 8}
thatMark:
- type: UntypedTarget
contentRange:
Expand Down
39 changes: 13 additions & 26 deletions data/fixtures/recorded/actions/snippets/testSnippetMakeLine.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
languageId: plaintext
command:
version: 6
version: 8
spokenForm: test snippet make line
action:
name: generateSnippet
dirPath: ""
snippetName: testSnippet
target:
type: primitive
Expand All @@ -19,32 +20,18 @@ initialState:
active: {line: 0, character: 12}
marks: {}
finalState:
documentContents: |-
{
"testSnippet": {
"definitions": [
{
"scope": {
"langIds": [
"plaintext"
]
},
"body": [
"\\textbf{\\$$variable1}"
]
}
],
"description": "",
"variables": {
"variable1": {}
}
}
}
documentContents: |
name: testSnippet
language: plaintext
phrase:

$0.wrapperPhrase:
-
\textbf{\$$0}
---
selections:
- anchor: {line: 10, character: 24}
active: {line: 10, character: 33}
- anchor: {line: 16, character: 7}
active: {line: 16, character: 16}
- anchor: {line: 2, character: 8}
active: {line: 2, character: 8}
thatMark:
- type: UntypedTarget
contentRange:
Expand Down
2 changes: 1 addition & 1 deletion data/fixtures/recorded/testCaseRecorder/takeHarp.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
languageId: plaintext
command:
version: 7
version: 8
spokenForm: take harp
action:
name: setSelection
Expand Down
9 changes: 5 additions & 4 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ export * from "./ide/types/Clipboard";
export * from "./ide/types/CommandHistoryStorage";
export * from "./ide/types/CommandId";
export * from "./ide/types/Configuration";
export * from "./ide/types/events.types";
export * from "./ide/types/Events";
export * from "./ide/types/events.types";
export * from "./ide/types/FileSystem.types";
export * from "./ide/types/FlashDescriptor";
export * from "./ide/types/Hats";
export * from "./ide/types/HatStability";
export * from "./ide/types/hatStyles.types";
export * from "./ide/types/ide.types";
export * from "./ide/types/KeyValueStore";
export * from "./ide/types/Messages";
export * from "./ide/types/Paths";
export * from "./ide/types/QuickPickOptions";
export * from "./ide/types/RawTreeSitterQueryProvider";
export * from "./ide/types/KeyValueStore";
export * from "./ide/types/TutorialContentProvider";
export * from "./ide/util/messages";
export * from "./scopeSupportFacets/languageScopeSupport";
Expand All @@ -46,15 +46,16 @@ export * from "./testUtil/TestCaseSnapshot";
export * from "./testUtil/testConstants";
export * from "./types/command/ActionDescriptor";
export * from "./types/command/command.types";
export * from "./types/command/CommandV6.types";
export * from "./types/command/CommandV7.types";
export * from "./types/command/CommandV8.types";
export * from "./types/command/DestinationDescriptor.types";
export * from "./types/command/legacy/ActionCommandV5";
export * from "./types/command/legacy/CommandV0V1.types";
export * from "./types/command/legacy/CommandV2.types";
export * from "./types/command/legacy/CommandV3.types";
export * from "./types/command/legacy/CommandV4.types";
export * from "./types/command/legacy/CommandV5.types";
export * from "./types/command/legacy/CommandV6.types";
export * from "./types/command/legacy/CommandV7.types";
export * from "./types/command/legacy/PartialTargetDescriptorV3.types";
export * from "./types/command/legacy/PartialTargetDescriptorV4.types";
export * from "./types/command/legacy/PartialTargetDescriptorV5.types";
Expand Down
9 changes: 6 additions & 3 deletions packages/common/src/testUtil/serializeTestFixture.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { TestCaseFixtureLegacy } from "../types/TestCaseFixture";
import type { ActionDescriptor } from "../types/command/ActionDescriptor";
import type { CommandV6 } from "../types/command/CommandV6.types";
import type { CommandV7 } from "../types/command/CommandV7.types";
import type { CommandV6 } from "../types/command/legacy/CommandV6.types";
import type { CommandV7 } from "../types/command/legacy/CommandV7.types";
import type { Command } from "../types/command/command.types";
import type { CommandV5 } from "../types/command/legacy/CommandV5.types";
import type { EnforceUndefined } from "../util/typeUtils";
import { serialize } from "./serialize";
import type { ActionDescriptorV6 } from "../types/command/legacy/ActionDescriptorV6";

function reorderFields(
fixture: TestCaseFixtureLegacy,
Expand Down Expand Up @@ -41,6 +42,8 @@ function reorderCommandFields(command: Command): Command {
return reorderCommandV6Fields(command);
case 7:
return reorderCommandV7Fields(command);
case 8:
return command;
}
}

Expand Down Expand Up @@ -81,7 +84,7 @@ function reorderCommandV7Fields(
};
}

function reorderActionFields(action: ActionDescriptor): ActionDescriptor {
function reorderActionFields(action: ActionDescriptorV6): ActionDescriptor {
const { name, ...rest } = action;
return {
name,
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/types/SpokenFormType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface SpokenFormMapKeyTypes {
pairedDelimiter: SpeakableSurroundingPairName;
simpleScopeTypeType: SimpleScopeTypeType;
complexScopeTypeType: "glyph";
surroundingPairForceDirection: "left" | "right";

/**
* These modifier types are spoken by directly saying the spoken form for the
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/types/command/ActionDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface PasteActionDescriptor {

export interface GenerateSnippetActionDescriptor {
name: "generateSnippet";
dirPath: string;
snippetName?: string;
target: PartialTargetDescriptor;
}
Expand Down
27 changes: 27 additions & 0 deletions packages/common/src/types/command/CommandV8.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { ActionDescriptor } from "./ActionDescriptor";

export interface CommandV8 {
/**
* The version number of the command API
*/
version: 8;

/**
* The spoken form of the command if issued from a voice command system
*/
spokenForm?: string;

/**
* If the command is issued from a voice command system, this boolean indicates
* whether we should use the pre phrase snapshot. Only set this to true if the
* voice command system issues a pre phrase signal at the start of every
* phrase.
*/
usePrePhraseSnapshot: boolean;

/**
* The action to perform. This field contains everything necessary to actually
* perform the action. The other fields are just metadata.
*/
action: ActionDescriptor;
}
Loading
Loading