@@ -351,6 +351,12 @@ namespace ts.Completions {
351
351
const files = tryReadDirectory ( host , baseDirectory , extensions , /*exclude*/ undefined , /*include*/ [ "./*" ] ) ;
352
352
353
353
if ( files ) {
354
+ /**
355
+ * Multiple file entries might map to the same truncated name once we remove extensions
356
+ * (happens iff includeExtensions === false)so we use a set-like data structure. Eg:
357
+ *
358
+ * both foo.ts and foo.tsx become foo
359
+ */
354
360
const foundFiles = createMap < boolean > ( ) ;
355
361
for ( let filePath of files ) {
356
362
filePath = normalizePath ( filePath ) ;
@@ -360,6 +366,11 @@ namespace ts.Completions {
360
366
361
367
const foundFileName = includeExtensions ? getBaseFileName ( filePath ) : removeFileExtension ( getBaseFileName ( filePath ) ) ;
362
368
369
+ // Only add entries that contain the basename as a substring.
370
+ if ( foundFileName . indexOf ( baseName ) === - 1 ) {
371
+ continue ;
372
+ }
373
+
363
374
if ( ! foundFiles [ foundFileName ] ) {
364
375
foundFiles [ foundFileName ] = true ;
365
376
}
@@ -377,13 +388,16 @@ namespace ts.Completions {
377
388
for ( const directory of directories ) {
378
389
const directoryName = getBaseFileName ( normalizePath ( directory ) ) ;
379
390
391
+ // Only add entries that contain the basename as a substring.
392
+ if ( directoryName . indexOf ( baseName ) === - 1 ) {
393
+ continue ;
394
+ }
395
+
380
396
result . push ( createCompletionEntryForModule ( directoryName , ScriptElementKind . directory , span ) ) ;
381
397
}
382
398
}
383
399
}
384
400
385
- result = result . filter ( entry => entry . name . indexOf ( baseName ) >= 0 ) ;
386
-
387
401
return result ;
388
402
}
389
403
0 commit comments