1- import glob from 'glob' ;
21import path from 'path' ;
32import Cache from "vscode-rpgle/language/models/cache" ;
43import { IncludeStatement } from "vscode-rpgle/language/parserTypes" ;
@@ -11,7 +10,7 @@ import { rpgExtensions, clExtensions, ddsExtension, sqlExtensions, srvPgmExtensi
1110import Parser from "vscode-rpgle/language/parser" ;
1211import { setupParser } from './languages/rpgle' ;
1312import { Logger } from './logger' ;
14- import { asPosix , getReferenceObjectsFrom , getSystemNameFromPath , toLocalPath } from './utils' ;
13+ import { asPosix , getReferenceObjectsFrom , getSystemNameFromPath , globalEntryIsValid , toLocalPath } from './utils' ;
1514import { extCanBeProgram , getObjectType } from './builders/environment' ;
1615import { isSqlFunction } from './languages/sql' ;
1716import { ReadFileSystem } from './readFileSystem' ;
@@ -294,40 +293,43 @@ export class Targets {
294293 return this . getResolvedObjects ( ) . find ( o => ( o . systemName === lookFor . name || o . longName ?. toUpperCase ( ) === lookFor . name ) && ( lookFor . types === undefined || lookFor . types . includes ( o . type ) ) ) ;
295294 }
296295
297- public resolveLocalFile ( name : string , baseFile ?: string ) : string | undefined {
296+ public async resolveLocalFile ( name : string , baseFile ?: string ) : Promise < string > {
298297 name = name . toUpperCase ( ) ;
299298
300299 if ( this . resolvedSearches [ name ] ) return this . resolvedSearches [ name ] ;
301300
302301 if ( ! this . pathCache ) {
303- // We don't really want to spam the FS
304- // So we can a list of files which can then
305- // use in glob again later.
306302 this . pathCache = { } ;
307303
308- glob . sync ( `**/*` , {
304+ ( await this . fs . getFiles ( this . getCwd ( ) , `**/*` , {
309305 cwd : this . cwd ,
310306 absolute : true ,
311307 nocase : true ,
312- } ) . forEach ( localPath => {
308+ } ) ) . forEach ( localPath => {
313309 this . pathCache [ localPath ] = true ;
314310 } ) ;
315311 }
316312
317- let globString = `**/${ name } *` ;
313+ const searchCache = ( ) : string | undefined => {
314+ for ( let entry in this . pathCache ) {
315+ if ( Array . isArray ( this . pathCache [ entry ] ) ) {
316+ const subEntry = this . pathCache [ entry ] . find ( e => globalEntryIsValid ( e , name ) ) ;
317+ if ( subEntry ) {
318+ return subEntry ;
319+ }
320+ } else {
321+ if ( globalEntryIsValid ( entry , name ) ) {
322+ return entry ;
323+ }
324+ }
325+ }
326+ }
318327
319- // TODO: replace with rfs.getFiles
320- const results = glob . sync ( globString , {
321- cwd : this . cwd ,
322- absolute : true ,
323- nocase : true ,
324- ignore : baseFile ? `**/${ baseFile } ` : undefined ,
325- cache : this . pathCache
326- } ) ;
328+ const result = searchCache ( ) ;
327329
328- if ( results [ 0 ] ) {
330+ if ( result ) {
329331 // To local path is required because glob returns posix paths
330- const localPath = toLocalPath ( results [ 0 ] )
332+ const localPath = toLocalPath ( result )
331333 this . resolvedSearches [ name ] = localPath ;
332334 return localPath ;
333335 }
0 commit comments