fix: Promise arrays being returned. Added a new definitions-only context provider. fix: typescript tagging. (#835)
* fix async bug, fix import * added definitions only context provider * npm bump dependency
This commit is contained in:
parent
31cd863e7f
commit
00eeb00241
4 changed files with 64 additions and 6 deletions
|
|
@ -6,7 +6,7 @@ import {
|
|||
} from "../..";
|
||||
import { getBasename } from "../../util";
|
||||
|
||||
const highlighterPromise = import("llm-code-highlighter/dist/index.continue");
|
||||
import { getSourceSetHighlights } from "llm-code-highlighter/dist/index.continue";
|
||||
|
||||
class CodeHighlightsContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
@ -33,8 +33,7 @@ class CodeHighlightsContextProvider extends BaseContextProvider {
|
|||
})
|
||||
);
|
||||
const topPercentile = 0.5;
|
||||
const highlighter = await highlighterPromise;
|
||||
const repoMap = await highlighter.getRepoHighlights(
|
||||
const repoMap = await getSourceSetHighlights(
|
||||
topPercentile,
|
||||
[],
|
||||
allFiles
|
||||
|
|
|
|||
57
core/context/providers/CodeOutlineContextProvider.ts
Normal file
57
core/context/providers/CodeOutlineContextProvider.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { getBasename } from "../../util";
|
||||
|
||||
import { getFileOutlineHighlights } from "llm-code-highlighter/dist/index.continue";
|
||||
|
||||
class CodeOutlineContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
title: "outlines",
|
||||
displayTitle: "Outlines",
|
||||
description: "Definition lines only (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 outlines = await getFileOutlineHighlights(
|
||||
allFiles
|
||||
.filter((file) => file.content.length > 0)
|
||||
.map((file) => {
|
||||
return {
|
||||
relPath: file.name,
|
||||
code: file.content,
|
||||
};
|
||||
})
|
||||
);
|
||||
return [
|
||||
{
|
||||
content: outlines ? outlines : "",
|
||||
name: "Code Outline",
|
||||
description: "Definition lines only (from open files)",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
async load(): Promise<void> {}
|
||||
}
|
||||
|
||||
export default CodeOutlineContextProvider;
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import { ContextProviderName } from "../..";
|
||||
import CodebaseContextProvider from "./CodebaseContextProvider";
|
||||
// import CodeHighlightsContextProvider from "./CodeHighlightsContextProvider";
|
||||
import CodeHighlightsContextProvider from "./CodeHighlightsContextProvider";
|
||||
import CodeOutlineContextProvider from "./CodeOutlineContextProvider";
|
||||
import DiffContextProvider from "./DiffContextProvider";
|
||||
import DocsContextProvider from "./DocsContextProvider";
|
||||
import FileTreeContextProvider from "./FileTreeContextProvider";
|
||||
|
|
@ -29,7 +30,8 @@ const Providers: (typeof BaseContextProvider)[] = [
|
|||
ProblemsContextProvider,
|
||||
FolderContextProvider,
|
||||
DocsContextProvider,
|
||||
// CodeHighlightsContextProvider,
|
||||
CodeHighlightsContextProvider,
|
||||
CodeOutlineContextProvider,
|
||||
];
|
||||
|
||||
export function contextProviderClassFromName(
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
"fastest-levenshtein": "^1.0.16",
|
||||
"handlebars": "^4.7.8",
|
||||
"js-tiktoken": "^1.0.8",
|
||||
"llm-code-highlighter": "^0.0.3",
|
||||
"llm-code-highlighter": "^0.0.5",
|
||||
"node-fetch": "^3.3.2",
|
||||
"node-html-markdown": "^1.3.0",
|
||||
"ollama": "^0.4.6",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue