diff --git a/core/config/default.ts b/core/config/default.ts index caecd965d..69b11ce01 100644 --- a/core/config/default.ts +++ b/core/config/default.ts @@ -56,6 +56,7 @@ const defaultConfig: SerializedContinueConfig = { params: {}, }, { name: "terminal", params: {} }, + { name: "problems", params: {} }, ], }; diff --git a/core/context/providers/ProblemsContextProvider.ts b/core/context/providers/ProblemsContextProvider.ts new file mode 100644 index 000000000..4ac143fff --- /dev/null +++ b/core/context/providers/ProblemsContextProvider.ts @@ -0,0 +1,52 @@ +import { BaseContextProvider } from ".."; +import { + ContextItem, + ContextProviderDescription, + ContextProviderExtras, +} from "../.."; +import { ExtensionIde } from "../../ide"; +import { getBasename } from "../../util"; + +class ProblemsContextProvider extends BaseContextProvider { + static description: ContextProviderDescription = { + title: "problems", + displayTitle: "Problems", + description: "Reference problems in the current file", + dynamic: true, + requiresQuery: false, + }; + + async getContextItems( + query: string, + extras: ContextProviderExtras + ): Promise { + const ide = new ExtensionIde(); + const problems = await ide.getProblems(); + + const items = await Promise.all( + problems.map(async (problem) => { + const content = await ide.readFile(problem.filepath); + const lines = content.split("\n"); + const rangeContent = lines + .slice( + Math.max(0, problem.range.start.line - 2), + problem.range.end.line + 2 + ) + .join("\n"); + + return { + description: "Problems in current file", + content: `\`\`\`${getBasename( + problem.filepath + )}\n${rangeContent}\n\`\`\`\n${problem.message}\n\n`, + name: `Warning in ${getBasename(problem.filepath)}`, + }; + }) + ); + + return items; + } + async load(): Promise {} +} + +export default ProblemsContextProvider; diff --git a/core/context/providers/index.ts b/core/context/providers/index.ts index 9246518a1..59666b679 100644 --- a/core/context/providers/index.ts +++ b/core/context/providers/index.ts @@ -7,6 +7,7 @@ import GitHubIssuesContextProvider from "./GitHubIssuesContextProvider"; import GoogleContextProvider from "./GoogleContextProvider"; import HttpContextProvider from "./HttpContextProvider"; import OpenFilesContextProvider from "./OpenFilesContextProvider"; +import ProblemsContextProvider from "./ProblemsContextProvider"; import SearchContextProvider from "./SearchContextProvider"; import TerminalContextProvider from "./TerminalContextProvider"; import URLContextProvider from "./URLContextProvider"; @@ -22,6 +23,7 @@ const Providers: (typeof BaseContextProvider)[] = [ HttpContextProvider, SearchContextProvider, CodebaseContextProvider, + ProblemsContextProvider, ]; export function contextProviderClassFromName( diff --git a/core/ide/filesystem.ts b/core/ide/filesystem.ts index 21c8bd698..5104c09b8 100644 --- a/core/ide/filesystem.ts +++ b/core/ide/filesystem.ts @@ -1,5 +1,5 @@ import * as fs from "fs"; -import { DiffLine, IDE, SerializedContinueConfig } from ".."; +import { DiffLine, IDE, Problem, SerializedContinueConfig } from ".."; import { Chunk } from "../index"; import { getConfigJsonPath, @@ -108,6 +108,10 @@ class FileSystemIde implements IDE { return ""; } + async getProblems(filepath?: string | undefined): Promise { + return Promise.resolve([]); + } + async subprocess(command: string): Promise<[string, string]> { return ["", ""]; } diff --git a/core/ide/index.ts b/core/ide/index.ts index b6b6f4297..706111847 100644 --- a/core/ide/index.ts +++ b/core/ide/index.ts @@ -1,4 +1,4 @@ -import { Chunk, DiffLine } from ".."; +import { Chunk, DiffLine, Problem } from ".."; import { IDE, SerializedContinueConfig } from "../index"; import { ideRequest } from "./messaging"; @@ -88,6 +88,10 @@ export class ExtensionIde implements IDE { return r("getSearchResults", { query }); } + getProblems(filepath?: string | undefined): Promise { + return r("getProblems", { filepath }); + } + subprocess(command: string): Promise<[string, string]> { return r("subprocess", { command }); } diff --git a/core/index.d.ts b/core/index.d.ts index c09a14b39..ad8e45da1 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -263,6 +263,12 @@ export interface DiffLine { line: string; } +export class Problem { + filepath: string; + range: Range; + message: string; +} + export interface IDE { getSerializedConfig(): Promise; getConfigJsUrl(): Promise; @@ -291,6 +297,7 @@ export interface IDE { getOpenFiles(): Promise; getSearchResults(query: string): Promise; subprocess(command: string): Promise<[string, string]>; + getProblems(filepath?: string | undefined): Promise; // Embeddings /** @@ -357,7 +364,8 @@ type ContextProviderName = | "url" | "tree" | "http" - | "codebase"; + | "codebase" + | "problems"; type TemplateType = | "llama2" diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 08569fc41..9916e35e5 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -850,7 +850,8 @@ "search", "url", "http", - "codebase" + "codebase", + "problems" ], "markdownEnumDescriptions": [ "Reference the contents of the current changes as given by `git diff`", @@ -858,7 +859,9 @@ "Reference the contents of all open files.", "Enter a search phrase and include the Google search results as context", "Enter a URL and use the contents of the webpage as context", - "Write a custom context provider at your own HTTP endpoint. Set 'url' in the params object for the endpoint you have setup." + "Write a custom context provider at your own HTTP endpoint. Set 'url' in the params object for the endpoint you have setup.", + "Use embeddings to automatically find relevant files from throughout the codebase", + "Reference all linting errors and warnings in the currently open file" ], "type": "string" }, diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index 583c087df..d51711fab 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -415,6 +415,10 @@ export function getSidebarContent( ); break; } + case "getProblems": { + respond(await ide.getProblems(data.message.filepath)); + break; + } case "getOpenFiles": { respond(await ide.getOpenFiles()); break; diff --git a/extensions/vscode/src/ideProtocol.ts b/extensions/vscode/src/ideProtocol.ts index 96d4910fe..e4ccaa704 100644 --- a/extensions/vscode/src/ideProtocol.ts +++ b/extensions/vscode/src/ideProtocol.ts @@ -18,6 +18,7 @@ import { ContinueConfig, DiffLine, IDE, + Problem, SerializedContinueConfig, } from "core"; import { @@ -315,6 +316,28 @@ class VsCodeIde implements IDE { return results.join("\n\n"); } + async getProblems(filepath?: string | undefined): Promise { + const uri = filepath + ? vscode.Uri.file(filepath) + : vscode.window.activeTextEditor?.document.uri; + if (!uri) { + return []; + } + return vscode.languages.getDiagnostics(uri).map((d) => { + return { + filepath: uri.fsPath, + range: { + start: { + line: d.range.start.line, + character: d.range.start.character, + }, + end: { line: d.range.end.line, character: d.range.end.character }, + }, + message: d.message, + }; + }); + } + async subprocess(command: string): Promise<[string, string]> { return new Promise((resolve, reject) => { exec(command, (error, stdout, stderr) => { diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 1d23b6442..dbdd73049 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -7,6 +7,7 @@ import { Cog6ToothIcon, CommandLineIcon, ExclamationCircleIcon, + ExclamationTriangleIcon, FolderIcon, FolderOpenIcon, GlobeAltIcon, @@ -44,6 +45,7 @@ const ICONS_FOR_DROPDOWN: { [key: string]: any } = { url: GlobeAltIcon, open: FolderOpenIcon, codebase: SparklesIcon, + problems: ExclamationTriangleIcon, "/edit": PaintBrushIcon, "/clear": TrashIcon, "/test": BeakerIcon,