Skip to content

Commit

Permalink
Make language loading more robust (#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey authored May 21, 2024
1 parent 2b6475e commit f9d2834
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/cursorless-engine/src/languages/LanguageDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {
Range,
TextDocument,
getCursorlessRepoRoot,
isTesting,
showError,
} from "@cursorless/common";
import { join } from "path";
import { SyntaxNode } from "web-tree-sitter";
import { TreeSitter } from "../typings/TreeSitter";
import { ide } from "../singletons/ide.singleton";
import { LanguageDefinition } from "./LanguageDefinition";
import { toString } from "lodash";

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

await Promise.all(
languageIds.map((languageId) => this.loadLanguage(languageId)),
);
try {
await Promise.all(
languageIds.map((languageId) => this.loadLanguage(languageId)),
);
} catch (err) {
showError(
ide().messages,
"Failed to load language definitions",
toString(err),
);
if (isTesting()) {
throw err;
}
}
}

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

private async reloadLanguageDefinitions(): Promise<void> {
const languageIds = Array.from(this.languageDefinitions.keys());
this.languageDefinitions.clear();
await Promise.all(
languageIds.map((languageId) => this.loadLanguage(languageId)),
);
await this.loadAllLanguages();
this.notifier.notifyListeners();
}

Expand Down

0 comments on commit f9d2834

Please sign in to comment.