@@ -27,7 +27,7 @@ namespace ts.Completions.PathCompletions {
27
27
const scriptDirectory = getDirectoryPath ( scriptPath ) ;
28
28
29
29
if ( isPathRelativeToScript ( literalValue ) || isRootedDiskPath ( literalValue ) ) {
30
- const extensions = getSupportedExtensions ( compilerOptions ) ;
30
+ const extensions = getSupportedExtensionsForModuleResolution ( compilerOptions ) ;
31
31
if ( compilerOptions . rootDirs ) {
32
32
return getCompletionEntriesForDirectoryFragmentWithRootDirs (
33
33
compilerOptions . rootDirs , literalValue , scriptDirectory , extensions , /*includeExtensions*/ false , compilerOptions , host , scriptPath ) ;
@@ -42,6 +42,13 @@ namespace ts.Completions.PathCompletions {
42
42
}
43
43
}
44
44
45
+ function getSupportedExtensionsForModuleResolution ( compilerOptions : CompilerOptions ) {
46
+ const extensions = getSupportedExtensions ( compilerOptions ) ;
47
+ return compilerOptions . resolveJsonModule && getEmitModuleResolutionKind ( compilerOptions ) === ModuleResolutionKind . NodeJs ?
48
+ extensions . concat ( Extension . Json ) :
49
+ extensions ;
50
+ }
51
+
45
52
/**
46
53
* Takes a script path and returns paths for all potential folders that could be merged with its
47
54
* containing folder via the "rootDirs" compiler option
@@ -122,7 +129,7 @@ namespace ts.Completions.PathCompletions {
122
129
continue ;
123
130
}
124
131
125
- const foundFileName = includeExtensions ? getBaseFileName ( filePath ) : removeFileExtension ( getBaseFileName ( filePath ) ) ;
132
+ const foundFileName = includeExtensions || fileExtensionIs ( filePath , Extension . Json ) ? getBaseFileName ( filePath ) : removeFileExtension ( getBaseFileName ( filePath ) ) ;
126
133
127
134
if ( ! foundFiles . has ( foundFileName ) ) {
128
135
foundFiles . set ( foundFileName , true ) ;
@@ -162,7 +169,7 @@ namespace ts.Completions.PathCompletions {
162
169
163
170
const result : NameAndKind [ ] = [ ] ;
164
171
165
- const fileExtensions = getSupportedExtensions ( compilerOptions ) ;
172
+ const fileExtensions = getSupportedExtensionsForModuleResolution ( compilerOptions ) ;
166
173
if ( baseUrl ) {
167
174
const projectDir = compilerOptions . project || host . getCurrentDirectory ( ) ;
168
175
const absolute = isRootedDiskPath ( baseUrl ) ? baseUrl : combinePaths ( projectDir , baseUrl ) ;
0 commit comments