continue-custom/core/context/providers/CodeHighlightsContextProvider.ts
Nate Sesti 53b61288ec
🎨 Refactor core (#1281)
* 🎨 refactor out react context

* 🎨 refactor local storage

* 🎨 refactor IdeMessenger

* 🔥 removing unused files

* 🚚 move scripts

* ✅ setup VSCode integration testing

* 🎨 fix test-related stuff

* 🚧 testing

* 🎨 tweak terminal cmd+L

* 🧑‍💻 install biome in core

* 🎨 run biome check on core

* 🎨 run biome check in vscode

* 🎨 run biome check in binary

* 🧑‍💻 global biome config

* 🎨 run biome check on core

* 🎨 run biome check in vscode

* 🎨 fix a few biome warnings

* 🚧 WIP on protocols

* 🚧 progress, organizing, about to remove webviewCore protocol

* 🚧 now running

* 🚧 move indexing code to core

* 🚧 WIP on JetBrains indexing implementation

* 🎨 finish listDir

* 🚧 gui fixes

* 🏷️ update IMessenger.on return type

* 🐛 fix jetbrains types + IDE detection

* 🧑‍💻 set up debugging for binary with TcpMessenger

* 👷 fix prepackage.js

* 🧑‍💻 turn off debug mode for intellij

* 🐛 merge fixes

* 🐛 fixes after refactor

* 🐛 merge fixes

* 💄 increase font size in JB

* 🔀 merge changes

* 🩹 small fixes

* 🐛 fix jetbrains build

* 🩹 more jetbrains fixes

* 🎨 jetbrains improvements

* 🐛 fix lancedb prob in jetbrains build

* 👷 update jetbrains build process

* ✨ intellij problems context provider

* 👷 add script utils file

* 💚 fix jetbrains build regression

* 🎨 dynamic import transformers.js

* 🩹 small jetbrains updates

* ✨ folder context provider in jetbrains

* 🎨 many more jetbrains improvements

* 🔀 merge fixes

* ⚡️ small improvements

* 🎨 tell users transformers.js not supported

* 🎨 trial updates

* 📝 update jetbrains readmej

* ⚡️ only use smaller context for local autocomplete models

* ⚡️ improve bracket filter

* ✨ global .continue/.prompts folder

* 💄 improved model setup process

* 🥅 display VSCode req errs
2024-05-24 19:38:13 -07:00

67 lines
1.9 KiB
TypeScript

import {
ContextItem,
ContextProviderDescription,
ContextProviderExtras,
} from "../../index.js";
import { getBasename } from "../../util/index.js";
import { BaseContextProvider } from "../index.js";
// import { getHighlightsThatFit, ILLMContextSizer } from "llm-code-highlighter/dist/index.continue";
const HIGHLIGHTS_TOKEN_BUDGET = 2000;
class CodeHighlightsContextProvider extends BaseContextProvider {
static description: ContextProviderDescription = {
title: "highlights",
displayTitle: "Highlights",
description: "Code highlights from open files",
type: "normal",
};
async getContextItems(
query: string,
extras: ContextProviderExtras,
): Promise<ContextItem[]> {
const ide = extras.ide;
const openFiles = await ide.getOpenFiles();
const allFiles: { name: string; absPath: string; content: string }[] =
await Promise.all(
openFiles.map(async (filepath: string) => {
return {
name: getBasename(filepath),
absPath: filepath,
content: `${await ide.readFile(filepath)}`,
};
}),
);
// const contextSizer = {
// fits(content: string): boolean {
// return countTokens(content, "") < HIGHLIGHTS_TOKEN_BUDGET;
// }
// } as ILLMContextSizer
// const repoMap = await getHighlightsThatFit(
// contextSizer,
// [],
// allFiles
// .filter((file) => file.content.length > 0)
// .map((file) => {
// return {
// relPath: file.name,
// code: file.content,
// };
// })
// );
// return [
// {
// content: repoMap ? repoMap : "",
// name: "Code Highlights",
// description: "Code highlights from open files",
// },
// ];
return [];
}
async load(): Promise<void> {}
}
export default CodeHighlightsContextProvider;