continue-custom/core/context/providers/OpenFilesContextProvider.ts
Bjørn Jørgensen 1d14eb46ef
Prefer using nullish coalescing operator (??) instead of a logical or (#922)
* Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.

* index.ts

* more...

* more..

* indenting

* fix indenting
2024-03-08 22:41:04 -08:00

39 lines
1.1 KiB
TypeScript

import { BaseContextProvider } from "..";
import {
ContextItem,
ContextProviderDescription,
ContextProviderExtras,
} from "../..";
import { getBasename } from "../../util";
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;