@@ -6,12 +6,7 @@ import {
66} from "@cursorless/common" ;
77import { homedir } from "os" ;
88import * as path from "path" ;
9- import {
10- CustomRegexSpokenFormEntry ,
11- PairedDelimiterSpokenFormEntry ,
12- SimpleScopeTypeTypeSpokenFormEntry ,
13- getSpokenFormEntries ,
14- } from "./scopeProviders/getSpokenFormEntries" ;
9+ import { getSpokenFormEntries } from "./scopeProviders/getSpokenFormEntries" ;
1510import { SpokenFormMap } from "./SpokenFormMap" ;
1611import { defaultSpokenFormMap } from "./DefaultSpokenFormMap" ;
1712
@@ -21,6 +16,12 @@ export const spokenFormsPath = path.join(
2116 "spokenForms.json" ,
2217) ;
2318
19+ const ENTRY_TYPES = [
20+ "simpleScopeTypeType" ,
21+ "customRegex" ,
22+ "pairedDelimiter" ,
23+ ] as const ;
24+
2425/**
2526 * Maintains a list of all scope types and notifies listeners when it changes.
2627 */
@@ -66,36 +67,22 @@ export class CustomSpokenForms implements SpokenFormMap {
6667 onDidChangeCustomSpokenForms = this . notifier . registerListener ;
6768
6869 private async updateSpokenFormMaps ( ) : Promise < void > {
69- console . log ( "updateSpokenFormMaps before getSpokenFormEntries" ) ;
7070 const entries = await getSpokenFormEntries ( ) ;
71- console . log ( "updateSpokenFormMaps after getSpokenFormEntries" ) ;
7271
73- this . simpleScopeTypeType = Object . fromEntries (
74- entries
75- . filter (
76- ( entry ) : entry is SimpleScopeTypeTypeSpokenFormEntry =>
77- entry . type === "simpleScopeTypeType" ,
78- )
79- . map ( ( { id, spokenForms } ) => [ id , spokenForms ] as const ) ,
80- ) ;
81- this . customRegex = Object . fromEntries (
82- entries
83- . filter (
84- ( entry ) : entry is CustomRegexSpokenFormEntry =>
85- entry . type === "customRegex" ,
86- )
87- . map ( ( { id, spokenForms } ) => [ id , spokenForms ] as const ) ,
88- ) ;
89- this . pairedDelimiter = Object . fromEntries (
90- entries
91- . filter (
92- ( entry ) : entry is PairedDelimiterSpokenFormEntry =>
93- entry . type === "pairedDelimiter" ,
94- )
95- . map ( ( { id, spokenForms } ) => [ id , spokenForms ] as const ) ,
96- ) ;
72+ for ( const entryType of ENTRY_TYPES ) {
73+ // TODO: Handle case where we've added a new scope type but they haven't yet
74+ // updated their talon files. In that case we want to indicate in tree view
75+ // that the scope type exists but they need to update their talon files to
76+ // be able to speak it. We could just detect that there's no entry for it in
77+ // the spoken forms file, but that feels a bit brittle.
78+ // FIXME: How to avoid the type assertion?
79+ this [ entryType ] = Object . fromEntries (
80+ entries
81+ . filter ( ( entry ) => entry . type === entryType )
82+ . map ( ( { id, spokenForms } ) => [ id , spokenForms ] ) ,
83+ ) as any ;
84+ }
9785
98- console . log ( "updateSpokenFormMaps at end" ) ;
9986 this . isInitialized_ = true ;
10087 this . notifier . notifyListeners ( ) ;
10188 }
0 commit comments