Skip to content

Commit 9215717

Browse files
committed
feat: fix helptag source and previewer
1 parent 47ba4b1 commit 9215717

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

builtin/previewer/helptag.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as opt from "@denops/std/option";
22
import { join } from "@std/path/join";
3+
import { expandGlob } from "@std/fs/expand-glob";
34

45
import { definePreviewer, type Previewer } from "../../previewer.ts";
56

@@ -64,17 +65,22 @@ async function readHelpfile(
6465
return await Deno.readTextFile(helpfileCache.get(helpfile)!);
6566
}
6667
for (const runtimepath of runtimepaths) {
67-
signal?.throwIfAborted();
68-
try {
69-
const path = join(runtimepath, "doc", helpfile);
70-
const text = await Deno.readTextFile(path);
68+
for await (
69+
const { path } of expandGlob(join(runtimepath, "doc", helpfile), {
70+
includeDirs: false,
71+
})
72+
) {
7173
signal?.throwIfAborted();
74+
try {
75+
const text = await Deno.readTextFile(path);
76+
signal?.throwIfAborted();
7277

73-
helpfileCache.set(helpfile, path);
74-
return text;
75-
} catch (err) {
76-
if (isSilence(err)) continue;
77-
throw err;
78+
helpfileCache.set(helpfile, path);
79+
return text;
80+
} catch (err) {
81+
if (isSilence(err)) continue;
82+
throw err;
83+
}
7884
}
7985
}
8086
return "";

builtin/source/helptag.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as opt from "@denops/std/option";
2-
import { walk } from "@std/fs/walk";
2+
import { expandGlob } from "@std/fs/expand-glob";
33
import { join } from "@std/path/join";
44

55
import { defineSource, type Source } from "../../source.ts";
@@ -67,15 +67,17 @@ export function helptag(): Source<Detail> {
6767
async function* discoverHelptags(
6868
runtimepath: string,
6969
): AsyncGenerator<Detail> {
70-
const match = [/\/tags(?:-\w{2})?$/];
70+
const pattern = /^tags(?:-\w{2})?$/;
7171
try {
7272
for await (
73-
const { path, name } of walk(join(runtimepath, "doc"), {
73+
const { path, name } of expandGlob(join(runtimepath, "doc", "*"), {
7474
includeDirs: false,
75-
match,
7675
})
7776
) {
78-
const lang = name.match(/tags-(\w{2})$/)?.at(1);
77+
if (!pattern.test(name)) {
78+
continue;
79+
}
80+
const lang = name.match(pattern)?.at(1);
7981
for (const helptag of parseHelptags(await Deno.readTextFile(path))) {
8082
yield {
8183
...helptag,

0 commit comments

Comments
 (0)