import { CodeSnippetsCodebaseIndex } from "../../indexing/CodeSnippetsIndex.js";
import { BaseContextProvider } from "../index.js";
const MAX_SUBMENU_ITEMS = 10_000;
class CodeContextProvider extends BaseContextProvider {
    static description = {
        title: "code",
        displayTitle: "Code",
        description: "Type to search",
        type: "submenu",
    };
    async getContextItems(query, extras) {
        // Assume the query is the id as returned by loadSubmenuItems
        return [
            await CodeSnippetsCodebaseIndex.getForId(Number.parseInt(query, 10)),
        ];
    }
    async loadSubmenuItems(args) {
        // TODO: Dynamically load submenu items based on the query
        // instead of loading everything into memory
        const tags = await args.ide.getTags("codeSnippets");
        const snippets = await Promise.all(tags.map((tag) => CodeSnippetsCodebaseIndex.getAll(tag)));
        const submenuItems = [];
        for (const snippetList of snippets.slice(-MAX_SUBMENU_ITEMS)) {
            submenuItems.push(...snippetList);
        }
        return submenuItems;
    }
}
export default CodeContextProvider;
