Skip to content

Commit

Permalink
Remove snippets from spoken form json (#2842)
Browse files Browse the repository at this point in the history
Read from deprecated snippet csv files if the exists, but do not create
them if they don't.

Fixes #2841
  • Loading branch information
AndreasArvidsson authored Feb 14, 2025
1 parent 5d4141c commit 9fa646b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
15 changes: 11 additions & 4 deletions cursorless-talon/src/csv_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def init_csv_and_watch_changes(
extra_ignored_values: Optional[list[str]] = None,
extra_allowed_values: Optional[list[str]] = None,
allow_unknown_values: bool = False,
deprecated: bool = False,
default_list_name: Optional[str] = None,
headers: list[str] = [SPOKEN_FORM_HEADER, CURSORLESS_IDENTIFIER_HEADER],
no_update_file: bool = False,
Expand Down Expand Up @@ -123,6 +124,12 @@ def init_csv_and_watch_changes(
pluralize_lists = []

file_path = get_full_path(filename)
is_file = file_path.is_file()

# Deprecated file that doesn't exist. Do nothing.
if deprecated and not is_file:
return lambda: None

super_default_values = get_super_values(default_values)

file_path.parent.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -151,9 +158,9 @@ def on_watch(path, flags):
handle_new_values=handle_new_values,
)

fs.watch(str(file_path.parent), on_watch)
fs.watch(file_path.parent, on_watch)

if file_path.is_file():
if is_file:
current_values = update_file(
path=file_path,
headers=headers,
Expand Down Expand Up @@ -188,7 +195,7 @@ def on_watch(path, flags):
)

def unsubscribe():
fs.unwatch(str(file_path.parent), on_watch)
fs.unwatch(file_path.parent, on_watch)

return unsubscribe

Expand Down Expand Up @@ -385,7 +392,7 @@ def csv_error(path: Path, index: int, message: str, value: str):
index (int): The index into the file (for error reporting)
text (str): The text of the error message to report if condition is false
"""
print(f"ERROR: {path}:{index+1}: {message} '{value}'")
print(f"ERROR: {path}:{index + 1}: {message} '{value}'")


def read_file(
Expand Down
26 changes: 3 additions & 23 deletions cursorless-talon/src/spoken_forms.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,29 +233,9 @@
"-from": "experimental.setInstanceReference"
}
},
"experimental/wrapper_snippets.csv": {
"wrapper_snippet": {
"else": "ifElseStatement.alternative",
"funk": "functionDeclaration.body",
"if else": "ifElseStatement.consequence",
"if": "ifStatement.consequence",
"try": "tryCatchStatement.body",
"link": "link.text"
}
},
"experimental/insertion_snippets.csv": {
"insertion_snippet_no_phrase": {
"if": "ifStatement",
"if else": "ifElseStatement",
"try": "tryCatchStatement"
}
},
"experimental/insertion_snippets_single_phrase.csv": {
"insertion_snippet_single_phrase": {
"funk": "functionDeclaration.name",
"link": "link.text"
}
},
"experimental/wrapper_snippets.csv": {},
"experimental/insertion_snippets.csv": {},
"experimental/insertion_snippets_single_phrase.csv": {},
"experimental/miscellaneous.csv": {
"phrase_terminator": { "over": "phraseTerminator" }
},
Expand Down
10 changes: 8 additions & 2 deletions cursorless-talon/src/spoken_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,26 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
# DEPRECATED @ 2025-02-01
handle_csv(
"experimental/wrapper_snippets.csv",
deprecated=True,
allow_unknown_values=True,
default_list_name="wrapper_snippet",
),
handle_csv(
"experimental/insertion_snippets.csv",
deprecated=True,
allow_unknown_values=True,
default_list_name="insertion_snippet_no_phrase",
),
handle_csv(
"experimental/insertion_snippets_single_phrase.csv",
deprecated=True,
allow_unknown_values=True,
default_list_name="insertion_snippet_single_phrase",
),
handle_csv("experimental/miscellaneous.csv"),
handle_csv(
"experimental/miscellaneous.csv",
deprecated=True,
),
# ---
handle_csv(
"experimental/actions_custom.csv",
Expand Down Expand Up @@ -235,7 +241,7 @@ def on_ready():

registry.register("update_captures", update_captures_debounced)

fs.watch(str(JSON_FILE.parent), on_watch)
fs.watch(JSON_FILE.parent, on_watch)


app.register("ready", on_ready)

0 comments on commit 9fa646b

Please sign in to comment.