@@ -17,13 +17,13 @@ namespace ts.Completions.PathCompletions {
1717 }
1818
1919 export function getStringLiteralCompletionsFromModuleNames ( sourceFile : SourceFile , node : LiteralExpression , compilerOptions : CompilerOptions , host : LanguageServiceHost , typeChecker : TypeChecker ) : ReadonlyArray < PathCompletion > {
20- return addReplacementSpans ( node . text , node . getStart ( sourceFile ) + 1 , getStringLiteralCompletionsFromModuleNamesWorker ( node , compilerOptions , host , typeChecker ) ) ;
20+ return addReplacementSpans ( node . text , node . getStart ( sourceFile ) + 1 , getStringLiteralCompletionsFromModuleNamesWorker ( sourceFile , node , compilerOptions , host , typeChecker ) ) ;
2121 }
2222
23- function getStringLiteralCompletionsFromModuleNamesWorker ( node : LiteralExpression , compilerOptions : CompilerOptions , host : LanguageServiceHost , typeChecker : TypeChecker ) : ReadonlyArray < NameAndKind > {
23+ function getStringLiteralCompletionsFromModuleNamesWorker ( sourceFile : SourceFile , node : LiteralExpression , compilerOptions : CompilerOptions , host : LanguageServiceHost , typeChecker : TypeChecker ) : ReadonlyArray < NameAndKind > {
2424 const literalValue = normalizeSlashes ( node . text ) ;
2525
26- const scriptPath = node . getSourceFile ( ) . path ;
26+ const scriptPath = sourceFile . path ;
2727 const scriptDirectory = getDirectoryPath ( scriptPath ) ;
2828
2929 if ( isPathRelativeToScript ( literalValue ) || isRootedDiskPath ( literalValue ) ) {
@@ -37,7 +37,6 @@ namespace ts.Completions.PathCompletions {
3737 }
3838 }
3939 else {
40- // Check for node modules
4140 return getCompletionEntriesForNonRelativeModules ( literalValue , scriptDirectory , compilerOptions , host , typeChecker ) ;
4241 }
4342 }
@@ -225,16 +224,17 @@ namespace ts.Completions.PathCompletions {
225224 ) : ReadonlyArray < NameAndKind > {
226225 if ( ! endsWith ( path , "*" ) ) {
227226 // For a path mapping "foo": ["/x/y/z.ts"], add "foo" itself as a completion.
228- return ! stringContains ( path , "*" ) && startsWith ( path , fragment ) ? [ { name : path , kind : ScriptElementKind . directory } ] : emptyArray ;
227+ return ! stringContains ( path , "*" ) ? justPathMappingName ( path ) : emptyArray ;
229228 }
230229
231230 const pathPrefix = path . slice ( 0 , path . length - 1 ) ;
232- if ( ! startsWith ( fragment , pathPrefix ) ) {
233- return [ { name : pathPrefix , kind : ScriptElementKind . directory } ] ;
234- }
231+ const remainingFragment = tryRemovePrefix ( fragment , pathPrefix ) ;
232+ return remainingFragment === undefined ? justPathMappingName ( pathPrefix ) : flatMap ( patterns , pattern =>
233+ getModulesForPathsPattern ( remainingFragment , baseUrl , pattern , fileExtensions , host ) ) ;
235234
236- const remainingFragment = fragment . slice ( pathPrefix . length ) ;
237- return flatMap ( patterns , pattern => getModulesForPathsPattern ( remainingFragment , baseUrl , pattern , fileExtensions , host ) ) ;
235+ function justPathMappingName ( name : string ) : ReadonlyArray < NameAndKind > {
236+ return startsWith ( name , fragment ) ? [ { name, kind : ScriptElementKind . directory } ] : emptyArray ;
237+ }
238238 }
239239
240240 function getModulesForPathsPattern ( fragment : string , baseUrl : string , pattern : string , fileExtensions : ReadonlyArray < string > , host : LanguageServiceHost ) : ReadonlyArray < NameAndKind > | undefined {
0 commit comments