Skip to content

Commit

Permalink
Check lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Jan 23, 2024
1 parent f921fdd commit ca7512e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
43 changes: 25 additions & 18 deletions denops/dpp/dpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class Dpp {
configReturn: ConfigReturn,
) {
const hasWindows = await fn.has(denops, "win32");
const hasLua = denops.meta.host === "nvim" || await fn.has(denops, "lua");

// Initialize plugins
const protocols = await this.getProtocols(denops, options);
Expand Down Expand Up @@ -165,6 +166,7 @@ export class Dpp {
recordPlugins[plugin.name] = initPlugin(
plugin,
basePath,
hasLua,
);
}

Expand Down Expand Up @@ -334,11 +336,13 @@ export class Dpp {
for await (const vimrc of inlineVimrcs) {
const vimrcLines = (await Deno.readTextFile(vimrc)).split(/\r?\n/);
if (extname(vimrc) == ".lua") {
stateLines = stateLines.concat(
["lua <<EOF"],
vimrcLines.filter((line) => !line.match(/^\s*$|^\s*--/)),
["EOF"],
);
if (hasLua) {
stateLines = stateLines.concat(
["lua <<EOF"],
vimrcLines.filter((line) => !line.match(/^\s*$|^\s*--/)),
["EOF"],
);
}
} else {
stateLines = stateLines.concat(
vimrcLines.filter((line) => !line.match(/^\s*$|^\s*"/)),
Expand Down Expand Up @@ -669,7 +673,7 @@ function protocolArgs<
return [o, p];
}

function initPlugin(plugin: Plugin, basePath: string): Plugin {
function initPlugin(plugin: Plugin, basePath: string, hasLua: boolean): Plugin {
plugin.sourced = false;

if (!plugin.path) {
Expand Down Expand Up @@ -725,16 +729,19 @@ function initPlugin(plugin: Plugin, basePath: string): Plugin {
"",
);
}

// Convert lua_xxx keys
for (
const key of Object.keys(plugin).filter((key) => key.startsWith("lua_"))
) {
const hook = key.replace(/^lua_/, "hook_");
const lua = `lua <<EOF\n${plugin[key as keyof typeof plugin]}\nEOF\n`;
if (hooks[hook]) {
hooks[hook] += "\n" + lua;
} else {
hooks[hook] = lua;
if (hasLua) {
for (
const key of Object.keys(plugin).filter((key) => key.startsWith("lua_"))
) {
const hook = key.replace(/^lua_/, "hook_");
const lua = `lua <<EOF\n${plugin[key as keyof typeof plugin]}\nEOF\n`;
if (hooks[hook]) {
hooks[hook] += "\n" + lua;
} else {
hooks[hook] = lua;
}
}
}

Expand Down Expand Up @@ -802,7 +809,7 @@ Deno.test("initPlugin", () => {
rev: "[hoge]",
script_type: "foo",
rtp: "autoload",
}, "base"),
}, "base", false),
{
name: "foo",
path: "base/repos/foo__hoge_/foo",
Expand All @@ -820,7 +827,7 @@ Deno.test("initPlugin", () => {
initPlugin({
name: "foo",
on_ft: "foo",
}, "base"),
}, "base", false),
{
name: "foo",
path: "base/repos/foo",
Expand All @@ -837,7 +844,7 @@ Deno.test("initPlugin", () => {
initPlugin({
name: "foo",
lua_add: "foo",
}, "base"),
}, "base", true),
{
name: "foo",
path: "base/repos/foo",
Expand Down
6 changes: 6 additions & 0 deletions doc/dpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -505,32 +505,38 @@ hook_source (String) or (Function)
lua_add (String)
Lua language string hook instead of Vim script.
It is converted to |dpp-plugin-option-hook_add| key.
NOTE: It works only for neovim or |+lua|.

*dpp-plugin-option-lua_depends_update*
lua_depends_update (String)
Lua language string hook instead of Vim script.
It is converted to |dpp-plugin-option-hook_depends_update|
key.
NOTE: It works only for neovim or |+lua|.

*dpp-plugin-option-lua_done_update*
lua_done_update (String)
Lua language string hook instead of Vim script.
It is converted to |dpp-plugin-option-hook_done_update| key.
NOTE: It works only for neovim or |+lua|.

*dpp-plugin-option-lua_post_source*
lua_post_sources (String)
Lua language string hook instead of Vim script.
It is converted to |dpp-plugin-option-hook_post_source| key.
NOTE: It works only for neovim or |+lua|.

*dpp-plugin-option-lua_post_update*
lua_post_update (String)
Lua language string hook instead of Vim script.
It is converted to |dpp-plugin-option-hook_post_update| key.
NOTE: It works only for neovim or |+lua|.

*dpp-plugin-option-lua_source*
lua_source (String)
Lua language string hook instead of Vim script.
It is converted to |dpp-plugin-option-hook_source| key.
NOTE: It works only for neovim or |+lua|.

------------------------------------------------------------------------------
LUA FUNCTIONS *dpp-lua-functions*
Expand Down

0 comments on commit ca7512e

Please sign in to comment.