Skip to content

Commit 20ae7c4

Browse files
committed
Start making factory for vscodeIde
1 parent f4347e7 commit 20ae7c4

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as vscode from "vscode";
2+
import { VscodeHats, VscodeIDE } from "..";
3+
import { FakeFontMeasurements } from "../ide/vscode/hats/FakeFontMeasurements";
4+
import { FontMeasurementsImpl } from "../ide/vscode/hats/FontMeasurementsImpl";
5+
6+
export async function createVscodeIde(context: vscode.ExtensionContext) {
7+
const vscodeIDE = new VscodeIDE(context);
8+
9+
const hats = new VscodeHats(
10+
vscodeIDE,
11+
context,
12+
vscodeIDE.runMode === "test"
13+
? new FakeFontMeasurements()
14+
: new FontMeasurementsImpl(context),
15+
);
16+
await hats.init();
17+
18+
return { vscodeIDE, hats };
19+
}

packages/cursorless-vscode-core/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export * from "./StatusBarItem";
22
export * from "./commands";
33
export * from "./ide/vscode/VscodeIDE";
44
export * from "./ide/vscode/hats/VscodeHats";
5-
export * from "./ide/vscode/hats/FontMeasurementsImpl";
6-
export * from "./ide/vscode/hats/FakeFontMeasurements";
75
export * from "./ide/vscode/toVscodeEditor";
86
export * from "./keyboard/KeyboardCommands";
7+
export * from "./compositionRoot/createVscodeIde";

packages/cursorless-vscode/src/extension.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ import {
1111
TreeSitter,
1212
} from "@cursorless/cursorless-engine";
1313
import {
14-
FakeFontMeasurements,
15-
FontMeasurementsImpl,
14+
createVscodeIde,
1615
KeyboardCommands,
1716
StatusBarItem,
18-
VscodeHats,
19-
VscodeIDE,
2017
} from "@cursorless/cursorless-vscode-core";
2118
import {
2219
CursorlessApi,
2320
getCommandServerApi,
2421
getParseTreeApi,
22+
ParseTreeApi,
2523
toVscodeRange,
2624
} from "@cursorless/vscode-common";
2725
import * as vscode from "vscode";
@@ -41,28 +39,14 @@ export async function activate(
4139
): Promise<CursorlessApi> {
4240
const parseTreeApi = await getParseTreeApi();
4341

44-
const vscodeIDE = new VscodeIDE(context);
45-
46-
const hats = new VscodeHats(
47-
vscodeIDE,
48-
context,
49-
vscodeIDE.runMode === "test"
50-
? new FakeFontMeasurements()
51-
: new FontMeasurementsImpl(context),
52-
);
42+
const { vscodeIDE, hats } = await createVscodeIde(context);
5343

5444
const commandServerApi =
5545
vscodeIDE.runMode === "test"
5646
? getFakeCommandServerApi()
5747
: await getCommandServerApi();
5848

59-
const getNodeAtLocation = (document: TextDocument, range: Range) => {
60-
return parseTreeApi.getNodeAtLocation(
61-
new vscode.Location(document.uri, toVscodeRange(range)),
62-
);
63-
};
64-
65-
const treeSitter: TreeSitter = { getNodeAtLocation };
49+
const treeSitter: TreeSitter = createTreeSitter(parseTreeApi);
6650

6751
const normalizedIde =
6852
vscodeIDE.runMode === "production"
@@ -119,6 +103,16 @@ export async function activate(
119103
};
120104
}
121105

106+
function createTreeSitter(parseTreeApi: ParseTreeApi): TreeSitter {
107+
return {
108+
getNodeAtLocation(document: TextDocument, range: Range) {
109+
return parseTreeApi.getNodeAtLocation(
110+
new vscode.Location(document.uri, toVscodeRange(range)),
111+
);
112+
},
113+
};
114+
}
115+
122116
// this method is called when your extension is deactivated
123117
export function deactivate() {
124118
// do nothing

0 commit comments

Comments
 (0)