Skip to content

Commit 80825fb

Browse files
authored
Merge pull request #154 from vim-denops/fix-mapping
🐛 Fix parse error on "Nvim builtin"
2 parents 538bdfb + 304b1fe commit 80825fb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

denops_std/mapping/mod.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,13 @@ export async function list(
118118
): Promise<Mapping[]> {
119119
const mode = options.mode ?? "";
120120
const result = await fn.execute(denops, `${mode}map ${lhs}`) as string;
121-
return result.split(/\r?\n/).filter((v) => v).map(parse);
121+
return result.split(/\r?\n/).flatMap((v) => {
122+
try {
123+
return [parse(v)];
124+
} catch {
125+
return [];
126+
}
127+
}).filter((v) => v);
122128
}
123129

124130
function forceArray<T>(v: T | T[]): T[] {

denops_std/mapping/parser_test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,11 @@ Deno.test(`parse() throws an error for invalid record`, () => {
105105
"Failed to parse a mapping record",
106106
);
107107
});
108+
Deno.test(`parse() throws an error for "Nvim builtin"`, () => {
109+
assertThrows(
110+
() => {
111+
parse(" Nvim builtin");
112+
},
113+
"Failed to parse a mapping record",
114+
);
115+
});

0 commit comments

Comments
 (0)