Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions action/gin_action_execute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useEval } from "@denops/std/eval/use-eval";
import { feedkeys } from "@denops/std/function";
import { type Action, defineAction } from "@vim-fall/std/action";
import type { Detail } from "@vim-fall/extra/source/gin-action";

/**
* Execute a gin action on the current vim-gin's buffer.
*
* @param denops - The Denops instance for executing Vim commands.
* @param item - The item containing the <Plug>-mapping to invoke a gin action.
*/
export function ginActionExecute(): Action<Detail> {
return defineAction<Detail>(
async (denops, { item }, { signal }) => {
if (item) {
const key = item.detail.gin.actionKey;
signal?.throwIfAborted();
await useEval(denops, async (denops) => {
await feedkeys(denops, key, "i");
});
}
},
);
}

export const defaultGinActionExecuteActions: {
"gin-action-execute": Action<Detail>;
} = {
"gin-action-execute": ginActionExecute(),
};
1 change: 1 addition & 0 deletions action/mod.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// This file is generated by gen-mod.ts
export * from "./gin_action_execute.ts";
export * from "./mr_delete.ts";
3 changes: 3 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"exports": {
".": "./mod.ts",
"./action": "./action/mod.ts",
"./action/gin-action-execute": "./action/gin_action_execute.ts",
"./action/mr-delete": "./action/mr_delete.ts",
"./matcher": "./matcher/mod.ts",
"./matcher/kensaku": "./matcher/kensaku.ts",
Expand All @@ -12,6 +13,7 @@
"./renderer/nerdfont": "./renderer/nerdfont.ts",
"./renderer/nvim-web-devicons": "./renderer/nvim_web_devicons.ts",
"./source": "./source/mod.ts",
"./source/gin-action": "./source/gin_action.ts",
"./source/mr": "./source/mr.ts"
},
"publish": {
Expand Down Expand Up @@ -42,6 +44,7 @@
"update:commit": "deno task -q update --commit --prefix :package: --pre-commit=fmt,lint"
},
"imports": {
"@core/iterutil": "jsr:@core/iterutil@^0.9.0",
"@denops/std": "jsr:@denops/std@^7.3.0",
"@std/assert": "jsr:@std/assert@^1.0.7",
"@std/collections": "jsr:@std/collections@^1.0.9",
Expand Down
45 changes: 45 additions & 0 deletions source/gin_action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { Denops } from "@denops/std";
import { type RawString, rawString as r } from "@denops/std/eval/string";
import { enumerate } from "@core/iterutil/enumerate";
import { defineSource, type Source } from "@vim-fall/std/source";

export type Detail = {
gin: { actionKey: RawString };
};

// This function returns all of the <Plug>-mappings of gin's actions.
async function listGinMaps(denops: Denops) {
return await denops.eval(
"maplist()->filter({_, v -> stridx(v.lhs, '<Plug>(gin-action-') == 0})->map({_, v -> v.lhs})",
) as string[];
}

// This function defines a source for gin's actions mainly provided by vim-gin
// plugin.
export function ginAction(): Source<Detail> {
return defineSource(async function* (denops, _params, { signal }) {
const maps = await listGinMaps(denops);
signal?.throwIfAborted();

const allActions = maps.map((v) =>
v.match(/^<Plug>\(gin-action-(.*)\)/)![1]
);
const actions = new Set(allActions);

signal?.throwIfAborted();
allActions.filter((v) => v.endsWith("=")).forEach((v) => {
if (actions.has(v.substring(0, v.length - 1))) {
actions.delete(v);
}
});

for (const [id, action] of enumerate(actions)) {
signal?.throwIfAborted();
yield {
id,
value: action,
detail: { gin: { actionKey: r`\<Plug>(gin-action-${action})` } },
};
}
});
}
1 change: 1 addition & 0 deletions source/mod.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
// This file is generated by gen-mod.ts
export * from "./gin_action.ts";
export * from "./mr.ts";