🎨 add getRepoName to IDE, use for indexing
This commit is contained in:
parent
a5bfcfe27d
commit
90e9933c97
12 changed files with 112 additions and 25 deletions
|
|
@ -13,6 +13,7 @@ export class ContinueServerClient {
|
|||
public async getFromIndexCache<T extends ArtifactType>(
|
||||
keys: string[],
|
||||
artifactId: T,
|
||||
repoName: string | undefined,
|
||||
): Promise<EmbeddingsCacheResponse<T>> {
|
||||
return { files: {} };
|
||||
}
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -399,6 +399,7 @@ export interface IDE {
|
|||
getBranch(dir: string): Promise<string>;
|
||||
getStats(directory: string): Promise<{ [path: string]: number }>;
|
||||
getTags(artifactId: string): Promise<IndexTag[]>;
|
||||
getRepoName(dir: string): Promise<string | undefined>;
|
||||
}
|
||||
|
||||
// Slash Commands
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
|
|||
tag: IndexTag,
|
||||
results: RefreshIndexResults,
|
||||
markComplete: MarkCompleteCallback,
|
||||
repoName: string | undefined,
|
||||
): AsyncGenerator<IndexingProgressUpdate, any, unknown> {
|
||||
const db = await SqliteDb.get();
|
||||
await CodeSnippetsCodebaseIndex._createTables(db);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex {
|
|||
tag: IndexTag,
|
||||
results: RefreshIndexResults,
|
||||
markComplete: MarkCompleteCallback,
|
||||
repoName: string | undefined,
|
||||
): AsyncGenerator<IndexingProgressUpdate, any, unknown> {
|
||||
const db = await SqliteDb.get();
|
||||
await this._createTables(db);
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
items: PathAndCacheKey[],
|
||||
resultType: IndexResultType,
|
||||
) => void,
|
||||
repoName: string | undefined,
|
||||
): AsyncGenerator<IndexingProgressUpdate> {
|
||||
const lancedb = await import("vectordb");
|
||||
const tableName = this.tableNameForTag(tag);
|
||||
|
|
@ -177,6 +178,7 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
const resp = await this.continueServerClient.getFromIndexCache(
|
||||
keys,
|
||||
"embeddings",
|
||||
repoName,
|
||||
);
|
||||
for (const [cacheKey, chunks] of Object.entries(resp.files)) {
|
||||
// Get path for cacheKey
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
|
|||
tag: IndexTag,
|
||||
results: RefreshIndexResults,
|
||||
markComplete: MarkCompleteCallback,
|
||||
repoName: string | undefined,
|
||||
): AsyncGenerator<IndexingProgressUpdate, any, unknown> {
|
||||
const db = await SqliteDb.get();
|
||||
await this._createTables(db);
|
||||
|
|
@ -76,6 +77,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
|
|||
const resp = await this.continueServerClient.getFromIndexCache(
|
||||
keys,
|
||||
"chunks",
|
||||
repoName,
|
||||
);
|
||||
|
||||
for (const [cacheKey, chunks] of Object.entries(resp.files)) {
|
||||
|
|
|
|||
|
|
@ -77,10 +77,12 @@ export class CodebaseIndexer {
|
|||
for (let directory of workspaceDirs) {
|
||||
const stats = await this.ide.getStats(directory);
|
||||
const branch = await this.ide.getBranch(directory);
|
||||
const repoName = await this.ide.getRepoName(directory);
|
||||
let completedIndexes = 0;
|
||||
|
||||
try {
|
||||
for (let codebaseIndex of indexesToBuild) {
|
||||
// TODO: IndexTag type should use repoName rather than directory
|
||||
const tag: IndexTag = {
|
||||
directory,
|
||||
branch,
|
||||
|
|
@ -90,12 +92,14 @@ export class CodebaseIndexer {
|
|||
tag,
|
||||
{ ...stats },
|
||||
(filepath) => this.ide.readFile(filepath),
|
||||
repoName,
|
||||
);
|
||||
|
||||
for await (let { progress, desc } of codebaseIndex.update(
|
||||
tag,
|
||||
results,
|
||||
markComplete,
|
||||
repoName,
|
||||
)) {
|
||||
// Handle pausing in this loop because it's the only one really taking time
|
||||
while (this.pauseToken.paused) {
|
||||
|
|
|
|||
|
|
@ -259,6 +259,7 @@ export async function getComputeDeleteAddRemove(
|
|||
tag: IndexTag,
|
||||
currentFiles: LastModifiedMap,
|
||||
readFile: (path: string) => Promise<string>,
|
||||
repoName: string | undefined,
|
||||
): Promise<[RefreshIndexResults, MarkCompleteCallback]> {
|
||||
const [add, remove, markComplete] = await getAddRemoveForTag(
|
||||
tag,
|
||||
|
|
@ -316,7 +317,12 @@ export async function getComputeDeleteAddRemove(
|
|||
removeTag: [],
|
||||
};
|
||||
results[resultType] = items;
|
||||
for await (let _ of globalCacheIndex.update(tag, results, () => {})) {
|
||||
for await (let _ of globalCacheIndex.update(
|
||||
tag,
|
||||
results,
|
||||
() => {},
|
||||
repoName,
|
||||
)) {
|
||||
}
|
||||
},
|
||||
];
|
||||
|
|
@ -338,6 +344,7 @@ export class GlobalCacheCodeBaseIndex implements CodebaseIndex {
|
|||
tag: IndexTag,
|
||||
results: RefreshIndexResults,
|
||||
_: MarkCompleteCallback,
|
||||
repoName: string | undefined,
|
||||
): AsyncGenerator<IndexingProgressUpdate> {
|
||||
const add = [...results.compute, ...results.addTag];
|
||||
const remove = [...results.del, ...results.removeTag];
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ export interface CodebaseIndex {
|
|||
tag: IndexTag,
|
||||
results: RefreshIndexResults,
|
||||
markComplete: MarkCompleteCallback,
|
||||
repoName: string | undefined,
|
||||
): AsyncGenerator<IndexingProgressUpdate>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,25 @@
|
|||
import * as fs from "fs";
|
||||
import { ContinueRcJson, IDE, IdeInfo, IndexTag, Problem, Range, Thread } from "..";
|
||||
import {
|
||||
ContinueRcJson,
|
||||
IDE,
|
||||
IdeInfo,
|
||||
IndexTag,
|
||||
Problem,
|
||||
Range,
|
||||
Thread,
|
||||
} from "..";
|
||||
|
||||
import { getContinueGlobalPath } from "./paths";
|
||||
|
||||
class FileSystemIde implements IDE {
|
||||
getRepoName(dir: string): Promise<string | undefined> {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
getTags(artifactId: string): Promise<IndexTag[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
getIdeInfo(): Promise<IdeInfo> {
|
||||
return Promise.resolve({
|
||||
ideType: "vscode",
|
||||
|
|
@ -15,18 +28,23 @@ class FileSystemIde implements IDE {
|
|||
remoteName: "na",
|
||||
});
|
||||
}
|
||||
|
||||
readRangeInFile(filepath: string, range: Range): Promise<string> {
|
||||
return Promise.resolve("");
|
||||
}
|
||||
|
||||
getStats(directory: string): Promise<{ [path: string]: number }> {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
|
||||
isTelemetryEnabled(): Promise<boolean> {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
getUniqueId(): Promise<string> {
|
||||
return Promise.resolve("NOT_UNIQUE");
|
||||
}
|
||||
|
||||
getWorkspaceConfigs(): Promise<ContinueRcJson[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
|
@ -34,28 +52,34 @@ class FileSystemIde implements IDE {
|
|||
getDiff(): Promise<string> {
|
||||
return Promise.resolve("");
|
||||
}
|
||||
|
||||
getTerminalContents(): Promise<string> {
|
||||
return Promise.resolve("");
|
||||
}
|
||||
|
||||
async getDebugLocals(threadIndex: number): Promise<string> {
|
||||
return Promise.resolve("");
|
||||
}
|
||||
|
||||
async getTopLevelCallStackSources(
|
||||
threadIndex: number,
|
||||
stackDepth: number
|
||||
stackDepth: number,
|
||||
): Promise<string[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
async getAvailableThreads(): Promise<Thread[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
showLines(
|
||||
filepath: string,
|
||||
startLine: number,
|
||||
endLine: number
|
||||
endLine: number,
|
||||
): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
listWorkspaceContents(): Promise<string[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readdir("/tmp/continue", (err, files) => {
|
||||
|
|
@ -66,6 +90,7 @@ class FileSystemIde implements IDE {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
getWorkspaceDirs(): Promise<string[]> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.mkdtemp("/tmp/continue", (err, folder) => {
|
||||
|
|
@ -76,9 +101,11 @@ class FileSystemIde implements IDE {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
listFolders(): Promise<string[]> {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
writeFile(path: string, contents: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(path, contents, (err) => {
|
||||
|
|
@ -89,21 +116,27 @@ class FileSystemIde implements IDE {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
showVirtualFile(title: string, contents: string): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
getContinueDir(): Promise<string> {
|
||||
return Promise.resolve(getContinueGlobalPath());
|
||||
}
|
||||
|
||||
openFile(path: string): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
runCommand(command: string): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
saveFile(filepath: string): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
readFile(filepath: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(filepath, "utf8", (err, contents) => {
|
||||
|
|
@ -114,10 +147,11 @@ class FileSystemIde implements IDE {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
showDiff(
|
||||
filepath: string,
|
||||
newContents: string,
|
||||
stepIndex: number
|
||||
stepIndex: number,
|
||||
): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,44 @@
|
|||
import { ContinueRcJson, IDE, IdeInfo, IndexTag, Problem, Range, Thread } from "..";
|
||||
import {
|
||||
ContinueRcJson,
|
||||
IDE,
|
||||
IdeInfo,
|
||||
IndexTag,
|
||||
Problem,
|
||||
Range,
|
||||
Thread,
|
||||
} from "..";
|
||||
|
||||
export class MessageIde implements IDE {
|
||||
constructor(
|
||||
private readonly request: (messageType: string, data: any) => Promise<any>
|
||||
private readonly request: (messageType: string, data: any) => Promise<any>,
|
||||
) {}
|
||||
|
||||
getRepoName(dir: string): Promise<string | undefined> {
|
||||
return this.request("getRepoName", { dir });
|
||||
}
|
||||
|
||||
getDebugLocals(threadIndex: number): Promise<string> {
|
||||
return this.request("getDebugLocals", { threadIndex });
|
||||
}
|
||||
|
||||
getTopLevelCallStackSources(
|
||||
threadIndex: number,
|
||||
stackDepth: number
|
||||
stackDepth: number,
|
||||
): Promise<string[]> {
|
||||
return this.request("getTopLevelCallStackSources", {
|
||||
threadIndex,
|
||||
stackDepth,
|
||||
});
|
||||
}
|
||||
|
||||
getAvailableThreads(): Promise<Thread[]> {
|
||||
return this.request("getAvailableThreads", undefined);
|
||||
}
|
||||
|
||||
getTags(artifactId: string): Promise<IndexTag[]> {
|
||||
return this.request("getTags", artifactId);
|
||||
}
|
||||
|
||||
getIdeInfo(): Promise<IdeInfo> {
|
||||
return this.request("getIdeInfo", undefined);
|
||||
}
|
||||
|
|
@ -29,9 +46,11 @@ export class MessageIde implements IDE {
|
|||
readRangeInFile(filepath: string, range: Range): Promise<string> {
|
||||
return this.request("readRangeInFile", { filepath, range });
|
||||
}
|
||||
|
||||
getStats(directory: string): Promise<{ [path: string]: number }> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
isTelemetryEnabled(): Promise<boolean> {
|
||||
return this.request("isTelemetryEnabled", undefined);
|
||||
}
|
||||
|
|
@ -63,7 +82,7 @@ export class MessageIde implements IDE {
|
|||
async showLines(
|
||||
filepath: string,
|
||||
startLine: number,
|
||||
endLine: number
|
||||
endLine: number,
|
||||
): Promise<void> {
|
||||
return await this.request("showLines", { filepath, startLine, endLine });
|
||||
}
|
||||
|
|
@ -108,7 +127,7 @@ export class MessageIde implements IDE {
|
|||
async showDiff(
|
||||
filepath: string,
|
||||
newContents: string,
|
||||
stepIndex: number
|
||||
stepIndex: number,
|
||||
): Promise<void> {
|
||||
await this.request("showDiff", { filepath, newContents, stepIndex });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,14 @@
|
|||
import * as child_process from "child_process";
|
||||
import { exec } from "child_process";
|
||||
import { ContinueRcJson, IDE, IdeInfo, IndexTag, Problem, Range, Thread } from "core";
|
||||
import {
|
||||
ContinueRcJson,
|
||||
IDE,
|
||||
IdeInfo,
|
||||
IndexTag,
|
||||
Problem,
|
||||
Range,
|
||||
Thread,
|
||||
} from "core";
|
||||
import { getContinueGlobalPath } from "core/util/paths";
|
||||
import * as path from "path";
|
||||
import * as vscode from "vscode";
|
||||
|
|
@ -19,6 +27,12 @@ class VsCodeIde implements IDE {
|
|||
constructor(private readonly diffManager: DiffManager) {
|
||||
this.ideUtils = new VsCodeIdeUtils();
|
||||
}
|
||||
|
||||
async getRepoName(dir: string): Promise<string | undefined> {
|
||||
const repo = await this.getRepo(vscode.Uri.file(dir));
|
||||
return repo?.state.HEAD?.name;
|
||||
}
|
||||
|
||||
async getTags(artifactId: string): Promise<IndexTag[]> {
|
||||
const workspaceDirs = await this.getWorkspaceDirs();
|
||||
|
||||
|
|
@ -47,8 +61,8 @@ class VsCodeIde implements IDE {
|
|||
filepath,
|
||||
new vscode.Range(
|
||||
new vscode.Position(range.start.line, range.start.character),
|
||||
new vscode.Position(range.end.line, range.end.character)
|
||||
)
|
||||
new vscode.Position(range.end.line, range.end.character),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +74,7 @@ class VsCodeIde implements IDE {
|
|||
files.map(async (file) => {
|
||||
let stat = await vscode.workspace.fs.stat(uriFromFilePath(file));
|
||||
pathToLastModified[file] = stat.mtime;
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
return pathToLastModified;
|
||||
|
|
@ -95,11 +109,11 @@ class VsCodeIde implements IDE {
|
|||
|
||||
async getTopLevelCallStackSources(
|
||||
threadIndex: number,
|
||||
stackDepth: number
|
||||
stackDepth: number,
|
||||
): Promise<string[]> {
|
||||
return await this.ideUtils.getTopLevelCallStackSources(
|
||||
threadIndex,
|
||||
stackDepth
|
||||
stackDepth,
|
||||
);
|
||||
}
|
||||
async getAvailableThreads(): Promise<Thread[]> {
|
||||
|
|
@ -113,7 +127,7 @@ class VsCodeIde implements IDE {
|
|||
const contents = await Promise.all(
|
||||
this.ideUtils
|
||||
.getWorkspaceDirectories()
|
||||
.map((dir) => this.ideUtils.getDirectoryContents(dir, true))
|
||||
.map((dir) => this.ideUtils.getDirectoryContents(dir, true)),
|
||||
);
|
||||
return contents.flat();
|
||||
}
|
||||
|
|
@ -128,7 +142,7 @@ class VsCodeIde implements IDE {
|
|||
for (const [filename, type] of files) {
|
||||
if (type === vscode.FileType.File && filename === ".continuerc.json") {
|
||||
const contents = await this.ideUtils.readFile(
|
||||
vscode.Uri.joinPath(workspaceDir, filename).fsPath
|
||||
vscode.Uri.joinPath(workspaceDir, filename).fsPath,
|
||||
);
|
||||
configs.push(JSON.parse(contents));
|
||||
}
|
||||
|
|
@ -146,7 +160,7 @@ class VsCodeIde implements IDE {
|
|||
directory,
|
||||
[],
|
||||
false,
|
||||
undefined
|
||||
undefined,
|
||||
)) {
|
||||
allDirs.push(dir);
|
||||
}
|
||||
|
|
@ -166,7 +180,7 @@ class VsCodeIde implements IDE {
|
|||
async writeFile(path: string, contents: string): Promise<void> {
|
||||
await vscode.workspace.fs.writeFile(
|
||||
vscode.Uri.file(path),
|
||||
Buffer.from(contents)
|
||||
Buffer.from(contents),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -181,11 +195,11 @@ class VsCodeIde implements IDE {
|
|||
async showLines(
|
||||
filepath: string,
|
||||
startLine: number,
|
||||
endLine: number
|
||||
endLine: number,
|
||||
): Promise<void> {
|
||||
const range = new vscode.Range(
|
||||
new vscode.Position(startLine, 0),
|
||||
new vscode.Position(endLine, 0)
|
||||
new vscode.Position(endLine, 0),
|
||||
);
|
||||
openEditorAndRevealRange(filepath, range).then(() => {
|
||||
// TODO: Highlight lines
|
||||
|
|
@ -219,7 +233,7 @@ class VsCodeIde implements IDE {
|
|||
async showDiff(
|
||||
filepath: string,
|
||||
newContents: string,
|
||||
stepIndex: number
|
||||
stepIndex: number,
|
||||
): Promise<void> {
|
||||
await this.diffManager.writeDiff(filepath, newContents, stepIndex);
|
||||
}
|
||||
|
|
@ -245,11 +259,11 @@ class VsCodeIde implements IDE {
|
|||
"@vscode",
|
||||
"ripgrep",
|
||||
"bin",
|
||||
"rg"
|
||||
"rg",
|
||||
),
|
||||
["-i", "-C", "2", "--", `${query}`, "."], //no regex
|
||||
//["-i", "-C", "2", "-e", `${query}`, "."], //use regex
|
||||
{ cwd: dir }
|
||||
{ cwd: dir },
|
||||
);
|
||||
let output = "";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue