walk dir logging
This commit is contained in:
parent
35592be6e9
commit
bf9cc74ace
14 changed files with 151 additions and 28 deletions
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
|
|
@ -12,8 +12,8 @@
|
|||
"cwd": "${workspaceFolder}/extensions/vscode",
|
||||
"args": [
|
||||
// Pass a directory to manually test in
|
||||
"${workspaceFolder}/manual-testing-sandbox",
|
||||
"${workspaceFolder}/manual-testing-sandbox/test.js",
|
||||
"/Users/dallin/Documents/code/continuedev/continue-extras/react",
|
||||
"/Users/dallin/Documents/code/continuedev/continue-extras/react/README.md",
|
||||
"--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode"
|
||||
],
|
||||
"pauseForSourceMap": false,
|
||||
|
|
|
|||
|
|
@ -41,7 +41,9 @@ export async function getAssistantFilesFromDir(
|
|||
return [];
|
||||
}
|
||||
|
||||
const uris = await walkDir(dir, ide);
|
||||
const uris = await walkDir(dir, ide, {
|
||||
source: "get dir assistant files",
|
||||
});
|
||||
const assistantFilePaths = uris.filter(
|
||||
(p) => p.endsWith(".yaml") || p.endsWith(".yml"),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import {
|
|||
} from "../../";
|
||||
import { walkDirs } from "../../indexing/walkDir";
|
||||
import {
|
||||
getUriPathBasename,
|
||||
getShortestUniqueRelativeUriPaths,
|
||||
getUriDescription,
|
||||
getUriPathBasename,
|
||||
} from "../../util/uri";
|
||||
|
||||
const MAX_SUBMENU_ITEMS = 10_000;
|
||||
|
|
@ -53,7 +53,13 @@ class FileContextProvider extends BaseContextProvider {
|
|||
args: LoadSubmenuItemsArgs,
|
||||
): Promise<ContextSubmenuItem[]> {
|
||||
const workspaceDirs = await args.ide.getWorkspaceDirs();
|
||||
const results = await walkDirs(args.ide, undefined, workspaceDirs);
|
||||
const results = await walkDirs(
|
||||
args.ide,
|
||||
{
|
||||
source: "load submenu items - file",
|
||||
},
|
||||
workspaceDirs,
|
||||
);
|
||||
const files = results.flat().slice(-MAX_SUBMENU_ITEMS);
|
||||
const withUniquePaths = getShortestUniqueRelativeUriPaths(
|
||||
files,
|
||||
|
|
|
|||
|
|
@ -50,7 +50,9 @@ class FileTreeContextProvider extends BaseContextProvider {
|
|||
directories: [],
|
||||
};
|
||||
|
||||
const uris = await walkDir(workspaceDir, extras.ide);
|
||||
const uris = await walkDir(workspaceDir, extras.ide, {
|
||||
source: "get context items - file tree",
|
||||
});
|
||||
const relativePaths = uris.map(
|
||||
(uri) => findUriInDirs(uri, [workspaceDir]).relativePathOrBasename,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class FolderContextProvider extends BaseContextProvider {
|
|||
args.ide,
|
||||
{
|
||||
onlyDirs: true,
|
||||
source: "load submenu items - folder",
|
||||
},
|
||||
workspaceDirs,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class RepoMapContextProvider extends BaseContextProvider {
|
|||
args.ide,
|
||||
{
|
||||
onlyDirs: true,
|
||||
source: "load submenu items - repo map",
|
||||
},
|
||||
workspaceDirs,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -887,6 +887,7 @@ export class Core {
|
|||
uri.endsWith(".gitignore")
|
||||
) {
|
||||
// Reindex the workspaces
|
||||
// walkDirCache.invalidate();
|
||||
this.invoke("index/forceReIndex", {
|
||||
shouldClearIndexes: true,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -282,7 +282,9 @@ export class CodebaseIndexer {
|
|||
status: "indexing",
|
||||
};
|
||||
const directoryFiles = [];
|
||||
for await (const p of walkDirAsync(directory, this.ide)) {
|
||||
for await (const p of walkDirAsync(directory, this.ide, {
|
||||
source: "codebase indexing: refresh dirs",
|
||||
})) {
|
||||
directoryFiles.push(p);
|
||||
if (abortSignal.aborted) {
|
||||
yield {
|
||||
|
|
|
|||
|
|
@ -12,10 +12,14 @@ import {
|
|||
export interface WalkerOptions {
|
||||
onlyDirs?: boolean;
|
||||
returnRelativeUrisPaths?: boolean;
|
||||
source?: string;
|
||||
}
|
||||
|
||||
type Entry = [string, FileType];
|
||||
|
||||
const LIST_DIR_CACHE_TIME = 30_000; // 30 seconds
|
||||
const IGNORE_FILE_CACHE_TIME = 30_000; // 30 seconds
|
||||
|
||||
// helper struct used for the DFS walk
|
||||
type WalkableEntry = {
|
||||
name: string;
|
||||
|
|
@ -36,6 +40,32 @@ type IgnoreContext = {
|
|||
dirname: string;
|
||||
};
|
||||
|
||||
class WalkDirCache {
|
||||
dirListCache: Map<
|
||||
string,
|
||||
{
|
||||
time: number;
|
||||
entries: Promise<[string, FileType][]>;
|
||||
}
|
||||
> = new Map();
|
||||
dirIgnoreCache: Map<
|
||||
string,
|
||||
{
|
||||
time: number;
|
||||
ignore: Promise<Ignore>;
|
||||
}
|
||||
> = new Map();
|
||||
}
|
||||
export const walkDirCache = new WalkDirCache(); // todo - singleton approach better?
|
||||
|
||||
// class ListDirCache {
|
||||
// private cache: Map<string, >();
|
||||
// getCacheKey(options: WalkerOptions) {
|
||||
// return `${options.returnRelativeUrisPaths ? "relative" : "absolute"}-${options.onlyDirs ? "dirs" : "files"}`;
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
class DFSWalker {
|
||||
constructor(
|
||||
private readonly uri: string,
|
||||
|
|
@ -45,9 +75,19 @@ class DFSWalker {
|
|||
|
||||
// walk is a depth-first search implementation
|
||||
public async *walk(): AsyncGenerator<string> {
|
||||
const start = Date.now();
|
||||
let ignoreFileTime = 0;
|
||||
let ignoreTime = 0;
|
||||
let listDirTime = 0;
|
||||
let dirs = 0;
|
||||
let listDirCacheHits = 0;
|
||||
let ignoreCacheHits = 0;
|
||||
|
||||
let section = Date.now();
|
||||
const defaultAndGlobalIgnores = ignore()
|
||||
.add(defaultIgnoreFileAndDir)
|
||||
.add(getGlobalContinueIgArray());
|
||||
ignoreFileTime += Date.now() - section;
|
||||
|
||||
const rootContext: WalkContext = {
|
||||
walkableEntry: {
|
||||
|
|
@ -62,15 +102,62 @@ class DFSWalker {
|
|||
const stack = [rootContext];
|
||||
|
||||
for (let cur = stack.pop(); cur; cur = stack.pop()) {
|
||||
// Only directories will be added to the stack
|
||||
const entries = await this.ide.listDir(cur.walkableEntry.uri);
|
||||
// const entries = await this.ide.listDir(cur.walkableEntry.uri);
|
||||
// const newIgnore = await getIgnoreContext(
|
||||
// cur.walkableEntry.uri,
|
||||
// entries,
|
||||
// this.ide,
|
||||
// defaultAndGlobalIgnores,
|
||||
// );
|
||||
|
||||
const newIgnore = await getIgnoreContext(
|
||||
// Only directories will be added to the stack
|
||||
dirs++;
|
||||
|
||||
section = Date.now();
|
||||
let entries: [string, FileType][] = [];
|
||||
const cachedListdir = walkDirCache.dirListCache.get(
|
||||
cur.walkableEntry.uri,
|
||||
entries,
|
||||
this.ide,
|
||||
defaultAndGlobalIgnores,
|
||||
);
|
||||
if (
|
||||
cachedListdir &&
|
||||
cachedListdir.time > Date.now() - LIST_DIR_CACHE_TIME
|
||||
) {
|
||||
entries = await cachedListdir.entries;
|
||||
listDirCacheHits++;
|
||||
} else {
|
||||
const promise = this.ide.listDir(cur.walkableEntry.uri);
|
||||
walkDirCache.dirListCache.set(cur.walkableEntry.uri, {
|
||||
time: Date.now(),
|
||||
entries: promise,
|
||||
});
|
||||
entries = await promise;
|
||||
}
|
||||
listDirTime += Date.now() - section;
|
||||
|
||||
section = Date.now();
|
||||
let newIgnore: Ignore;
|
||||
const cachedIgnore = walkDirCache.dirIgnoreCache.get(
|
||||
cur.walkableEntry.uri,
|
||||
);
|
||||
if (
|
||||
cachedIgnore &&
|
||||
cachedIgnore.time > Date.now() - IGNORE_FILE_CACHE_TIME
|
||||
) {
|
||||
newIgnore = await cachedIgnore.ignore;
|
||||
ignoreCacheHits++;
|
||||
} else {
|
||||
const ignorePromise = getIgnoreContext(
|
||||
cur.walkableEntry.uri,
|
||||
entries,
|
||||
this.ide,
|
||||
defaultAndGlobalIgnores,
|
||||
);
|
||||
walkDirCache.dirIgnoreCache.set(cur.walkableEntry.uri, {
|
||||
time: Date.now(),
|
||||
ignore: ignorePromise,
|
||||
});
|
||||
newIgnore = await ignorePromise;
|
||||
}
|
||||
|
||||
const ignoreContexts = [
|
||||
...cur.ignoreContexts,
|
||||
|
|
@ -79,6 +166,7 @@ class DFSWalker {
|
|||
dirname: cur.walkableEntry.relativeUriPath,
|
||||
},
|
||||
];
|
||||
ignoreFileTime += Date.now() - section;
|
||||
|
||||
for (const entry of entries) {
|
||||
if (this.entryIsSymlink(entry)) {
|
||||
|
|
@ -103,19 +191,24 @@ class DFSWalker {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
let shouldInclude = true;
|
||||
let shouldIgnore = false;
|
||||
for (const ig of ignoreContexts) {
|
||||
if (shouldIgnore) {
|
||||
continue;
|
||||
}
|
||||
// remove the directory name and path separator from the match path, unless this an ignore file
|
||||
// in the root directory
|
||||
const prefixLength =
|
||||
ig.dirname.length === 0 ? 0 : ig.dirname.length + 1;
|
||||
// The ignore library expects a path relative to the ignore file location
|
||||
const matchPath = relPath.substring(prefixLength);
|
||||
section = Date.now();
|
||||
if (ig.ignore.ignores(matchPath)) {
|
||||
shouldInclude = false;
|
||||
shouldIgnore = true;
|
||||
}
|
||||
ignoreTime += Date.now() - section;
|
||||
}
|
||||
if (!shouldInclude) {
|
||||
if (shouldIgnore) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -141,6 +234,10 @@ class DFSWalker {
|
|||
}
|
||||
}
|
||||
}
|
||||
// console.log(walkDirCache.listDirCache.values().toArray().slice(0, 30));
|
||||
console.log(
|
||||
`Walk Dir Result:\nSource: ${this.options.source ?? "unknown"}\nDir: ${this.uri}\nDuration: ${Date.now() - start}ms:\n\tList dir: ${listDirTime}ms (${listDirCacheHits}/${dirs} cache hits)\n\tIgnore files: ${ignoreFileTime}ms (${ignoreCacheHits}/${dirs} cache hits)\n\tIgnoring: ${ignoreTime}ms`,
|
||||
);
|
||||
}
|
||||
|
||||
private entryIsDirectory(entry: Entry) {
|
||||
|
|
@ -162,10 +259,8 @@ export async function* walkDirAsync(
|
|||
ide: IDE,
|
||||
_optionOverrides?: WalkerOptions,
|
||||
): AsyncGenerator<string> {
|
||||
const start = Date.now();
|
||||
const options = { ...defaultOptions, ..._optionOverrides };
|
||||
yield* new DFSWalker(path, ide, options).walk();
|
||||
console.log(`walkDir took ${Date.now() - start}ms`);
|
||||
}
|
||||
|
||||
export async function walkDir(
|
||||
|
|
@ -229,6 +324,10 @@ export async function getIgnoreContext(
|
|||
getContinueIgnorePatterns(),
|
||||
]);
|
||||
|
||||
if (ignoreArrays[0].length === 0 && ignoreArrays[1].length === 0) {
|
||||
return defaultAndGlobalIgnores;
|
||||
}
|
||||
|
||||
// Note precedence here!
|
||||
const ignoreContext = ignore()
|
||||
.add(ignoreArrays[0]) // gitignore
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ export async function getPromptFilesFromDir(
|
|||
return [];
|
||||
}
|
||||
|
||||
const uris = await walkDir(dir, ide);
|
||||
const uris = await walkDir(dir, ide, {
|
||||
source: "get dir prompt files",
|
||||
});
|
||||
const promptFilePaths = uris.filter((p) => p.endsWith(".prompt"));
|
||||
const results = promptFilePaths.map(async (uri) => {
|
||||
const content = await ide.readFile(uri); // make a try catch
|
||||
|
|
|
|||
|
|
@ -50,7 +50,13 @@ class RepoMapGenerator {
|
|||
|
||||
async generate(): Promise<string> {
|
||||
this.dirs = this.options.dirUris ?? (await this.ide.getWorkspaceDirs());
|
||||
this.allUris = await walkDirs(this.ide, undefined, this.dirs);
|
||||
this.allUris = await walkDirs(
|
||||
this.ide,
|
||||
{
|
||||
source: "generate repo map",
|
||||
},
|
||||
this.dirs,
|
||||
);
|
||||
|
||||
// Initialize
|
||||
await this.writeToStream(this.PREAMBLE);
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "1.1.5",
|
||||
"version": "1.1.7",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "1.1.5",
|
||||
"version": "1.1.7",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@continuedev/fetch": "^1.0.3",
|
||||
|
|
|
|||
|
|
@ -819,7 +819,9 @@ const getCommandsMap: (
|
|||
.stat(uri)
|
||||
?.then((stat) => stat.type === vscode.FileType.Directory);
|
||||
if (isDirectory) {
|
||||
for await (const fileUri of walkDirAsync(uri.toString(), ide)) {
|
||||
for await (const fileUri of walkDirAsync(uri.toString(), ide, {
|
||||
source: "vscode continue.selectFilesAsContext command",
|
||||
})) {
|
||||
addEntireFileToContext(
|
||||
vscode.Uri.parse(fileUri),
|
||||
sidebar.webviewProtocol,
|
||||
|
|
@ -962,10 +964,7 @@ const getCommandsMap: (
|
|||
vscode.commands.executeCommand("continue.giveAutocompleteFeedback");
|
||||
} else if (selectedOption === "$(comment) Open chat") {
|
||||
vscode.commands.executeCommand("continue.focusContinueInput");
|
||||
} else if (
|
||||
selectedOption ===
|
||||
"$(screen-full) Open full screen chat"
|
||||
) {
|
||||
} else if (selectedOption === "$(screen-full) Open full screen chat") {
|
||||
vscode.commands.executeCommand("continue.toggleFullScreen");
|
||||
} else if (selectedOption === "$(question) Open help center") {
|
||||
focusGUI();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,9 @@ export class FileSearch {
|
|||
},
|
||||
});
|
||||
private async initializeFileSearchState() {
|
||||
const results = await walkDirs(this.ide);
|
||||
const results = await walkDirs(this.ide, {
|
||||
source: "file search initialization",
|
||||
});
|
||||
this.miniSearch.addAll(
|
||||
results.flat().map((uri) => ({
|
||||
id: uri,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue