-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathextension.ts
More file actions
60 lines (51 loc) · 2.12 KB
/
extension.ts
File metadata and controls
60 lines (51 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { NeovimClient } from "neovim/lib/api/client";
import type { NvimPlugin } from "neovim/lib/host/NvimPlugin";
import {
FakeCommandServerApi,
FakeIDE,
NormalizedIDE,
} from "@cursorless/lib-common";
import { createCursorlessEngine } from "@cursorless/lib-engine";
import { EXTENSION_ID, NeovimIDE } from "@cursorless/lib-neovim-common";
import { getNeovimRegistry } from "@cursorless/lib-neovim-registry";
import { constructTestHelpers } from "./constructTestHelpers";
import { NeovimCommandServerApi } from "./NeovimCommandServerApi";
import { registerCommands } from "./registerCommands";
/**
* This function is called from cursorless.nvim to initialize the Cursorless engine.
* NOTE: this is not the cursorless-neovim extension entrypoint (which is called at Neovim startup)
* We named it activate() in order to have the same structure as the extension entrypoint to match app-vscode
*/
export async function activate(plugin: NvimPlugin) {
const client = plugin.nvim as NeovimClient;
const neovimIDE = new NeovimIDE(client);
await neovimIDE.init();
const isTesting = neovimIDE.runMode === "test";
const normalizedIde =
neovimIDE.runMode === "production"
? neovimIDE
: new NormalizedIDE(neovimIDE, new FakeIDE(), isTesting);
const fakeCommandServerApi = new FakeCommandServerApi();
const neovimCommandServerApi = new NeovimCommandServerApi(client);
const commandServerApi = isTesting
? fakeCommandServerApi
: neovimCommandServerApi;
const { commandApi, storedTargets, hatTokenMap, scopeProvider, injectIde } =
await createCursorlessEngine({ ide: normalizedIde, commandServerApi });
await registerCommands(client, neovimIDE, commandApi, commandServerApi);
const cursorlessApi = {
testHelpers: isTesting
? constructTestHelpers(
fakeCommandServerApi,
storedTargets,
hatTokenMap,
neovimIDE,
normalizedIde as NormalizedIDE,
scopeProvider,
injectIde,
)
: undefined,
};
getNeovimRegistry().registerExtensionApi(EXTENSION_ID, cursorlessApi);
console.log("activate(): Cursorless extension loaded");
}