From 6f4b0f18adbf0da8a74d5248de72b4dfee9cd2c7 Mon Sep 17 00:00:00 2001 From: Pranjal Rana <129268721+PRANJALRANA11@users.noreply.github.com> Date: Sat, 2 Nov 2024 10:46:39 +0530 Subject: [PATCH] fix rel-path for ignore --- core/core.ts | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/core/core.ts b/core/core.ts index 11b5ddb016..a3f59ec8e3 100644 --- a/core/core.ts +++ b/core/core.ts @@ -29,7 +29,9 @@ import type { IMessenger, Message } from "./util/messenger"; import { editConfigJson, setupInitialDotContinueDirectory } from "./util/paths"; import { Telemetry } from "./util/posthog"; import { TTS } from "./util/tts"; -import { walkDir } from "./indexing/walkDir"; +import ignore from "ignore"; +import { defaultIgnoreFile } from "./indexing/ignore.js"; +import path from "path"; export class Core { // implements IMessenger @@ -704,41 +706,17 @@ export class Core { const url = await getAuthUrlForTokenPage(); return { url }; }); + on("didChangeActiveTextEditor", async ({ data: { filepath } }) => { - let dirs = await this.ide.getWorkspaceDirs(); - let memoizedFunction = await this.memoizedFunction(dirs); - if (memoizedFunction.includes(filepath)) { - console.log("yep running"); + const ignoreInstance = ignore().add(defaultIgnoreFile); + let rootDirectory = await this.ide.getWorkspaceDirs(); + const relativeFilePath = path.relative(rootDirectory[0], filepath); + if (!ignoreInstance.ignores(relativeFilePath)) { recentlyEditedFilesCache.set(filepath, filepath); } }); } - private memoize Promise>( - fn: T, - ): (...args: Parameters) => Promise> { - const cache = new Map>>(); - - return async function (...args: Parameters): Promise> { - const key = JSON.stringify(args); - if (cache.has(key)) { - return cache.get(key) as Promise>; - } - const result = await fn(...args); - cache.set(key, Promise.resolve(result)); - return result; - }; - } - - private async checkIgnoredFiles(dirs: string[]): Promise { - console.log("called"); - const paths = await walkDir(dirs[0], this.ide); - return paths; - } - - // Memoize the async checkIgnoredFiles function - memoizedFunction = this.memoize(this.checkIgnoredFiles.bind(this)); - private indexingCancellationController: AbortController | undefined; private async refreshCodebaseIndex(dirs: string[]) {