@@ -2076,6 +2076,8 @@ namespace ts {
2076
2076
*/
2077
2077
const tripleSlashDirectiveFragmentRegex = / ^ ( \/ \/ \/ \s * < r e f e r e n c e \s + ( p a t h | t y p e s ) \s * = \s * (?: ' | " ) ) ( [ ^ \3] * ) $ / ;
2078
2078
2079
+ const nodeModulesDependencyKeys = [ "dependencies" , "devDependencies" , "peerDependencies" , "optionalDependencies" ] ;
2080
+
2079
2081
let commandLineOptionsStringToEnum : CommandLineOptionOfCustomType [ ] ;
2080
2082
2081
2083
/** JS users may pass in string values for enum compiler options (such as ModuleKind), so convert. */
@@ -4606,23 +4608,27 @@ namespace ts {
4606
4608
if ( host . readDirectory ) {
4607
4609
// Enumerate the available files if possible
4608
4610
const files = host . readDirectory ( baseDirectory , extensions , /*exclude*/ undefined , /*include*/ [ "./*" ] ) ;
4611
+ const foundFiles = createMap < boolean > ( ) ;
4609
4612
for ( let filePath of files ) {
4610
4613
filePath = normalizePath ( filePath ) ;
4611
4614
if ( exclude && comparePaths ( filePath , exclude , scriptPath , ignoreCase ) === Comparison . EqualTo ) {
4612
4615
continue ;
4613
4616
}
4614
4617
4615
- const fileName = includeExtensions ? getBaseFileName ( filePath ) : removeFileExtension ( getBaseFileName ( filePath ) ) ;
4616
- const duplicate = ! includeExtensions && forEach ( result , entry => entry . name === fileName ) ;
4618
+ const foundFileName = includeExtensions ? getBaseFileName ( filePath ) : removeFileExtension ( getBaseFileName ( filePath ) ) ;
4617
4619
4618
- if ( ! duplicate ) {
4619
- result . push ( {
4620
- name : fileName ,
4621
- kind : ScriptElementKind . scriptElement ,
4622
- sortText : fileName
4623
- } ) ;
4620
+ if ( ! foundFiles [ foundFileName ] ) {
4621
+ foundFiles [ foundFileName ] = true ;
4624
4622
}
4625
4623
}
4624
+
4625
+ for ( const foundFile in foundFiles ) {
4626
+ result . push ( {
4627
+ name : foundFile ,
4628
+ kind : ScriptElementKind . scriptElement ,
4629
+ sortText : foundFile
4630
+ } ) ;
4631
+ }
4626
4632
}
4627
4633
4628
4634
// If possible, get folder completion as well
@@ -4836,7 +4842,7 @@ namespace ts {
4836
4842
function getCompletionEntriesFromTypings ( host : LanguageServiceHost , options : CompilerOptions , scriptPath : string , result : ImportCompletionEntry [ ] = [ ] ) : ImportCompletionEntry [ ] {
4837
4843
// Check for typings specified in compiler options
4838
4844
if ( options . types ) {
4839
- for ( const moduleName of options . types ) {
4845
+ for ( const moduleName of options . types ) {
4840
4846
result . push ( createCompletionEntryForModule ( moduleName , ScriptElementKind . externalModuleName ) ) ;
4841
4847
}
4842
4848
}
@@ -4911,11 +4917,9 @@ namespace ts {
4911
4917
const nodeModulesDir = combinePaths ( getDirectoryPath ( packageJson ) , "node_modules" ) ;
4912
4918
const foundModuleNames : string [ ] = [ ] ;
4913
4919
4914
- if ( package . dependencies ) {
4915
- addPotentialPackageNames ( package . dependencies , foundModuleNames ) ;
4916
- }
4917
- if ( package . devDependencies ) {
4918
- addPotentialPackageNames ( package . devDependencies , foundModuleNames ) ;
4920
+ // Provide completions for all non @types dependencies
4921
+ for ( const key of nodeModulesDependencyKeys ) {
4922
+ addPotentialPackageNames ( package [ key ] , foundModuleNames ) ;
4919
4923
}
4920
4924
4921
4925
for ( const moduleName of foundModuleNames ) {
@@ -4940,11 +4944,12 @@ namespace ts {
4940
4944
}
4941
4945
}
4942
4946
4943
- // Add all the package names that are not in the @types scope
4944
4947
function addPotentialPackageNames ( dependencies : any , result : string [ ] ) {
4945
- for ( const dep in dependencies ) {
4946
- if ( dependencies . hasOwnProperty ( dep ) && ! startsWith ( dep , "@types/" ) ) {
4947
- result . push ( dep ) ;
4948
+ if ( dependencies ) {
4949
+ for ( const dep in dependencies ) {
4950
+ if ( dependencies . hasOwnProperty ( dep ) && ! startsWith ( dep , "@types/" ) ) {
4951
+ result . push ( dep ) ;
4952
+ }
4948
4953
}
4949
4954
}
4950
4955
}
@@ -4955,7 +4960,6 @@ namespace ts {
4955
4960
}
4956
4961
4957
4962
// Replace everything after the last directory seperator that appears
4958
- // FIXME: do we care about the other seperator?
4959
4963
function getDirectoryFragmentTextSpan ( text : string , textStart : number ) : TextSpan {
4960
4964
const index = text . lastIndexOf ( directorySeparator ) ;
4961
4965
const offset = index !== - 1 ? index + 1 : 0 ;
0 commit comments