file stats method
This commit is contained in:
parent
6294253ab4
commit
26a847cd12
16 changed files with 61 additions and 46 deletions
12
core/index.d.ts
vendored
12
core/index.d.ts
vendored
|
|
@ -582,6 +582,16 @@ export interface IdeSettings {
|
|||
enableDebugLogs: boolean;
|
||||
}
|
||||
|
||||
export interface FileStats {
|
||||
size: number;
|
||||
lastModified: number;
|
||||
}
|
||||
|
||||
/** Map of file name to stats */
|
||||
export type FileStatsMap = {
|
||||
[path: string]: FileStats;
|
||||
};
|
||||
|
||||
export interface IDE {
|
||||
getIdeInfo(): Promise<IdeInfo>;
|
||||
|
||||
|
|
@ -665,7 +675,7 @@ export interface IDE {
|
|||
|
||||
listDir(dir: string): Promise<[string, FileType][]>;
|
||||
|
||||
getLastModified(files: string[]): Promise<{ [path: string]: number }>;
|
||||
getFileStats(files: string[]): Promise<FileStatsMap>;
|
||||
|
||||
getGitHubAuthToken(args: GetGhTokenArgs): Promise<string | undefined>;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { jest } from "@jest/globals";
|
||||
import { execSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "path";
|
||||
import { jest } from "@jest/globals";
|
||||
|
||||
import { ContinueServerClient } from "../continueServer/stubs/client.js";
|
||||
import { testConfigHandler, testIde } from "../test/fixtures.js";
|
||||
|
|
@ -14,13 +14,12 @@ import {
|
|||
} from "../test/testDir.js";
|
||||
import { getIndexSqlitePath } from "../util/paths.js";
|
||||
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { CodebaseIndexer, PauseToken } from "./CodebaseIndexer.js";
|
||||
import { getComputeDeleteAddRemove } from "./refreshIndex.js";
|
||||
import { TestCodebaseIndex } from "./TestCodebaseIndex.js";
|
||||
import { CodebaseIndex } from "./types.js";
|
||||
import { walkDir } from "./walkDir.js";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { joinPathsToUri } from "../util/uri.js";
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
|
|
@ -120,7 +119,7 @@ describe("CodebaseIndexer", () => {
|
|||
async function getIndexPlan() {
|
||||
const workspaceFiles = await walkDir(TEST_DIR, testIde);
|
||||
const [tag] = await testIde.getTags(testIndex.artifactId);
|
||||
const stats = await testIde.getLastModified(workspaceFiles);
|
||||
const stats = await testIde.getFileStats(workspaceFiles);
|
||||
|
||||
const [results, lastUpdated, markComplete] =
|
||||
await getComputeDeleteAddRemove(
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { IDE, IndexingProgressUpdate, IndexTag } from "../index.js";
|
|||
import { extractMinimalStackTraceInfo } from "../util/extractMinimalStackTraceInfo.js";
|
||||
import { getIndexSqlitePath, getLanceDbPath } from "../util/paths.js";
|
||||
|
||||
import { findUriInDirs, getUriPathBasename } from "../util/uri.js";
|
||||
import { ChunkCodebaseIndex } from "./chunk/ChunkCodebaseIndex.js";
|
||||
import { CodeSnippetsCodebaseIndex } from "./CodeSnippetsIndex.js";
|
||||
import { FullTextSearchCodebaseIndex } from "./FullTextSearchCodebaseIndex.js";
|
||||
|
|
@ -17,7 +18,6 @@ import {
|
|||
RefreshIndexResults,
|
||||
} from "./types.js";
|
||||
import { walkDirAsync } from "./walkDir.js";
|
||||
import { findUriInDirs, getUriPathBasename } from "../util/uri.js";
|
||||
|
||||
export class PauseToken {
|
||||
constructor(private _paused: boolean) {}
|
||||
|
|
@ -110,7 +110,7 @@ export class CodebaseIndexer {
|
|||
const branch = await this.ide.getBranch(foundInDir);
|
||||
const repoName = await this.ide.getRepoName(foundInDir);
|
||||
const indexesToBuild = await this.getIndexesToBuild();
|
||||
const stats = await this.ide.getLastModified([file]);
|
||||
const stats = await this.ide.getFileStats([file]);
|
||||
for (const index of indexesToBuild) {
|
||||
const tag = {
|
||||
directory: foundInDir,
|
||||
|
|
@ -389,7 +389,7 @@ export class CodebaseIndexer {
|
|||
branch: string,
|
||||
repoName: string | undefined,
|
||||
): AsyncGenerator<IndexingProgressUpdate> {
|
||||
const stats = await this.ide.getLastModified(files);
|
||||
const stats = await this.ide.getFileStats(files);
|
||||
const indexesToBuild = await this.getIndexesToBuild();
|
||||
let completedIndexCount = 0;
|
||||
let progress = 0;
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@ import plimit from "p-limit";
|
|||
import { open, type Database } from "sqlite";
|
||||
import sqlite3 from "sqlite3";
|
||||
|
||||
import { IndexTag, IndexingProgressUpdate } from "../index.js";
|
||||
import { FileStatsMap, IndexTag, IndexingProgressUpdate } from "../index.js";
|
||||
import { getIndexSqlitePath } from "../util/paths.js";
|
||||
|
||||
import {
|
||||
CodebaseIndex,
|
||||
IndexResultType,
|
||||
LastModifiedMap,
|
||||
MarkCompleteCallback,
|
||||
PathAndCacheKey,
|
||||
RefreshIndexResults,
|
||||
|
|
@ -129,7 +128,7 @@ enum AddRemoveResultType {
|
|||
|
||||
async function getAddRemoveForTag(
|
||||
tag: IndexTag,
|
||||
currentFiles: LastModifiedMap,
|
||||
currentFiles: FileStatsMap,
|
||||
readFile: (path: string) => Promise<string>,
|
||||
): Promise<
|
||||
[
|
||||
|
|
@ -157,7 +156,7 @@ async function getAddRemoveForTag(
|
|||
remove.push(pathAndCacheKey);
|
||||
} else {
|
||||
// Exists in old and new, so determine whether it was updated
|
||||
if (lastUpdated < files[item.path]) {
|
||||
if (lastUpdated < files[item.path].lastModified) {
|
||||
// Change was made after last update
|
||||
const newHash = calculateHash(await readFile(pathAndCacheKey.path));
|
||||
if (pathAndCacheKey.cacheKey !== newHash) {
|
||||
|
|
@ -345,7 +344,7 @@ function mapIndexResultTypeToAddRemoveResultType(
|
|||
|
||||
export async function getComputeDeleteAddRemove(
|
||||
tag: IndexTag,
|
||||
currentFiles: LastModifiedMap,
|
||||
currentFiles: FileStatsMap,
|
||||
readFile: (path: string) => Promise<string>,
|
||||
repoName: string | undefined,
|
||||
): Promise<[RefreshIndexResults, PathAndCacheKey[], MarkCompleteCallback]> {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,4 @@ export type RefreshIndexResults = {
|
|||
removeTag: PathAndCacheKey[];
|
||||
};
|
||||
|
||||
export type LastModifiedMap = {
|
||||
[path: string]: number;
|
||||
};
|
||||
|
||||
export type RefreshIndex = (tag: IndexTag) => Promise<RefreshIndexResults>;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { ControlPlaneSessionInfo } from "../control-plane/client";
|
|||
import type {
|
||||
ContinueRcJson,
|
||||
DiffLine,
|
||||
FileStatsMap,
|
||||
FileType,
|
||||
IDE,
|
||||
IdeInfo,
|
||||
|
|
@ -84,7 +85,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
|
|||
];
|
||||
getGitRootPath: [{ dir: string }, string | undefined];
|
||||
listDir: [{ dir: string }, [string, FileType][]];
|
||||
getLastModified: [{ files: string[] }, { [path: string]: number }];
|
||||
getFileStats: [{ files: string[] }, FileStatsMap];
|
||||
|
||||
gotoDefinition: [{ location: Location }, RangeInFile[]];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { GetGhTokenArgs, ToIdeFromWebviewOrCoreProtocol } from "../ide";
|
||||
import { FromIdeProtocol } from "..";
|
||||
import { GetGhTokenArgs, ToIdeFromWebviewOrCoreProtocol } from "../ide";
|
||||
|
||||
import type {
|
||||
ContinueRcJson,
|
||||
FileStatsMap,
|
||||
FileType,
|
||||
IDE,
|
||||
IdeInfo,
|
||||
|
|
@ -43,8 +44,8 @@ export class MessageIde implements IDE {
|
|||
getGitHubAuthToken(args: GetGhTokenArgs): Promise<string | undefined> {
|
||||
return this.request("getGitHubAuthToken", args);
|
||||
}
|
||||
getLastModified(files: string[]): Promise<{ [path: string]: number }> {
|
||||
return this.request("getLastModified", { files });
|
||||
getFileStats(files: string[]): Promise<FileStatsMap> {
|
||||
return this.request("getFileStats", { files });
|
||||
}
|
||||
getGitRootPath(dir: string): Promise<string | undefined> {
|
||||
return this.request("getGitRootPath", { dir });
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ export class ReverseMessageIde {
|
|||
return this.ide.getGitHubAuthToken(data);
|
||||
});
|
||||
|
||||
this.on("getLastModified", (data) => {
|
||||
return this.ide.getLastModified(data.files);
|
||||
this.on("getFileStats", (data) => {
|
||||
return this.ide.getFileStats(data.files);
|
||||
});
|
||||
|
||||
this.on("getGitRootPath", (data) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import * as fs from "node:fs";
|
||||
|
||||
import { fileURLToPath } from "node:url";
|
||||
import {
|
||||
ContinueRcJson,
|
||||
FileStatsMap,
|
||||
FileType,
|
||||
IDE,
|
||||
IdeInfo,
|
||||
|
|
@ -15,7 +17,6 @@ import {
|
|||
ToastType,
|
||||
} from "../index.js";
|
||||
import { GetGhTokenArgs } from "../protocol/ide.js";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
class FileSystemIde implements IDE {
|
||||
constructor(private readonly workspaceDir: string) {}
|
||||
|
|
@ -51,15 +52,16 @@ class FileSystemIde implements IDE {
|
|||
async getGitHubAuthToken(args: GetGhTokenArgs): Promise<string | undefined> {
|
||||
return undefined;
|
||||
}
|
||||
async getLastModified(
|
||||
fileUris: string[],
|
||||
): Promise<{ [path: string]: number }> {
|
||||
const result: { [path: string]: number } = {};
|
||||
async getFileStats(fileUris: string[]): Promise<FileStatsMap> {
|
||||
const result: FileStatsMap = {};
|
||||
for (const uri of fileUris) {
|
||||
try {
|
||||
const filepath = fileURLToPath(uri);
|
||||
const stats = fs.statSync(filepath);
|
||||
result[uri] = stats.mtimeMs;
|
||||
result[uri] = {
|
||||
lastModified: stats.mtimeMs,
|
||||
size: stats.size,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Error getting last modified time for ${uri}:`, error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class MessageTypes {
|
|||
"getRepoName",
|
||||
"listDir",
|
||||
"getGitRootPath",
|
||||
"getLastModified",
|
||||
"getFileStats",
|
||||
"insertAtCursor",
|
||||
"applyToFile",
|
||||
"getGitHubAuthToken",
|
||||
|
|
|
|||
|
|
@ -215,13 +215,13 @@ class IdeProtocolClient(
|
|||
respond(null)
|
||||
}
|
||||
|
||||
"getLastModified" -> {
|
||||
"getFileStats" -> {
|
||||
val params = Gson().fromJson(
|
||||
dataElement.toString(),
|
||||
GetLastModifiedParams::class.java
|
||||
GetFileStatsParams::class.java
|
||||
)
|
||||
val lastModifiedMap = ide.getLastModified(params.files)
|
||||
respond(lastModifiedMap)
|
||||
val fileStatsMap = ide.getFileStats(params.files)
|
||||
respond(fileStatsMap)
|
||||
}
|
||||
|
||||
"listDir" -> {
|
||||
|
|
|
|||
|
|
@ -519,9 +519,9 @@ class IntelliJIDE(
|
|||
return files
|
||||
}
|
||||
|
||||
override suspend fun getLastModified(files: List<String>): Map<String, Long> {
|
||||
override suspend fun getFileStats(files: List<String>): Map<String, FileStats> {
|
||||
return files.associateWith { file ->
|
||||
File(URI(file)).lastModified()
|
||||
FileStats(File(URI(file)).lastModified(), File(URI(file)).length())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,4 +58,4 @@ data class GetGitRootPathParams(val dir: String)
|
|||
|
||||
data class ListDirParams(val dir: String)
|
||||
|
||||
data class GetLastModifiedParams(val files: List<String>)
|
||||
data class GetFileStatsParams(val files: List<String>)
|
||||
|
|
@ -77,6 +77,11 @@ data class Account(
|
|||
val id: String
|
||||
)
|
||||
|
||||
data class FileStats(
|
||||
val lastModified: Long,
|
||||
val size: Long
|
||||
)
|
||||
|
||||
data class IdeSettings(
|
||||
val remoteConfigServerUrl: String?,
|
||||
val remoteConfigSyncPeriod: Int,
|
||||
|
|
@ -183,7 +188,7 @@ interface IDE {
|
|||
// will serialize to `first and `second` rather than `0` and `1` like in JavaScript
|
||||
suspend fun listDir(dir: String): List<List<Any>>
|
||||
|
||||
suspend fun getLastModified(files: List<String>): Map<String, Long>
|
||||
suspend fun getFileStats(files: List<String>): Map<String, FileStats>
|
||||
|
||||
suspend fun getGitHubAuthToken(args: GetGhTokenArgs): String?
|
||||
|
||||
|
|
|
|||
|
|
@ -3,20 +3,20 @@ import { exec } from "node:child_process";
|
|||
|
||||
import { Range } from "core";
|
||||
import { EXTENSION_NAME } from "core/control-plane/env";
|
||||
import { walkDir } from "core/indexing/walkDir";
|
||||
import { GetGhTokenArgs } from "core/protocol/ide";
|
||||
import { editConfigJson, getConfigJsonPath } from "core/util/paths";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
import * as URI from "uri-js";
|
||||
import { executeGotoProvider } from "./autocomplete/lsp";
|
||||
import { Repository } from "./otherExtensions/git";
|
||||
import { VsCodeIdeUtils } from "./util/ideUtils";
|
||||
import { getExtensionUri, openEditorAndRevealRange } from "./util/vscode";
|
||||
import { VsCodeWebviewProtocol } from "./webviewProtocol";
|
||||
import * as URI from "uri-js";
|
||||
|
||||
import type {
|
||||
ContinueRcJson,
|
||||
FileStatsMap,
|
||||
FileType,
|
||||
IDE,
|
||||
IdeInfo,
|
||||
|
|
@ -27,7 +27,6 @@ import type {
|
|||
RangeInFile,
|
||||
Thread,
|
||||
} from "core";
|
||||
import { findUriInDirs } from "core/util/uri";
|
||||
|
||||
class VsCodeIde implements IDE {
|
||||
ideUtils: VsCodeIdeUtils;
|
||||
|
|
@ -274,12 +273,15 @@ class VsCodeIde implements IDE {
|
|||
);
|
||||
}
|
||||
|
||||
async getLastModified(files: string[]): Promise<{ [path: string]: number }> {
|
||||
const pathToLastModified: { [path: string]: number } = {};
|
||||
async getFileStats(files: string[]): Promise<FileStatsMap> {
|
||||
const pathToLastModified: FileStatsMap = {};
|
||||
await Promise.all(
|
||||
files.map(async (file) => {
|
||||
const stat = await vscode.workspace.fs.stat(vscode.Uri.parse(file));
|
||||
pathToLastModified[file] = stat.mtime;
|
||||
pathToLastModified[file] = {
|
||||
lastModified: stat.mtime,
|
||||
size: stat.size,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -473,8 +473,8 @@ export class VsCodeMessenger {
|
|||
return await ide.gotoDefinition(msg.data.location);
|
||||
});
|
||||
|
||||
this.onWebviewOrCore("getLastModified", async (msg) => {
|
||||
return await ide.getLastModified(msg.data.files);
|
||||
this.onWebviewOrCore("getFileStats", async (msg) => {
|
||||
return await ide.getFileStats(msg.data.files);
|
||||
});
|
||||
|
||||
this.onWebviewOrCore("getGitRootPath", async (msg) => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue