Skip to content

Commit 7b28d64

Browse files
committed
feat: add quickfix source
1 parent c123789 commit 7b28d64

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

builtin/source/quickfix.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { enumerate } from "@core/iterutil/enumerate";
2+
import * as fn from "@denops/std/function";
3+
4+
import { defineSource, type Source } from "../../source.ts";
5+
6+
type Detail = {
7+
bufnr: number;
8+
line: number;
9+
column: number;
10+
quickfix: QuickfixItem;
11+
};
12+
13+
/**
14+
* Provides a source for recently accessed files.
15+
*
16+
* This source fetches the list of old files stored in the `v:oldfiles` variable
17+
* in Vim/Neovim and yields them with each file’s path as `Detail`.
18+
*
19+
* @returns A source that yields recently accessed files.
20+
*/
21+
export function quickfix(): Source<Detail> {
22+
return defineSource(async function* (denops, _params, { signal }) {
23+
const qflist = await fn.getqflist(denops) as unknown as QuickfixItem[];
24+
signal?.throwIfAborted();
25+
for (const [id, item] of enumerate(qflist)) {
26+
const length = (item.end_col ?? 0) - item.col;
27+
const decorations = length > 0 ? [{ column: item.col, length }] : [];
28+
yield {
29+
id,
30+
value: item.text,
31+
detail: {
32+
bufnr: item.bufnr,
33+
line: item.lnum,
34+
column: item.col,
35+
quickfix: item,
36+
},
37+
decorations,
38+
};
39+
}
40+
});
41+
}
42+
43+
type QuickfixItem = {
44+
bufnr: number;
45+
module: string;
46+
lnum: number;
47+
end_lnum?: number;
48+
col: number;
49+
end_col?: number;
50+
vcol: boolean;
51+
nr: number;
52+
pattern: string;
53+
text: string;
54+
type: string;
55+
valid: boolean;
56+
user_data: unknown;
57+
};

0 commit comments

Comments
 (0)