diff --git a/core/indexing/chunk/ChunkCodebaseIndex.ts b/core/indexing/chunk/ChunkCodebaseIndex.ts index 0e866b3bf9..4fbc10266a 100644 --- a/core/indexing/chunk/ChunkCodebaseIndex.ts +++ b/core/indexing/chunk/ChunkCodebaseIndex.ts @@ -2,7 +2,6 @@ import { RunResult } from "sqlite3"; import { IContinueServerClient } from "../../continueServer/interface.js"; import { Chunk, IndexTag, IndexingProgressUpdate } from "../../index.js"; import { getBasename } from "../../util/index.js"; -import { getLanguageForFile } from "../../util/treeSitter.js"; import { DatabaseConnection, SqliteDb, tagToString } from "../refreshIndex.js"; import { IndexResultType, @@ -12,6 +11,7 @@ import { type CodebaseIndex, } from "../types.js"; import { chunkDocument, shouldChunk } from "./chunk.js"; +import * as path from "path"; export class ChunkCodebaseIndex implements CodebaseIndex { relativeExpectedTime: number = 1; @@ -61,8 +61,11 @@ export class ChunkCodebaseIndex implements CodebaseIndex { let accumulatedProgress = 0; if (results.compute.length > 0) { + const folderPath = results.compute[0].path; + const folderName = path.basename(path.dirname(folderPath)); + yield { - desc: `Chunking ${results.compute.length} ${this.formatListPlurality("file", results.compute.length)}`, + desc: `Chunking files in ${folderName}`, status: "indexing", progress: accumulatedProgress, }; @@ -171,11 +174,17 @@ export class ChunkCodebaseIndex implements CodebaseIndex { } private async computeChunks(paths: PathAndCacheKey[]): Promise { - const chunkLists = await Promise.all(paths.map(p => this.packToChunks(p))); + const chunkLists = await Promise.all( + paths.map((p) => this.packToChunks(p)), + ); return chunkLists.flat(); } - private async insertChunks(db: DatabaseConnection, tagString: string, chunks: Chunk[]) { + private async insertChunks( + db: DatabaseConnection, + tagString: string, + chunks: Chunk[], + ) { await new Promise((resolve, reject) => { db.db.serialize(() => { db.db.exec("BEGIN", (err: Error | null) => { @@ -183,23 +192,45 @@ export class ChunkCodebaseIndex implements CodebaseIndex { reject(new Error("error creating transaction", { cause: err })); } }); - const chunksSQL = "INSERT INTO chunks (cacheKey, path, idx, startLine, endLine, content) VALUES (?, ?, ?, ?, ?, ?)"; - chunks.map(c => { - db.db.run(chunksSQL, [c.digest, c.filepath, c.index, c.startLine, c.endLine, c.content], (result: RunResult, err: Error) => { - if (err) { - reject(new Error("error inserting into chunks table", { cause: err })); - } - }); - const chunkTagsSQL = "INSERT INTO chunk_tags (chunkId, tag) VALUES (last_insert_rowid(), ?)"; - db.db.run(chunkTagsSQL, [ tagString ], (result: RunResult, err: Error) => { - if (err) { - reject(new Error("error inserting into chunk_tags table", { cause: err })); - } - }); + const chunksSQL = + "INSERT INTO chunks (cacheKey, path, idx, startLine, endLine, content) VALUES (?, ?, ?, ?, ?, ?)"; + chunks.map((c) => { + db.db.run( + chunksSQL, + [c.digest, c.filepath, c.index, c.startLine, c.endLine, c.content], + (result: RunResult, err: Error) => { + if (err) { + reject( + new Error("error inserting into chunks table", { + cause: err, + }), + ); + } + }, + ); + const chunkTagsSQL = + "INSERT INTO chunk_tags (chunkId, tag) VALUES (last_insert_rowid(), ?)"; + db.db.run( + chunkTagsSQL, + [tagString], + (result: RunResult, err: Error) => { + if (err) { + reject( + new Error("error inserting into chunk_tags table", { + cause: err, + }), + ); + } + }, + ); }); db.db.exec("COMMIT", (err: Error | null) => { if (err) { - reject(new Error("error while committing insert chunks transaction", { cause: err })); + reject( + new Error("error while committing insert chunks transaction", { + cause: err, + }), + ); } else { resolve(); }