@@ -6,12 +6,7 @@ import {
6
6
} from "@cursorless/common" ;
7
7
import { homedir } from "os" ;
8
8
import * as path from "path" ;
9
- import {
10
- CustomRegexSpokenFormEntry ,
11
- PairedDelimiterSpokenFormEntry ,
12
- SimpleScopeTypeTypeSpokenFormEntry ,
13
- getSpokenFormEntries ,
14
- } from "./scopeProviders/getSpokenFormEntries" ;
9
+ import { getSpokenFormEntries } from "./scopeProviders/getSpokenFormEntries" ;
15
10
import { SpokenFormMap } from "./SpokenFormMap" ;
16
11
import { defaultSpokenFormMap } from "./DefaultSpokenFormMap" ;
17
12
@@ -21,6 +16,12 @@ export const spokenFormsPath = path.join(
21
16
"spokenForms.json" ,
22
17
) ;
23
18
19
+ const ENTRY_TYPES = [
20
+ "simpleScopeTypeType" ,
21
+ "customRegex" ,
22
+ "pairedDelimiter" ,
23
+ ] as const ;
24
+
24
25
/**
25
26
* Maintains a list of all scope types and notifies listeners when it changes.
26
27
*/
@@ -66,36 +67,22 @@ export class CustomSpokenForms implements SpokenFormMap {
66
67
onDidChangeCustomSpokenForms = this . notifier . registerListener ;
67
68
68
69
private async updateSpokenFormMaps ( ) : Promise < void > {
69
- console . log ( "updateSpokenFormMaps before getSpokenFormEntries" ) ;
70
70
const entries = await getSpokenFormEntries ( ) ;
71
- console . log ( "updateSpokenFormMaps after getSpokenFormEntries" ) ;
72
71
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
+ }
97
85
98
- console . log ( "updateSpokenFormMaps at end" ) ;
99
86
this . isInitialized_ = true ;
100
87
this . notifier . notifyListeners ( ) ;
101
88
}
0 commit comments