1- import * as fs from "fs/promises" ;
21import path from "path" ;
32import { pathToFileURL } from "url" ;
43import Parser from "web-tree-sitter" ;
5- import { IDE , Position } from "../../.." ;
4+ import { FileType , IDE , Position } from "../../.." ;
65import { localPathOrUriToPath } from "../../../util/pathToUri" ;
76import { getFullLanguageName , getQueryForFile } from "../../../util/treeSitter" ;
87import {
@@ -353,10 +352,7 @@ export class StaticContextService {
353352 if ( foundContents . has ( tdLocation . filepath ) ) {
354353 content = foundContents . get ( tdLocation . filepath ) ! ;
355354 } else {
356- content = await fs . readFile (
357- localPathOrUriToPath ( tdLocation . filepath ) ,
358- "utf8" ,
359- ) ;
355+ content = await this . ide . readFile ( tdLocation . filepath ) ;
360356 foundContents . set ( tdLocation . filepath , content ) ;
361357 }
362358
@@ -854,24 +850,20 @@ export class StaticContextService {
854850 return skipDirs . includes ( dirName ) || dirName . startsWith ( "." ) ;
855851 } ;
856852
857- async function scanRecursively ( currentPath : string ) : Promise < void > {
853+ const scanRecursively = async ( currentPath : string ) : Promise < void > = > {
858854 try {
859- const entries = await fs . readdir ( currentPath , {
860- withFileTypes : true ,
861- } ) ;
855+ const currentUri = pathToFileURL ( currentPath ) . toString ( ) ;
856+ const entries = await this . ide . listDir ( currentUri ) ;
862857
863- for ( const entry of entries ) {
864- const fullPath = localPathOrUriToPath (
865- path . join ( currentPath , entry . name ) ,
866- ) ;
858+ for ( const [ name , fileType ] of entries ) {
859+ const fullPath = localPathOrUriToPath ( path . join ( currentPath , name ) ) ;
867860
868- if ( entry . isDirectory ( ) ) {
869- // Skip common directories that typically don't contain source files
870- if ( ! shouldSkipDirectory ( entry . name ) ) {
861+ if ( fileType === FileType . Directory ) {
862+ if ( ! shouldSkipDirectory ( name ) ) {
871863 await scanRecursively ( fullPath ) ;
872864 }
873- } else if ( entry . isFile ( ) ) {
874- const extension = path . extname ( entry . name ) . toLowerCase ( ) ;
865+ } else if ( fileType === FileType . File ) {
866+ const extension = path . extname ( name ) . toLowerCase ( ) ;
875867 if ( tsExtensions . includes ( extension ) ) {
876868 tsFiles . push ( fullPath ) ;
877869 }
@@ -880,7 +872,7 @@ export class StaticContextService {
880872 } catch ( error ) {
881873 console . error ( `Error reading directory ${ currentPath } :` , error ) ;
882874 }
883- }
875+ } ;
884876
885877 await scanRecursively ( dirPath ) ;
886878 return tsFiles ;
0 commit comments