From 9166bda360a0aa27006e1ea1503a2bd1071f5dba Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 24 Oct 2025 10:44:52 +0530 Subject: [PATCH 1/2] refactor: use ide.readFile instead of fs.readFile in static context service --- .../static-context/StaticContextService.ts | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/core/autocomplete/context/static-context/StaticContextService.ts b/core/autocomplete/context/static-context/StaticContextService.ts index b955a38ff4c..29f10447bcb 100644 --- a/core/autocomplete/context/static-context/StaticContextService.ts +++ b/core/autocomplete/context/static-context/StaticContextService.ts @@ -1,8 +1,7 @@ -import * as fs from "fs/promises"; import path from "path"; import { pathToFileURL } from "url"; import Parser from "web-tree-sitter"; -import { IDE, Position } from "../../.."; +import { FileType, IDE, Position } from "../../.."; import { localPathOrUriToPath } from "../../../util/pathToUri"; import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; import { @@ -353,10 +352,7 @@ export class StaticContextService { if (foundContents.has(tdLocation.filepath)) { content = foundContents.get(tdLocation.filepath)!; } else { - content = await fs.readFile( - localPathOrUriToPath(tdLocation.filepath), - "utf8", - ); + content = await this.ide.readFile(tdLocation.filepath); foundContents.set(tdLocation.filepath, content); } @@ -854,24 +850,20 @@ export class StaticContextService { return skipDirs.includes(dirName) || dirName.startsWith("."); }; - async function scanRecursively(currentPath: string): Promise { + const scanRecursively = async (currentPath: string): Promise => { try { - const entries = await fs.readdir(currentPath, { - withFileTypes: true, - }); + const currentUri = pathToFileURL(currentPath).toString(); + const entries = await this.ide.listDir(currentUri); - for (const entry of entries) { - const fullPath = localPathOrUriToPath( - path.join(currentPath, entry.name), - ); + for (const [name, fileType] of entries) { + const fullPath = localPathOrUriToPath(path.join(currentPath, name)); - if (entry.isDirectory()) { - // Skip common directories that typically don't contain source files - if (!shouldSkipDirectory(entry.name)) { + if (fileType === FileType.Directory) { + if (!shouldSkipDirectory(name)) { await scanRecursively(fullPath); } - } else if (entry.isFile()) { - const extension = path.extname(entry.name).toLowerCase(); + } else if (fileType === FileType.File) { + const extension = path.extname(name).toLowerCase(); if (tsExtensions.includes(extension)) { tsFiles.push(fullPath); } @@ -880,7 +872,7 @@ export class StaticContextService { } catch (error) { console.error(`Error reading directory ${currentPath}:`, error); } - } + }; await scanRecursively(dirPath); return tsFiles; From 74af332dcbb962cb00146a8b8588d06236b59e8d Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 28 Oct 2025 09:14:19 +0530 Subject: [PATCH 2/2] fix tests fix tests Revert "fix tests" This reverts commit 7be374d70bd220d73154cd254ea91cab45c8a249. --- .../context/static-context/StaticContextService.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/autocomplete/context/static-context/StaticContextService.ts b/core/autocomplete/context/static-context/StaticContextService.ts index 29f10447bcb..a756abc63cb 100644 --- a/core/autocomplete/context/static-context/StaticContextService.ts +++ b/core/autocomplete/context/static-context/StaticContextService.ts @@ -1,7 +1,7 @@ import path from "path"; import { pathToFileURL } from "url"; import Parser from "web-tree-sitter"; -import { FileType, IDE, Position } from "../../.."; +import { FileType, IDE, Position } from "../../../"; import { localPathOrUriToPath } from "../../../util/pathToUri"; import { getFullLanguageName, getQueryForFile } from "../../../util/treeSitter"; import { @@ -854,15 +854,14 @@ export class StaticContextService { try { const currentUri = pathToFileURL(currentPath).toString(); const entries = await this.ide.listDir(currentUri); - for (const [name, fileType] of entries) { const fullPath = localPathOrUriToPath(path.join(currentPath, name)); - if (fileType === FileType.Directory) { + if (fileType === (2 as FileType.Directory)) { if (!shouldSkipDirectory(name)) { await scanRecursively(fullPath); } - } else if (fileType === FileType.File) { + } else if (fileType === (1 as FileType.File)) { const extension = path.extname(name).toLowerCase(); if (tsExtensions.includes(extension)) { tsFiles.push(fullPath);