From 2052d55626675d21529b9c7e2ef62f787cf42764 Mon Sep 17 00:00:00 2001 From: Pokey Rule <755842+pokey@users.noreply.github.com> Date: Wed, 1 May 2024 16:58:37 +0100 Subject: [PATCH] Fix language not loaded errors --- .../cursorless-engine/src/cursorlessEngine.ts | 5 +++-- .../src/languages/LanguageDefinitions.ts | 18 ++++++++++++++---- packages/cursorless-vscode/src/extension.ts | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/cursorless-engine/src/cursorlessEngine.ts b/packages/cursorless-engine/src/cursorlessEngine.ts index 71dd1b1d4e..6dc220db4a 100644 --- a/packages/cursorless-engine/src/cursorlessEngine.ts +++ b/packages/cursorless-engine/src/cursorlessEngine.ts @@ -31,13 +31,13 @@ import { ScopeSupportWatcher } from "./scopeProviders/ScopeSupportWatcher"; import { injectIde } from "./singletons/ide.singleton"; import { TreeSitter } from "./typings/TreeSitter"; -export function createCursorlessEngine( +export async function createCursorlessEngine( treeSitter: TreeSitter, ide: IDE, hats: Hats, commandServerApi: CommandServerApi | null, fileSystem: FileSystem, -): CursorlessEngine { +): Promise { injectIde(ide); const debug = new Debug(treeSitter); @@ -58,6 +58,7 @@ export function createCursorlessEngine( const storedTargets = new StoredTargetMap(); const languageDefinitions = new LanguageDefinitions(fileSystem, treeSitter); + await languageDefinitions.init(); const talonSpokenForms = new TalonSpokenFormsJsonReader(fileSystem); diff --git a/packages/cursorless-engine/src/languages/LanguageDefinitions.ts b/packages/cursorless-engine/src/languages/LanguageDefinitions.ts index a38f0a20a8..04467ff5f2 100644 --- a/packages/cursorless-engine/src/languages/LanguageDefinitions.ts +++ b/packages/cursorless-engine/src/languages/LanguageDefinitions.ts @@ -60,10 +60,6 @@ export class LanguageDefinitions { ? join(getCursorlessRepoRoot(), "queries") : "queries"; - ide().visibleTextEditors.forEach(({ document }) => - this.loadLanguage(document.languageId), - ); - if (ide().runMode === "development") { this.disposables.push( fileSystem.watchDir(this.queryDir, () => { @@ -73,6 +69,20 @@ export class LanguageDefinitions { } } + public async init(): Promise { + await this.loadAllLanguages(); + } + + private async loadAllLanguages(): Promise { + const languageIds = ide().visibleTextEditors.map( + ({ document }) => document.languageId, + ); + + await Promise.all( + languageIds.map((languageId) => this.loadLanguage(languageId)), + ); + } + public async loadLanguage(languageId: string): Promise { if (this.languageDefinitions.has(languageId)) { return; diff --git a/packages/cursorless-vscode/src/extension.ts b/packages/cursorless-vscode/src/extension.ts index fcc7e2334d..de08aa21b6 100644 --- a/packages/cursorless-vscode/src/extension.ts +++ b/packages/cursorless-vscode/src/extension.ts @@ -92,7 +92,7 @@ export async function activate( runIntegrationTests, addCommandRunnerDecorator, customSpokenFormGenerator, - } = createCursorlessEngine( + } = await createCursorlessEngine( treeSitter, normalizedIde, hats,