Skip to content

Commit f9d2834

Browse files
authored
Make language loading more robust (#2350)
## 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 2b6475e commit f9d2834

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/cursorless-engine/src/languages/LanguageDefinitions.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import {
55
Range,
66
TextDocument,
77
getCursorlessRepoRoot,
8+
isTesting,
9+
showError,
810
} from "@cursorless/common";
911
import { join } from "path";
1012
import { SyntaxNode } from "web-tree-sitter";
1113
import { TreeSitter } from "../typings/TreeSitter";
1214
import { ide } from "../singletons/ide.singleton";
1315
import { LanguageDefinition } from "./LanguageDefinition";
16+
import { toString } from "lodash";
1417

1518
/**
1619
* Sentinel value to indicate that a language doesn't have
@@ -78,9 +81,20 @@ export class LanguageDefinitions {
7881
({ document }) => document.languageId,
7982
);
8083

81-
await Promise.all(
82-
languageIds.map((languageId) => this.loadLanguage(languageId)),
83-
);
84+
try {
85+
await Promise.all(
86+
languageIds.map((languageId) => this.loadLanguage(languageId)),
87+
);
88+
} catch (err) {
89+
showError(
90+
ide().messages,
91+
"Failed to load language definitions",
92+
toString(err),
93+
);
94+
if (isTesting()) {
95+
throw err;
96+
}
97+
}
8498
}
8599

86100
public async loadLanguage(languageId: string): Promise<void> {
@@ -100,11 +114,8 @@ export class LanguageDefinitions {
100114
}
101115

102116
private async reloadLanguageDefinitions(): Promise<void> {
103-
const languageIds = Array.from(this.languageDefinitions.keys());
104117
this.languageDefinitions.clear();
105-
await Promise.all(
106-
languageIds.map((languageId) => this.loadLanguage(languageId)),
107-
);
118+
await this.loadAllLanguages();
108119
this.notifier.notifyListeners();
109120
}
110121

0 commit comments

Comments
 (0)