@@ -17,13 +17,13 @@ namespace ts.Completions.PathCompletions {
17
17
}
18
18
19
19
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 ) ) ;
21
21
}
22
22
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 > {
24
24
const literalValue = normalizeSlashes ( node . text ) ;
25
25
26
- const scriptPath = node . getSourceFile ( ) . path ;
26
+ const scriptPath = sourceFile . path ;
27
27
const scriptDirectory = getDirectoryPath ( scriptPath ) ;
28
28
29
29
if ( isPathRelativeToScript ( literalValue ) || isRootedDiskPath ( literalValue ) ) {
@@ -37,7 +37,6 @@ namespace ts.Completions.PathCompletions {
37
37
}
38
38
}
39
39
else {
40
- // Check for node modules
41
40
return getCompletionEntriesForNonRelativeModules ( literalValue , scriptDirectory , compilerOptions , host , typeChecker ) ;
42
41
}
43
42
}
@@ -225,16 +224,17 @@ namespace ts.Completions.PathCompletions {
225
224
) : ReadonlyArray < NameAndKind > {
226
225
if ( ! endsWith ( path , "*" ) ) {
227
226
// 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 ;
229
228
}
230
229
231
230
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 ) ) ;
235
234
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
+ }
238
238
}
239
239
240
240
function getModulesForPathsPattern ( fragment : string , baseUrl : string , pattern : string , fileExtensions : ReadonlyArray < string > , host : LanguageServiceHost ) : ReadonlyArray < NameAndKind > | undefined {
0 commit comments