-
-
Notifications
You must be signed in to change notification settings - Fork 199
/
dein.ts
67 lines (57 loc) · 1.5 KB
/
dein.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import {
ActionArguments,
ActionFlags,
BaseSource,
DduItem,
Item,
} from "https://deno.land/x/[email protected]/types.ts";
import { Denops } from "https://deno.land/x/[email protected]/deps.ts";
import { ActionData } from "https://deno.land/x/[email protected]/file.ts";
type Params = Record<string, never>;
type Action = {
path: string;
__name: string;
};
type Dein = {
name: string;
path: string;
};
export class Source extends BaseSource<Params> {
override kind = "file";
override gather(args: {
denops: Denops;
sourceParams: Params;
}): ReadableStream<Item<ActionData>[]> {
return new ReadableStream({
async start(controller) {
const deins = Object.values(
await args.denops.call("dein#get") as Record<string, Dein>,
);
const items = deins.map((dein) => {
return {
word: dein.name,
action: {
path: dein.path,
__name: dein.name,
} as Action,
};
});
controller.enqueue(items);
controller.close();
},
});
}
override actions: Record<
string,
(args: ActionArguments<Params>) => Promise<ActionFlags>
> = {
update: async (args: { denops: Denops; items: DduItem[] }) => {
const plugins = args.items.map((item) => (item.action as Action).__name);
await args.denops.call("dein#update", plugins);
return Promise.resolve(ActionFlags.None);
},
};
override params(): Params {
return {};
}
}