Skip to content

Commit 1393fbe

Browse files
committed
Add 'defaultValue' to fix #5
1 parent dcbb49a commit 1393fbe

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

vim/variable.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ export async function getVar<T = unknown>(
1616
denops: Denops,
1717
group: VariableGroups,
1818
prop: string,
19-
): Promise<T> {
20-
const name = `${group}:${prop}`;
19+
defaultValue?: T,
20+
): Promise<T | null> {
21+
const result = await denops.eval(`get(${group}:, name, value)`, {
22+
name: prop,
23+
value: defaultValue ?? null,
24+
});
2125
// deno-lint-ignore no-explicit-any
22-
return (await denops.eval(name)) as any;
26+
return result as any;
2327
}
2428

2529
export async function setVar<T = unknown>(
@@ -52,8 +56,8 @@ export class VariableHelper {
5256
this.#group = group;
5357
}
5458

55-
async get<T = unknown>(prop: string): Promise<T> {
56-
return await getVar(this.#denops, this.#group, prop);
59+
async get<T = unknown>(prop: string, defaultValue?: T): Promise<T | null> {
60+
return await getVar(this.#denops, this.#group, prop, defaultValue);
5761
}
5862

5963
async set<T = unknown>(prop: string, value: T): Promise<void> {

0 commit comments

Comments
 (0)