diff --git a/core/indexing/CodeSnippetsIndex.ts b/core/indexing/CodeSnippetsIndex.ts index 26edbc432..737c3c058 100644 --- a/core/indexing/CodeSnippetsIndex.ts +++ b/core/indexing/CodeSnippetsIndex.ts @@ -33,6 +33,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { path TEXT NOT NULL, cacheKey TEXT NOT NULL, content TEXT NOT NULL, + title TEXT NOT NULL, startLine INTEGER NOT NULL, endLine INTEGER NOT NULL )`); @@ -42,7 +43,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { tag TEXT NOT NULL, snippetId INTEGER NOT NULL, FOREIGN KEY (snippetId) REFERENCES code_snippets (id) - )`); + )`); } private getQuerySource(filepath: string) { @@ -62,8 +63,11 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { async getSnippetsInFile( filepath: string, contents: string, - ): Promise { + ): Promise<(ChunkWithoutID & { title: string })[]> { const lang = await getLanguageForFile(filepath); + if (!lang) { + return []; + } const parser = await getParserForFile(filepath); const ast = parser.parse(contents); const query = lang?.query(this.getQuerySource(filepath)); @@ -71,12 +75,14 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { return ( matches?.flatMap((match) => { - const nodes = match.captures.map((capture) => capture.node); - const results = nodes.map((node) => ({ + const node = match.captures[0].node; + const title = match.captures[1].node.text; + const results = { + title, content: node.text, startLine: node.startPosition.row, endLine: node.endPosition.row, - })); + }; return results; }) ?? [] ); @@ -101,11 +107,12 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { // Add snippets to sqlite for (const snippet of snippets) { const { lastID } = await db.run( - `INSERT INTO code_snippets (path, cacheKey, content, startLine, endLine) VALUES (?, ?, ?, ?, ?)`, + `INSERT INTO code_snippets (path, cacheKey, content, title, startLine, endLine) VALUES (?, ?, ?, ?, ?, ?)`, [ compute.path, compute.cacheKey, snippet.content, + snippet.title, snippet.startLine, snippet.endLine, ], @@ -174,7 +181,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { const row = await db.get(`SELECT * FROM code_snippets WHERE id = ?`, [id]); return { - name: getBasename(row.path), + name: row.title, description: getBasename(row.path, 2), content: `\`\`\`${getBasename(row.path)}\n${row.content}\n\`\`\``, }; @@ -182,19 +189,24 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex { static async getAll(tag: IndexTag): Promise { const db = await SqliteDb.get(); - const rows = await db.all( - `SELECT * - FROM code_snippets cs - JOIN code_snippets_tags cst ON cs.id = cst.snippetId - WHERE cst.tag = ?; - `, - [tagToString(tag)], - ); + try { + const rows = await db.all( + `SELECT * + FROM code_snippets cs + JOIN code_snippets_tags cst ON cs.id = cst.snippetId + WHERE cst.tag = ?; + `, + [tagToString(tag)], + ); - return rows.map((row) => ({ - title: getBasename(row.path), - description: getBasename(row.path, 2), - id: row.id.toString(), - })); + return rows.map((row) => ({ + title: row.title, + description: getBasename(row.path, 2), + id: row.id.toString(), + })); + } catch (e) { + console.warn("Error getting all code snippets: ", e); + return []; + } } } diff --git a/core/util/treeSitter.ts b/core/util/treeSitter.ts index f0e9814b3..4116d5440 100644 --- a/core/util/treeSitter.ts +++ b/core/util/treeSitter.ts @@ -90,12 +90,6 @@ export async function getLanguageForFile( const extension = path.extname(filepath).slice(1); if (!supportedLanguages[extension]) { - console.warn( - "Unable to load language for file", - extension, - "from path: ", - filepath, - ); return undefined; } diff --git a/extensions/vscode/src/ideProtocol.ts b/extensions/vscode/src/ideProtocol.ts index 3114e3bd9..ea8edcc1d 100644 --- a/extensions/vscode/src/ideProtocol.ts +++ b/extensions/vscode/src/ideProtocol.ts @@ -22,14 +22,9 @@ class VsCodeIde implements IDE { async getTags(artifactId: string): Promise { const workspaceDirs = await this.getWorkspaceDirs(); - const branches = (await Promise.race([ - Promise.all(workspaceDirs.map((dir) => this.getBranch(dir))), - new Promise((resolve) => { - setTimeout(() => { - resolve(["NONE"]); - }, 500); - }), - ])) as string[]; + const branches = await Promise.all( + workspaceDirs.map((dir) => this.getBranch(dir)), + ); const tags: IndexTag[] = workspaceDirs.map((directory, i) => ({ directory, diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 4695b874d..524019e30 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -5,6 +5,7 @@ import { BeakerIcon, BookOpenIcon, ChevronDoubleRightIcon, + CodeBracketIcon, Cog6ToothIcon, CommandLineIcon, ExclamationCircleIcon, @@ -47,6 +48,7 @@ import { ComboBoxItem } from "./types"; const ICONS_FOR_DROPDOWN: { [key: string]: any } = { file: FolderIcon, + code: CodeBracketIcon, terminal: CommandLineIcon, diff: PlusIcon, search: MagnifyingGlassIcon, @@ -163,7 +165,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => { const [selectedIndex, setSelectedIndex] = useState(0); const [subMenuTitle, setSubMenuTitle] = useState( - undefined + undefined, ); const [querySubmenuItem, setQuerySubmenuItem] = useState< ComboBoxItem | undefined @@ -186,7 +188,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => { const text = tr.doc.textBetween(0, tr.selection.from); const start = text.lastIndexOf("@"); props.editor.view.dispatch( - tr.delete(start, tr.selection.from).scrollIntoView() + tr.delete(start, tr.selection.from).scrollIntoView(), ); }, description: "Add a new documentation source",