Skip to content

Commit 3844208

Browse files
feat: improve chunking desc on large projects
1 parent 3692aee commit 3844208

File tree

1 file changed

+49
-18
lines changed

1 file changed

+49
-18
lines changed

core/indexing/chunk/ChunkCodebaseIndex.ts

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { RunResult } from "sqlite3";
22
import { IContinueServerClient } from "../../continueServer/interface.js";
33
import { Chunk, IndexTag, IndexingProgressUpdate } from "../../index.js";
44
import { getBasename } from "../../util/index.js";
5-
import { getLanguageForFile } from "../../util/treeSitter.js";
65
import { DatabaseConnection, SqliteDb, tagToString } from "../refreshIndex.js";
76
import {
87
IndexResultType,
@@ -12,6 +11,7 @@ import {
1211
type CodebaseIndex,
1312
} from "../types.js";
1413
import { chunkDocument, shouldChunk } from "./chunk.js";
14+
import * as path from "path";
1515

1616
export class ChunkCodebaseIndex implements CodebaseIndex {
1717
relativeExpectedTime: number = 1;
@@ -61,8 +61,11 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
6161
let accumulatedProgress = 0;
6262

6363
if (results.compute.length > 0) {
64+
const folderPath = results.compute[0].path;
65+
const folderName = path.basename(path.dirname(folderPath));
66+
6467
yield {
65-
desc: `Chunking ${results.compute.length} ${this.formatListPlurality("file", results.compute.length)}`,
68+
desc: `Chunking files in ${folderName}`,
6669
status: "indexing",
6770
progress: accumulatedProgress,
6871
};
@@ -171,35 +174,63 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
171174
}
172175

173176
private async computeChunks(paths: PathAndCacheKey[]): Promise<Chunk[]> {
174-
const chunkLists = await Promise.all(paths.map(p => this.packToChunks(p)));
177+
const chunkLists = await Promise.all(
178+
paths.map((p) => this.packToChunks(p)),
179+
);
175180
return chunkLists.flat();
176181
}
177182

178-
private async insertChunks(db: DatabaseConnection, tagString: string, chunks: Chunk[]) {
183+
private async insertChunks(
184+
db: DatabaseConnection,
185+
tagString: string,
186+
chunks: Chunk[],
187+
) {
179188
await new Promise<void>((resolve, reject) => {
180189
db.db.serialize(() => {
181190
db.db.exec("BEGIN", (err: Error | null) => {
182191
if (err) {
183192
reject(new Error("error creating transaction", { cause: err }));
184193
}
185194
});
186-
const chunksSQL = "INSERT INTO chunks (cacheKey, path, idx, startLine, endLine, content) VALUES (?, ?, ?, ?, ?, ?)";
187-
chunks.map(c => {
188-
db.db.run(chunksSQL, [c.digest, c.filepath, c.index, c.startLine, c.endLine, c.content], (result: RunResult, err: Error) => {
189-
if (err) {
190-
reject(new Error("error inserting into chunks table", { cause: err }));
191-
}
192-
});
193-
const chunkTagsSQL = "INSERT INTO chunk_tags (chunkId, tag) VALUES (last_insert_rowid(), ?)";
194-
db.db.run(chunkTagsSQL, [ tagString ], (result: RunResult, err: Error) => {
195-
if (err) {
196-
reject(new Error("error inserting into chunk_tags table", { cause: err }));
197-
}
198-
});
195+
const chunksSQL =
196+
"INSERT INTO chunks (cacheKey, path, idx, startLine, endLine, content) VALUES (?, ?, ?, ?, ?, ?)";
197+
chunks.map((c) => {
198+
db.db.run(
199+
chunksSQL,
200+
[c.digest, c.filepath, c.index, c.startLine, c.endLine, c.content],
201+
(result: RunResult, err: Error) => {
202+
if (err) {
203+
reject(
204+
new Error("error inserting into chunks table", {
205+
cause: err,
206+
}),
207+
);
208+
}
209+
},
210+
);
211+
const chunkTagsSQL =
212+
"INSERT INTO chunk_tags (chunkId, tag) VALUES (last_insert_rowid(), ?)";
213+
db.db.run(
214+
chunkTagsSQL,
215+
[tagString],
216+
(result: RunResult, err: Error) => {
217+
if (err) {
218+
reject(
219+
new Error("error inserting into chunk_tags table", {
220+
cause: err,
221+
}),
222+
);
223+
}
224+
},
225+
);
199226
});
200227
db.db.exec("COMMIT", (err: Error | null) => {
201228
if (err) {
202-
reject(new Error("error while committing insert chunks transaction", { cause: err }));
229+
reject(
230+
new Error("error while committing insert chunks transaction", {
231+
cause: err,
232+
}),
233+
);
203234
} else {
204235
resolve();
205236
}

0 commit comments

Comments
 (0)