@@ -281,33 +281,26 @@ namespace ts.Completions.StringCompletions {
281
281
* Takes a script path and returns paths for all potential folders that could be merged with its
282
282
* containing folder via the "rootDirs" compiler option
283
283
*/
284
- function getBaseDirectoriesFromRootDirs ( rootDirs : string [ ] , basePath : string , scriptPath : string , ignoreCase : boolean ) : string [ ] {
284
+ function getBaseDirectoriesFromRootDirs ( rootDirs : string [ ] , basePath : string , scriptDirectory : string , ignoreCase : boolean ) : ReadonlyArray < string > {
285
285
// Make all paths absolute/normalized if they are not already
286
286
rootDirs = rootDirs . map ( rootDirectory => normalizePath ( isRootedDiskPath ( rootDirectory ) ? rootDirectory : combinePaths ( basePath , rootDirectory ) ) ) ;
287
287
288
288
// Determine the path to the directory containing the script relative to the root directory it is contained within
289
289
const relativeDirectory = firstDefined ( rootDirs , rootDirectory =>
290
- containsPath ( rootDirectory , scriptPath , basePath , ignoreCase ) ? scriptPath . substr ( rootDirectory . length ) : undefined ) ! ; // TODO: GH#18217
290
+ containsPath ( rootDirectory , scriptDirectory , basePath , ignoreCase ) ? scriptDirectory . substr ( rootDirectory . length ) : undefined ) ! ; // TODO: GH#18217
291
291
292
292
// Now find a path for each potential directory that is to be merged with the one containing the script
293
293
return deduplicate < string > (
294
- rootDirs . map ( rootDirectory => combinePaths ( rootDirectory , relativeDirectory ) ) ,
294
+ [ ... rootDirs . map ( rootDirectory => combinePaths ( rootDirectory , relativeDirectory ) ) , scriptDirectory ] ,
295
295
equateStringsCaseSensitive ,
296
296
compareStringsCaseSensitive ) ;
297
297
}
298
298
299
- function getCompletionEntriesForDirectoryFragmentWithRootDirs ( rootDirs : string [ ] , fragment : string , scriptPath : string , extensionOptions : ExtensionOptions , compilerOptions : CompilerOptions , host : LanguageServiceHost , exclude ? : string ) : NameAndKind [ ] {
299
+ function getCompletionEntriesForDirectoryFragmentWithRootDirs ( rootDirs : string [ ] , fragment : string , scriptDirectory : string , extensionOptions : ExtensionOptions , compilerOptions : CompilerOptions , host : LanguageServiceHost , exclude : string ) : ReadonlyArray < NameAndKind > {
300
300
const basePath = compilerOptions . project || host . getCurrentDirectory ( ) ;
301
301
const ignoreCase = ! ( host . useCaseSensitiveFileNames && host . useCaseSensitiveFileNames ( ) ) ;
302
- const baseDirectories = getBaseDirectoriesFromRootDirs ( rootDirs , basePath , scriptPath , ignoreCase ) ;
303
-
304
- const result : NameAndKind [ ] = [ ] ;
305
-
306
- for ( const baseDirectory of baseDirectories ) {
307
- getCompletionEntriesForDirectoryFragment ( fragment , baseDirectory , extensionOptions , host , exclude , result ) ;
308
- }
309
-
310
- return result ;
302
+ const baseDirectories = getBaseDirectoriesFromRootDirs ( rootDirs , basePath , scriptDirectory , ignoreCase ) ;
303
+ return flatMap ( baseDirectories , baseDirectory => getCompletionEntriesForDirectoryFragment ( fragment , baseDirectory , extensionOptions , host , exclude ) ) ;
311
304
}
312
305
313
306
/**
0 commit comments