forked from continuedev/continue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenFilesContextProvider.ts
39 lines (36 loc) · 1.08 KB
/
OpenFilesContextProvider.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
import { BaseContextProvider } from "../index.js";
import {
ContextItem,
ContextProviderDescription,
ContextProviderExtras,
} from "../../index.js";
import { getBasename } from "../../util/index.js";
class OpenFilesContextProvider extends BaseContextProvider {
static description: ContextProviderDescription = {
title: "open",
displayTitle: "Open Files",
description: "Reference the current open files",
type: "normal",
};
async getContextItems(
query: string,
extras: ContextProviderExtras,
): Promise<ContextItem[]> {
const ide = extras.ide;
const openFiles = this.options?.onlyPinned
? await ide.getPinnedFiles()
: await ide.getOpenFiles();
return await Promise.all(
openFiles.map(async (filepath: string) => {
return {
description: filepath,
content: `\`\`\`${getBasename(filepath)}\n${await ide.readFile(
filepath,
)}\n\`\`\``,
name: (filepath.split("/").pop() ?? "").split("\\").pop() ?? "",
};
}),
);
}
}
export default OpenFilesContextProvider;