Elffuss BraidHub

kikocis/continue public

main · 1.8 KiBRawPermalink
1import {
2 ContextItem,
3 ContextProviderDescription,
4 ContextProviderExtras,
5} from "../../index.js";
6import { isSecurityConcern } from "../../indexing/ignore.js";
7import { getUriDescription } from "../../util/uri.js";
8import { BaseContextProvider } from "../index.js";
9
10class ProblemsContextProvider extends BaseContextProvider {
11 static description: ContextProviderDescription = {
12 title: "problems",
13 displayTitle: "Problems",
14 description: "Reference problems in the current file",
15 type: "normal",
16 };
17
18 async getContextItems(
19 query: string,
20 extras: ContextProviderExtras,
21 ): Promise<ContextItem[]> {
22 const ide = extras.ide;
23 const problems = await ide.getProblems();
24 const workspaceDirs = await ide.getWorkspaceDirs();
25
26 const items = await Promise.all(
27 problems.map(async (problem) => {
28 const { relativePathOrBasename, baseName } = getUriDescription(
29 problem.filepath,
30 workspaceDirs,
31 );
32 const content = await ide.readFile(problem.filepath);
33 const lines = content.split("\n");
34 const rangeContent = lines
35 .slice(
36 Math.max(0, problem.range.start.line - 2),
37 problem.range.end.line + 2,
38 )
39 .join("\n");
40
41 return {
42 description: "Problems in current file",
43 content: `\`\`\`${relativePathOrBasename}\n${rangeContent}\n\`\`\`\n${problem.message}\n\n`,
44 name: `Warnings in ${baseName}`,
45 };
46 }),
47 );
48
49 return items.length === 0
50 ? [
51 {
52 description: "Problems in current file",
53 content: "There are no problems found in the open file.",
54 name: "No problems found",
55 },
56 ]
57 : items;
58 }
59}
60
61export default ProblemsContextProvider;