refactor: use ide.readFile instead of fs.readFile in static context service

This commit is contained in:
uinstinct 2025-10-24 10:44:52 +05:30
parent 8fe0288937
commit 9166bda360

View file

@ -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<void> {
const scanRecursively = async (currentPath: string): Promise<void> => {
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;