Skip to content

Commit

Permalink
Fixed bug where we tried to read missing custom regex list (#2637)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson authored Aug 5, 2024
1 parent 5ebe165 commit 7e12524
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
20 changes: 10 additions & 10 deletions cursorless-talon/src/get_grapheme_spoken_form_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
def get_grapheme_spoken_form_entries(
grapheme_talon_list: dict[str, str],
) -> list[SpokenFormOutputEntry]:
if grapheme_capture_name not in registry.captures:
# 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.
# 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.
if "en" in scope.get("language", {}):
app.notify(f"Capture <{grapheme_capture_name}> isn't defined")
print(
f"Capture <{grapheme_capture_name}> isn't defined, which is required by Cursorless. Please check your community setup"
)
return []

return [
{
"type": "grapheme",
Expand All @@ -37,6 +27,16 @@ def get_grapheme_spoken_form_entries(


def get_graphemes_talon_list() -> dict[str, str]:
if grapheme_capture_name not in registry.captures:
# 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.
# 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.
if "en" in scope.get("language", {}):
app.notify(f"Capture <{grapheme_capture_name}> isn't defined")
print(
f"Capture <{grapheme_capture_name}> isn't defined, which is required by Cursorless. Please check your community setup"
)
return {}

return {
spoken_form: id
for symbol_list in generate_lists_from_capture(grapheme_capture_name)
Expand Down
1 change: 1 addition & 0 deletions cursorless-talon/src/spoken_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def handle_new_values(csv_name: str, values: list[SpokenFormEntry]):
if initialized:
# On first run, we just do one update at the end, so we suppress
# writing until we get there
init_scope_spoken_forms(graphemes_talon_list)
update_spoken_forms_output()

handle_csv = auto_construct_defaults(
Expand Down
15 changes: 5 additions & 10 deletions cursorless-talon/src/spoken_scope_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@


def init_scope_spoken_forms(graphemes_talon_list: dict[str, str]):
create_flattened_talon_list(
csv_get_ctx(), graphemes_talon_list, include_custom_regex=True
)
create_flattened_talon_list(csv_get_ctx(), graphemes_talon_list)
if is_cursorless_test_mode():
create_flattened_talon_list(
csv_get_normalized_ctx(), graphemes_talon_list, include_custom_regex=False
)
create_flattened_talon_list(csv_get_normalized_ctx(), graphemes_talon_list)


def create_flattened_talon_list(
ctx: Context, graphemes_talon_list: dict[str, str], include_custom_regex: bool
):
def create_flattened_talon_list(ctx: Context, graphemes_talon_list: dict[str, str]):
lists_to_merge = {
"cursorless_scope_type": "simple",
"cursorless_surrounding_pair_scope_type": "surroundingPair",
"cursorless_selectable_only_paired_delimiter": "surroundingPair",
"cursorless_wrapper_selectable_paired_delimiter": "surroundingPair",
}
if include_custom_regex:
# If the user have no custom regex scope type, then that list is missing from the context
if "user.cursorless_custom_regex_scope_type" in ctx.lists.keys(): # noqa: SIM118
lists_to_merge["cursorless_custom_regex_scope_type"] = "customRegex"

scope_types_singular: dict[str, str] = {}
Expand Down

0 comments on commit 7e12524

Please sign in to comment.