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