Skip to content

Commit

Permalink
feat: get talon.nvim and assets path
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric Halbronn committed Mar 27, 2024
1 parent 94c3ec4 commit 54f9728
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/cursorless-neovim/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export async function activate(context: NeovimExtensionContext) {

async function createNeovimIde(context: ExtensionContext) {
const neovimIDE = new NeovimIDE(context);
await neovimIDE.init();

const hats = new NeovimHats(neovimIDE, context);
await hats.init();
Expand Down
25 changes: 24 additions & 1 deletion packages/cursorless-neovim/src/ide/neovim/NeovimIDE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import NeovimGlobalState from "./NeovimGlobalState";
import NeovimMessages from "./NeovimMessages";
import { Window } from "neovim";
import { NeovimTextEditorImpl } from "./NeovimTextEditorImpl";
import { NeovimExtensionContext } from "./NeovimExtensionContext";
import { getTalonNvimPath } from "../../neovimApi";
import path from "path";

export class NeovimIDE implements IDE {
readonly configuration: NeovimConfiguration;
Expand All @@ -50,6 +53,7 @@ export class NeovimIDE implements IDE {
workspaceFolders: readonly WorkspaceFolder[] | undefined = undefined;
private disposables: Disposable[] = [];
private assetsRoot_: string | undefined;
private cursorlessNeovimPath: string | undefined;
private quickPickReturnValue: string | undefined = undefined;

constructor(private extensionContext: ExtensionContext) {
Expand All @@ -60,7 +64,26 @@ export class NeovimIDE implements IDE {
this.capabilities = new NeovimCapabilities();
this.editorMap = new Map<Window, NeovimTextEditorImpl>();
this.activeWindow = undefined;
//this.assetsRoot_ = "C:\\"; // TODO: fix but not needed for now as used by snippets and cheatsheet only?
}

async init() {
const client = (this.extensionContext as NeovimExtensionContext).client;
const talonNvimPath = await getTalonNvimPath(client);
// talon-nvim path: C:\Users\User\AppData\Local\nvim-data\lazy\talon.nvim
// we store the assets into a subfolder of talon.nvim
this.assetsRoot_ = path.join(talonNvimPath, "assets");
// development cursorless-neovim path: C:\Users\User\AppData\Local\nvim\rplugin\node\cursorless-neovim
// TODO: we will need to change this once all the files are in talon.nvim/
this.cursorlessNeovimPath = path.join(
talonNvimPath,
"..",
"..",
"..",
"nvim",
"rplugin",
"node",
"cursorless-neovim",
);
}

async showQuickPick(
Expand Down
9 changes: 8 additions & 1 deletion packages/cursorless-neovim/src/neovimApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,18 @@ export async function windowGetVisibleRanges(
];
}

export async function getTalonNvimPath(client: NeovimClient): Promise<string> {
const luaCode = `return require("talon.utils").talon_nvim_path()`;
const data = await client.executeLua(luaCode, []);
// TODO: is there a better way to cast that?
return data as unknown as string;
}

export async function putToClipboard(data: string, client: NeovimClient) {
await client.callFunction("setreg", ["*", data]);
}

// TODO: this hasn't been tested yet
// TODO: this hasn't been tested yet and will be once we test "paste to row one" commands
export async function getFromClipboard(client: NeovimClient): Promise<string> {
const luaCode = `return require("talon.cursorless").get_from_clipboard()`;
const data = await client.executeLua(luaCode, []);
Expand Down

0 comments on commit 54f9728

Please sign in to comment.