Skip to content

Commit c5bc19b

Browse files
committed
feat: throw error on invalid picker params
1 parent e6be1c3 commit c5bc19b

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

denops/fall/config/item_picker.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Denops } from "jsr:@denops/std@^7.3.0";
22
import type { Curator } from "jsr:@vim-fall/std@^0.1.0/curator";
3+
import type { Action } from "jsr:@vim-fall/std@^0.1.0/action";
34
import type { CollectParams, Source } from "jsr:@vim-fall/std@^0.1.0/source";
45
import type { Matcher, MatchParams } from "jsr:@vim-fall/std@^0.1.0/matcher";
56
import type {
@@ -45,6 +46,7 @@ export const defineItemPickerFromSource: DefineItemPickerFromSource = (
4546
if (itemPickerParamsMap.has(name)) {
4647
throw new Error(`Item picker "${name}" is already defined.`);
4748
}
49+
validatePickerName(name);
4850
const derivedParams = omitUndefinedAttributes({
4951
actions: deriveMap(params.actions) as Actions,
5052
defaultAction: params.defaultAction,
@@ -55,6 +57,7 @@ export const defineItemPickerFromSource: DefineItemPickerFromSource = (
5557
coordinator: derive(params.coordinator),
5658
theme: derive(params.theme),
5759
});
60+
validateActions(derivedParams.actions);
5861
itemPickerParamsMap.set(name, {
5962
...derivedParams,
6063
name,
@@ -67,9 +70,7 @@ export const defineItemPickerFromCurator: DefineItemPickerFromCurator = (
6770
curator,
6871
params,
6972
) => {
70-
if (itemPickerParamsMap.has(name)) {
71-
throw new Error(`Item picker "${name}" is already defined.`);
72-
}
73+
validatePickerName(name);
7374
const source = new CuratorSourceMatcher(derive(curator));
7475
const derivedParams = omitUndefinedAttributes({
7576
actions: deriveMap(params.actions) as Actions,
@@ -80,6 +81,7 @@ export const defineItemPickerFromCurator: DefineItemPickerFromCurator = (
8081
coordinator: derive(params.coordinator),
8182
theme: derive(params.theme),
8283
});
84+
validateActions(derivedParams.actions);
8385
itemPickerParamsMap.set(name, {
8486
...derivedParams,
8587
name,
@@ -131,3 +133,20 @@ function omitUndefinedAttributes<
131133
Object.entries(map).filter(([, v]) => v !== undefined),
132134
) as R;
133135
}
136+
137+
function validatePickerName(name: string): void {
138+
if (itemPickerParamsMap.has(name)) {
139+
throw new Error(`Item picker "${name}" is already defined.`);
140+
}
141+
if (name.startsWith("@")) {
142+
throw new Error(`Name "${name}" must not start with "@".`);
143+
}
144+
}
145+
146+
function validateActions(actions: Record<string, Action<unknown>>): void {
147+
Object.entries(actions).forEach(([name, _action]) => {
148+
if (name.startsWith("@")) {
149+
throw new Error(`Action name "${name}" must not start with "@".`);
150+
}
151+
});
152+
}

0 commit comments

Comments
 (0)