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,