Skip to content

Commit f2995f7

Browse files
committed
💥 Remove "variables" entry from dict getbufnr() returns
`getbufnr()` function have dictionaries of buffer local variables in its return value. Therefore, when there's a funcref in buffer local variables, denops will fail to send the return value back to the deno world. This behavior is inconvenient, make denops-std's `getbufnr()` omit the "variables" entries from the return value.
1 parent c3719e6 commit f2995f7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

function/buffer.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ export async function deletebufline(
414414
* name sign name
415415
* variables A reference to the dictionary with
416416
* buffer-local variables.
417+
* CAUTION: Different from the builtin getbufnr()
418+
* function, denops-std's getbufnr() function doesn't
419+
* return this entry.
417420
* windows List of `window-ID`s that display this
418421
* buffer
419422
* popups List of popup `window-ID`s that
@@ -437,6 +440,10 @@ export async function deletebufline(
437440
* Can also be used as a `method`:
438441
*
439442
* GetBufnr()->getbufinfo()
443+
*
444+
* CAUTION: Different from the builtin getbufnr() function, denops-std's
445+
* getbufnr() function omits the "variables" entry from the returned
446+
* dictionary.
440447
*/
441448
export function getbufinfo(
442449
denops: Denops,
@@ -450,7 +457,12 @@ export async function getbufinfo(
450457
denops: Denops,
451458
...args: unknown[]
452459
): Promise<BufInfo[]> {
453-
const bufinfos = await denops.call("getbufinfo", ...args) as Record<
460+
const bufinfos = await denops.eval(
461+
"map(call('getbufinfo', l:args), {_, v -> filter(v, {k -> k !=# 'variables'})})",
462+
{
463+
args: args,
464+
},
465+
) as Record<
454466
keyof BufInfo,
455467
unknown
456468
>[];

function/buffer_test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals } from "@std/assert";
1+
import { assertEquals, assertFalse } from "@std/assert";
22
import { assert, is } from "@core/unknownutil";
33
import { test } from "@denops/test";
44
import type { BufInfo } from "./types.ts";
@@ -61,5 +61,17 @@ test({
6161
},
6262
});
6363
await denops.cmd("1,$bwipeout!");
64+
65+
await t.step({
66+
name: "getbufinfo() will filter buffer-local variables",
67+
fn: async () => {
68+
await denops.cmd("enew!");
69+
await denops.cmd("let b:var = 0");
70+
71+
const actual = await buffer.getbufinfo(denops);
72+
assertEquals(actual.length, 1);
73+
assertFalse("variables" in actual[0]);
74+
},
75+
});
6476
},
6577
});

0 commit comments

Comments
 (0)