Skip to content

Commit c65c10f

Browse files
committed
Start making factory for vscodeIde
1 parent 657ac28 commit c65c10f

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as vscode from "vscode";
2+
import { VscodeHats, VscodeIDE } from "..";
3+
4+
export async function createVscodeIde(context: vscode.ExtensionContext) {
5+
const vscodeIDE = new VscodeIDE(context);
6+
7+
const hats = new VscodeHats(vscodeIDE, context);
8+
await hats.init();
9+
return { vscodeIDE, hats };
10+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from "./ide/vscode/VscodeIDE";
44
export * from "./ide/vscode/hats/VscodeHats";
55
export * from "./ide/vscode/toVscodeEditor";
66
export * from "./keyboard/KeyboardCommands";
7+
export * from "./compositionRoot/createVscodeIde";

packages/cursorless-vscode/src/extension.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import {
1212
} from "@cursorless/cursorless-engine";
1313
import {
1414
commandIds,
15+
createVscodeIde,
1516
KeyboardCommands,
1617
StatusBarItem,
17-
VscodeHats,
18-
VscodeIDE,
1918
} from "@cursorless/cursorless-vscode-core";
2019
import {
2120
CursorlessApi,
2221
getCommandServerApi,
2322
getParseTreeApi,
23+
ParseTreeApi,
2424
toVscodeRange,
2525
} from "@cursorless/vscode-common";
2626
import * as vscode from "vscode";
@@ -40,23 +40,14 @@ export async function activate(
4040
): Promise<CursorlessApi> {
4141
const parseTreeApi = await getParseTreeApi();
4242

43-
const vscodeIDE = new VscodeIDE(context);
44-
45-
const hats = new VscodeHats(vscodeIDE, context);
46-
await hats.init();
43+
const { vscodeIDE, hats } = await createVscodeIde(context);
4744

4845
const commandServerApi =
4946
vscodeIDE.runMode === "test"
5047
? getFakeCommandServerApi()
5148
: await getCommandServerApi();
5249

53-
const getNodeAtLocation = (document: TextDocument, range: Range) => {
54-
return parseTreeApi.getNodeAtLocation(
55-
new vscode.Location(document.uri, toVscodeRange(range)),
56-
);
57-
};
58-
59-
const treeSitter: TreeSitter = { getNodeAtLocation };
50+
const treeSitter: TreeSitter = createTreeSitter(parseTreeApi);
6051

6152
const normalizedIde =
6253
vscodeIDE.runMode === "production"
@@ -112,6 +103,16 @@ export async function activate(
112103
};
113104
}
114105

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+
115116
// this method is called when your extension is deactivated
116117
export function deactivate() {
117118
// do nothing

0 commit comments

Comments
 (0)