@@ -7,7 +7,7 @@ namespace ts.Completions.StringCompletions {
7
7
}
8
8
if ( isInString ( sourceFile , position , contextToken ) ) {
9
9
if ( ! contextToken || ! isStringLiteralLike ( contextToken ) ) return undefined ;
10
- const entries = getStringLiteralCompletionEntries ( sourceFile , contextToken , position , checker , options , host ) ;
10
+ const entries = getStringLiteralCompletionEntries ( sourceFile , contextToken , position , checker , options , host , preferences ) ;
11
11
return convertStringLiteralCompletions ( entries , contextToken , sourceFile , checker , log , preferences ) ;
12
12
}
13
13
}
@@ -52,9 +52,9 @@ namespace ts.Completions.StringCompletions {
52
52
}
53
53
}
54
54
55
- export function getStringLiteralCompletionDetails ( name : string , sourceFile : SourceFile , position : number , contextToken : Node | undefined , checker : TypeChecker , options : CompilerOptions , host : LanguageServiceHost , cancellationToken : CancellationToken ) {
55
+ export function getStringLiteralCompletionDetails ( name : string , sourceFile : SourceFile , position : number , contextToken : Node | undefined , checker : TypeChecker , options : CompilerOptions , host : LanguageServiceHost , cancellationToken : CancellationToken , preferences : UserPreferences ) {
56
56
if ( ! contextToken || ! isStringLiteralLike ( contextToken ) ) return undefined ;
57
- const completions = getStringLiteralCompletionEntries ( sourceFile , contextToken , position , checker , options , host ) ;
57
+ const completions = getStringLiteralCompletionEntries ( sourceFile , contextToken , position , checker , options , host , preferences ) ;
58
58
return completions && stringLiteralCompletionDetails ( name , contextToken , completions , sourceFile , checker , cancellationToken ) ;
59
59
}
60
60
@@ -109,7 +109,7 @@ namespace ts.Completions.StringCompletions {
109
109
readonly isNewIdentifier : boolean ;
110
110
}
111
111
type StringLiteralCompletion = { readonly kind : StringLiteralCompletionKind . Paths , readonly paths : readonly PathCompletion [ ] } | StringLiteralCompletionsFromProperties | StringLiteralCompletionsFromTypes ;
112
- function getStringLiteralCompletionEntries ( sourceFile : SourceFile , node : StringLiteralLike , position : number , typeChecker : TypeChecker , compilerOptions : CompilerOptions , host : LanguageServiceHost ) : StringLiteralCompletion | undefined {
112
+ function getStringLiteralCompletionEntries ( sourceFile : SourceFile , node : StringLiteralLike , position : number , typeChecker : TypeChecker , compilerOptions : CompilerOptions , host : LanguageServiceHost , preferences : UserPreferences ) : StringLiteralCompletion | undefined {
113
113
const parent = walkUpParentheses ( node . parent ) ;
114
114
switch ( parent . kind ) {
115
115
case SyntaxKind . LiteralType : {
@@ -136,7 +136,7 @@ namespace ts.Completions.StringCompletions {
136
136
}
137
137
return stringLiteralCompletionsFromProperties ( typeChecker . getTypeFromTypeNode ( objectType ) ) ;
138
138
case SyntaxKind . ImportType :
139
- return { kind : StringLiteralCompletionKind . Paths , paths : getStringLiteralCompletionsFromModuleNames ( sourceFile , node , compilerOptions , host , typeChecker ) } ;
139
+ return { kind : StringLiteralCompletionKind . Paths , paths : getStringLiteralCompletionsFromModuleNames ( sourceFile , node , compilerOptions , host , typeChecker , preferences ) } ;
140
140
case SyntaxKind . UnionType : {
141
141
if ( ! isTypeReferenceNode ( grandParent . parent ) ) {
142
142
return undefined ;
@@ -201,7 +201,7 @@ namespace ts.Completions.StringCompletions {
201
201
// import x = require("/*completion position*/");
202
202
// var y = require("/*completion position*/");
203
203
// export * from "/*completion position*/";
204
- return { kind : StringLiteralCompletionKind . Paths , paths : getStringLiteralCompletionsFromModuleNames ( sourceFile , node , compilerOptions , host , typeChecker ) } ;
204
+ return { kind : StringLiteralCompletionKind . Paths , paths : getStringLiteralCompletionsFromModuleNames ( sourceFile , node , compilerOptions , host , typeChecker , preferences ) } ;
205
205
206
206
default :
207
207
return fromContextualType ( ) ;
@@ -303,18 +303,18 @@ namespace ts.Completions.StringCompletions {
303
303
Math . max ( name . indexOf ( directorySeparator ) , name . indexOf ( altDirectorySeparator ) ) !== - 1 ? { name, kind, extension, span : wholeSpan } : { name, kind, extension, span } ) ;
304
304
}
305
305
306
- function getStringLiteralCompletionsFromModuleNames ( sourceFile : SourceFile , node : LiteralExpression , compilerOptions : CompilerOptions , host : LanguageServiceHost , typeChecker : TypeChecker ) : readonly PathCompletion [ ] {
307
- return addReplacementSpans ( node . text , node . getStart ( sourceFile ) + 1 , getStringLiteralCompletionsFromModuleNamesWorker ( sourceFile , node , compilerOptions , host , typeChecker ) ) ;
306
+ function getStringLiteralCompletionsFromModuleNames ( sourceFile : SourceFile , node : LiteralExpression , compilerOptions : CompilerOptions , host : LanguageServiceHost , typeChecker : TypeChecker , preferences : UserPreferences ) : readonly PathCompletion [ ] {
307
+ return addReplacementSpans ( node . text , node . getStart ( sourceFile ) + 1 , getStringLiteralCompletionsFromModuleNamesWorker ( sourceFile , node , compilerOptions , host , typeChecker , preferences ) ) ;
308
308
}
309
309
310
- function getStringLiteralCompletionsFromModuleNamesWorker ( sourceFile : SourceFile , node : LiteralExpression , compilerOptions : CompilerOptions , host : LanguageServiceHost , typeChecker : TypeChecker ) : readonly NameAndKind [ ] {
310
+ function getStringLiteralCompletionsFromModuleNamesWorker ( sourceFile : SourceFile , node : LiteralExpression , compilerOptions : CompilerOptions , host : LanguageServiceHost , typeChecker : TypeChecker , preferences : UserPreferences ) : readonly NameAndKind [ ] {
311
311
const literalValue = normalizeSlashes ( node . text ) ;
312
312
313
313
const scriptPath = sourceFile . path ;
314
314
const scriptDirectory = getDirectoryPath ( scriptPath ) ;
315
315
316
316
return isPathRelativeToScript ( literalValue ) || ! compilerOptions . baseUrl && ( isRootedDiskPath ( literalValue ) || isUrl ( literalValue ) )
317
- ? getCompletionEntriesForRelativeModules ( literalValue , scriptDirectory , compilerOptions , host , scriptPath )
317
+ ? getCompletionEntriesForRelativeModules ( literalValue , scriptDirectory , compilerOptions , host , scriptPath , preferences )
318
318
: getCompletionEntriesForNonRelativeModules ( literalValue , scriptDirectory , compilerOptions , host , typeChecker ) ;
319
319
}
320
320
@@ -325,8 +325,8 @@ namespace ts.Completions.StringCompletions {
325
325
function getExtensionOptions ( compilerOptions : CompilerOptions , includeExtensions = false ) : ExtensionOptions {
326
326
return { extensions : getSupportedExtensionsForModuleResolution ( compilerOptions ) , includeExtensions } ;
327
327
}
328
- function getCompletionEntriesForRelativeModules ( literalValue : string , scriptDirectory : string , compilerOptions : CompilerOptions , host : LanguageServiceHost , scriptPath : Path ) {
329
- const extensionOptions = getExtensionOptions ( compilerOptions ) ;
328
+ function getCompletionEntriesForRelativeModules ( literalValue : string , scriptDirectory : string , compilerOptions : CompilerOptions , host : LanguageServiceHost , scriptPath : Path , preferences : UserPreferences ) {
329
+ const extensionOptions = getExtensionOptions ( compilerOptions , preferences . importModuleSpecifierEnding === "js" ) ;
330
330
if ( compilerOptions . rootDirs ) {
331
331
return getCompletionEntriesForDirectoryFragmentWithRootDirs (
332
332
compilerOptions . rootDirs , literalValue , scriptDirectory , extensionOptions , compilerOptions , host , scriptPath ) ;
0 commit comments