Skip to content

Commit

Permalink
Fix language not loaded errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pokey committed May 1, 2024
1 parent e0a9806 commit 2052d55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/cursorless-engine/src/cursorlessEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CursorlessEngine> {
injectIde(ide);

const debug = new Debug(treeSitter);
Expand All @@ -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);

Expand Down
18 changes: 14 additions & 4 deletions packages/cursorless-engine/src/languages/LanguageDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand All @@ -73,6 +69,20 @@ export class LanguageDefinitions {
}
}

public async init(): Promise<void> {
await this.loadAllLanguages();
}

private async loadAllLanguages(): Promise<void> {
const languageIds = ide().visibleTextEditors.map(
({ document }) => document.languageId,
);

await Promise.all(
languageIds.map((languageId) => this.loadLanguage(languageId)),
);
}

public async loadLanguage(languageId: string): Promise<void> {
if (this.languageDefinitions.has(languageId)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/cursorless-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function activate(
runIntegrationTests,
addCommandRunnerDecorator,
customSpokenFormGenerator,
} = createCursorlessEngine(
} = await createCursorlessEngine(
treeSitter,
normalizedIde,
hats,
Expand Down

0 comments on commit 2052d55

Please sign in to comment.