Skip to content

Commit 7e12524

Browse files
Fixed bug where we tried to read missing custom regex list (#2637)
## Checklist - [/] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [/] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [/] I have not broken the cheatsheet
1 parent 5ebe165 commit 7e12524

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

cursorless-talon/src/get_grapheme_spoken_form_entries.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414
def get_grapheme_spoken_form_entries(
1515
grapheme_talon_list: dict[str, str],
1616
) -> list[SpokenFormOutputEntry]:
17-
if grapheme_capture_name not in registry.captures:
18-
# We require this capture, and expect it to be defined. We want to show a user friendly error if it isn't present (usually indicating a problem with their community.git setup) and we think the user is going to use Cursorless.
19-
# However, sometimes users use different dictation engines (Vosk, Webspeech) with entirely different/smaller grammars that don't have the capture, and this code will run then, and falsely error. We don't want to show an error in that case because they don't plan to actually use Cursorless.
20-
if "en" in scope.get("language", {}):
21-
app.notify(f"Capture <{grapheme_capture_name}> isn't defined")
22-
print(
23-
f"Capture <{grapheme_capture_name}> isn't defined, which is required by Cursorless. Please check your community setup"
24-
)
25-
return []
26-
2717
return [
2818
{
2919
"type": "grapheme",
@@ -37,6 +27,16 @@ def get_grapheme_spoken_form_entries(
3727

3828

3929
def get_graphemes_talon_list() -> dict[str, str]:
30+
if grapheme_capture_name not in registry.captures:
31+
# We require this capture, and expect it to be defined. We want to show a user friendly error if it isn't present (usually indicating a problem with their community.git setup) and we think the user is going to use Cursorless.
32+
# However, sometimes users use different dictation engines (Vosk, Webspeech) with entirely different/smaller grammars that don't have the capture, and this code will run then, and falsely error. We don't want to show an error in that case because they don't plan to actually use Cursorless.
33+
if "en" in scope.get("language", {}):
34+
app.notify(f"Capture <{grapheme_capture_name}> isn't defined")
35+
print(
36+
f"Capture <{grapheme_capture_name}> isn't defined, which is required by Cursorless. Please check your community setup"
37+
)
38+
return {}
39+
4040
return {
4141
spoken_form: id
4242
for symbol_list in generate_lists_from_capture(grapheme_capture_name)

cursorless-talon/src/spoken_forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
125125
if initialized:
126126
# On first run, we just do one update at the end, so we suppress
127127
# writing until we get there
128+
init_scope_spoken_forms(graphemes_talon_list)
128129
update_spoken_forms_output()
129130

130131
handle_csv = auto_construct_defaults(

cursorless-talon/src/spoken_scope_forms.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,20 @@
44

55

66
def init_scope_spoken_forms(graphemes_talon_list: dict[str, str]):
7-
create_flattened_talon_list(
8-
csv_get_ctx(), graphemes_talon_list, include_custom_regex=True
9-
)
7+
create_flattened_talon_list(csv_get_ctx(), graphemes_talon_list)
108
if is_cursorless_test_mode():
11-
create_flattened_talon_list(
12-
csv_get_normalized_ctx(), graphemes_talon_list, include_custom_regex=False
13-
)
9+
create_flattened_talon_list(csv_get_normalized_ctx(), graphemes_talon_list)
1410

1511

16-
def create_flattened_talon_list(
17-
ctx: Context, graphemes_talon_list: dict[str, str], include_custom_regex: bool
18-
):
12+
def create_flattened_talon_list(ctx: Context, graphemes_talon_list: dict[str, str]):
1913
lists_to_merge = {
2014
"cursorless_scope_type": "simple",
2115
"cursorless_surrounding_pair_scope_type": "surroundingPair",
2216
"cursorless_selectable_only_paired_delimiter": "surroundingPair",
2317
"cursorless_wrapper_selectable_paired_delimiter": "surroundingPair",
2418
}
25-
if include_custom_regex:
19+
# If the user have no custom regex scope type, then that list is missing from the context
20+
if "user.cursorless_custom_regex_scope_type" in ctx.lists.keys(): # noqa: SIM118
2621
lists_to_merge["cursorless_custom_regex_scope_type"] = "customRegex"
2722

2823
scope_types_singular: dict[str, str] = {}

0 commit comments

Comments
 (0)