File tree 4 files changed +29
-6
lines changed
4 files changed +29
-6
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @code-hike/lighter " : patch
3
+ ---
4
+
5
+ Better parallelism
Original file line number Diff line number Diff line change @@ -1194,6 +1194,7 @@ const lighter = {
1194
1194
registry: null,
1195
1195
aliasToScope: new Map(),
1196
1196
scopeToGrammar: new Map(),
1197
+ scopeToPromise: new Map(),
1197
1198
};
1198
1199
1199
1200
function newRegistry() {
@@ -1208,8 +1209,9 @@ async function loadGrammars(alias) {
1208
1209
lighter.registry = newRegistry();
1209
1210
}
1210
1211
1211
- // if alias is registered, return
1212
1212
if (lighter.aliasToScope.has(alias)) {
1213
+ const scope = lighter.aliasToScope.get(alias);
1214
+ await lighter.scopeToPromise.get(scope);
1213
1215
return;
1214
1216
}
1215
1217
@@ -1227,7 +1229,11 @@ async function loadGrammars(alias) {
1227
1229
});
1228
1230
1229
1231
await Promise.all(
1230
- newGrammars.map((g) => lighter.registry.loadGrammar(g.scopeName))
1232
+ newGrammars.map((g) => {
1233
+ const promise = lighter.registry.loadGrammar(g.scopeName);
1234
+ lighter.scopeToPromise.set(g.scopeName, promise);
1235
+ return promise;
1236
+ })
1231
1237
);
1232
1238
}
1233
1239
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const lighter = {
10
10
registry : null ,
11
11
aliasToScope : new Map ( ) ,
12
12
scopeToGrammar : new Map ( ) ,
13
+ scopeToPromise : new Map ( ) ,
13
14
} ;
14
15
15
16
export function newRegistry ( ) {
@@ -24,8 +25,9 @@ export async function loadGrammars(alias) {
24
25
lighter . registry = newRegistry ( ) ;
25
26
}
26
27
27
- // if alias is registered, return
28
28
if ( lighter . aliasToScope . has ( alias ) ) {
29
+ const scope = lighter . aliasToScope . get ( alias ) ;
30
+ await lighter . scopeToPromise . get ( scope ) ;
29
31
return ;
30
32
}
31
33
@@ -43,7 +45,11 @@ export async function loadGrammars(alias) {
43
45
} ) ;
44
46
45
47
await Promise . all (
46
- newGrammars . map ( ( g ) => lighter . registry . loadGrammar ( g . scopeName ) )
48
+ newGrammars . map ( ( g ) => {
49
+ const promise = lighter . registry . loadGrammar ( g . scopeName ) ;
50
+ lighter . scopeToPromise . set ( g . scopeName , promise ) ;
51
+ return promise ;
52
+ } )
47
53
) ;
48
54
}
49
55
You can’t perform that action at this time.
0 commit comments