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,19 @@ 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- } ) ;
862-
863- for ( const entry of entries ) {
864- const fullPath = localPathOrUriToPath (
865- path . join ( currentPath , entry . name ) ,
866- ) ;
855+ const currentUri = pathToFileURL ( currentPath ) . toString ( ) ;
856+ const entries = await this . ide . listDir ( currentUri ) ;
857+ for ( const [ name , fileType ] of entries ) {
858+ const fullPath = localPathOrUriToPath ( path . join ( currentPath , name ) ) ;
867859
868- if ( entry . isDirectory ( ) ) {
869- // Skip common directories that typically don't contain source files
870- if ( ! shouldSkipDirectory ( entry . name ) ) {
860+ if ( fileType === ( 2 as FileType . Directory ) ) {
861+ if ( ! shouldSkipDirectory ( name ) ) {
871862 await scanRecursively ( fullPath ) ;
872863 }
873- } else if ( entry . isFile ( ) ) {
874- const extension = path . extname ( entry . name ) . toLowerCase ( ) ;
864+ } else if ( fileType === ( 1 as FileType . File ) ) {
865+ const extension = path . extname ( name ) . toLowerCase ( ) ;
875866 if ( tsExtensions . includes ( extension ) ) {
876867 tsFiles . push ( fullPath ) ;
877868 }
@@ -880,7 +871,7 @@ export class StaticContextService {
880871 } catch ( error ) {
881872 console . error ( `Error reading directory ${ currentPath } :` , error ) ;
882873 }
883- }
874+ } ;
884875
885876 await scanRecursively ( dirPath ) ;
886877 return tsFiles ;
0 commit comments