Skip to content

Commit d7df9c3

Browse files
authored
Fix language not loaded errors (#2317)
Was causing sidebar to not load correctly if it was open on startup. Might also address #2294 but not sure ## 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 e0a9806 commit d7df9c3

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

packages/cursorless-engine/src/cursorlessEngine.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ import { ScopeSupportWatcher } from "./scopeProviders/ScopeSupportWatcher";
3131
import { injectIde } from "./singletons/ide.singleton";
3232
import { TreeSitter } from "./typings/TreeSitter";
3333

34-
export function createCursorlessEngine(
34+
export async function createCursorlessEngine(
3535
treeSitter: TreeSitter,
3636
ide: IDE,
3737
hats: Hats,
3838
commandServerApi: CommandServerApi | null,
3939
fileSystem: FileSystem,
40-
): CursorlessEngine {
40+
): Promise<CursorlessEngine> {
4141
injectIde(ide);
4242

4343
const debug = new Debug(treeSitter);
@@ -58,6 +58,7 @@ export function createCursorlessEngine(
5858
const storedTargets = new StoredTargetMap();
5959

6060
const languageDefinitions = new LanguageDefinitions(fileSystem, treeSitter);
61+
await languageDefinitions.init();
6162

6263
const talonSpokenForms = new TalonSpokenFormsJsonReader(fileSystem);
6364

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ export class LanguageDefinitions {
6060
? join(getCursorlessRepoRoot(), "queries")
6161
: "queries";
6262

63-
ide().visibleTextEditors.forEach(({ document }) =>
64-
this.loadLanguage(document.languageId),
65-
);
66-
6763
if (ide().runMode === "development") {
6864
this.disposables.push(
6965
fileSystem.watchDir(this.queryDir, () => {
@@ -73,6 +69,20 @@ export class LanguageDefinitions {
7369
}
7470
}
7571

72+
public async init(): Promise<void> {
73+
await this.loadAllLanguages();
74+
}
75+
76+
private async loadAllLanguages(): Promise<void> {
77+
const languageIds = ide().visibleTextEditors.map(
78+
({ document }) => document.languageId,
79+
);
80+
81+
await Promise.all(
82+
languageIds.map((languageId) => this.loadLanguage(languageId)),
83+
);
84+
}
85+
7686
public async loadLanguage(languageId: string): Promise<void> {
7787
if (this.languageDefinitions.has(languageId)) {
7888
return;

packages/cursorless-vscode/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export async function activate(
9292
runIntegrationTests,
9393
addCommandRunnerDecorator,
9494
customSpokenFormGenerator,
95-
} = createCursorlessEngine(
95+
} = await createCursorlessEngine(
9696
treeSitter,
9797
normalizedIde,
9898
hats,

0 commit comments

Comments
 (0)