Skip to content

Commit d95cd0c

Browse files
committed
Fix hooks check
1 parent a6d53c8 commit d95cd0c

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

denops/dpp/types.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ export type Plugin = {
5252
extAttrs?: unknown;
5353
external_commands?: string | string[];
5454
ftplugin?: Record<string, string>;
55+
group?: string | string[];
5556
hook_add?: string;
5657
hook_depends_update?: string;
5758
hook_done_update?: string;
59+
hook_post_check_update?: string;
5860
hook_post_source?: string;
5961
hook_post_update?: string;
6062
hook_pre_update?: string;
61-
hook_post_check_update?: string;
6263
hook_source?: string;
6364
hooks_file?: string | string[];
6465
if?: boolean | string;
65-
group?: string | string[];
6666
lazy?: boolean;
6767
local?: boolean;
6868
lua_add?: string;
@@ -92,3 +92,14 @@ export type Plugin = {
9292
sourced?: boolean;
9393
url?: string;
9494
};
95+
96+
export const Hooks: Set<string> = new Set([
97+
"add",
98+
"depends_update",
99+
"done_update",
100+
"post_check_update",
101+
"post_source",
102+
"post_update",
103+
"pre_update",
104+
"source",
105+
]);

denops/dpp/utils.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Plugin } from "./types.ts";
1+
import { Hooks, type Plugin } from "./types.ts";
22

33
import type { Denops } from "@denops/std";
44

@@ -186,12 +186,15 @@ export function parseHooksFile(
186186
nestedCount++;
187187

188188
hookName = match.groups.hookName;
189-
if (
190-
hookName.startsWith("hook_") ||
191-
hookName.startsWith("lua_")
192-
) {
193-
dest = options;
194-
} else {
189+
if (hookName.startsWith("hook_") || hookName.startsWith("lua_")) {
190+
// Check Hooks.
191+
const checkHook = hookName.replace(/^hook_|^lua_/, "");
192+
if (Hooks.has(checkHook)) {
193+
dest = options;
194+
}
195+
}
196+
197+
if (!dest) {
195198
// Use ftplugin
196199
dest = ftplugin;
197200
}
@@ -411,8 +414,9 @@ Deno.test("parseHooksFile", () => {
411414
"-- }}}",
412415
]),
413416
{
414-
lua_hoge: "piyo",
415-
ftplugin: {},
417+
ftplugin: {
418+
lua_hoge: "piyo",
419+
},
416420
},
417421
);
418422
});

0 commit comments

Comments
 (0)