@@ -229,6 +229,7 @@ namespace ts.server {
229
229
}
230
230
231
231
constructor (
232
+ private readonly projectName : string ,
232
233
readonly projectKind : ProjectKind ,
233
234
readonly projectService : ProjectService ,
234
235
private documentRegistry : ts . DocumentRegistry ,
@@ -307,7 +308,9 @@ namespace ts.server {
307
308
this . projectService . onUpdateLanguageServiceStateForProject ( this , /*languageServiceEnabled*/ false ) ;
308
309
}
309
310
310
- abstract getProjectName ( ) : string ;
311
+ getProjectName ( ) {
312
+ return this . projectName ;
313
+ }
311
314
abstract getProjectRootPath ( ) : string | undefined ;
312
315
abstract getTypingOptions ( ) : TypingOptions ;
313
316
@@ -759,31 +762,27 @@ namespace ts.server {
759
762
760
763
export class InferredProject extends Project {
761
764
762
- private static NextId = 1 ;
763
-
764
- /**
765
- * Unique name that identifies this particular inferred project
766
- */
767
- private readonly inferredProjectName : string ;
765
+ private static newName = ( ( ) => {
766
+ let nextId = 1 ;
767
+ return ( ) => {
768
+ const id = nextId ;
769
+ nextId ++ ;
770
+ return makeInferredProjectName ( id ) ;
771
+ }
772
+ } ) ( ) ;
768
773
769
774
// Used to keep track of what directories are watched for this project
770
775
directoriesWatchedForTsconfig : string [ ] = [ ] ;
771
776
772
777
constructor ( projectService : ProjectService , documentRegistry : ts . DocumentRegistry , compilerOptions : CompilerOptions ) {
773
- super ( ProjectKind . Inferred ,
778
+ super ( InferredProject . newName ( ) ,
779
+ ProjectKind . Inferred ,
774
780
projectService ,
775
781
documentRegistry ,
776
782
/*files*/ undefined ,
777
783
/*languageServiceEnabled*/ true ,
778
784
compilerOptions ,
779
785
/*compileOnSaveEnabled*/ false ) ;
780
-
781
- this . inferredProjectName = makeInferredProjectName ( InferredProject . NextId ) ;
782
- InferredProject . NextId ++ ;
783
- }
784
-
785
- getProjectName ( ) {
786
- return this . inferredProjectName ;
787
786
}
788
787
789
788
getProjectRootPath ( ) {
@@ -822,19 +821,23 @@ namespace ts.server {
822
821
/** Used for configured projects which may have multiple open roots */
823
822
openRefCount = 0 ;
824
823
825
- constructor ( readonly configFileName : NormalizedPath ,
824
+ constructor ( configFileName : NormalizedPath ,
826
825
projectService : ProjectService ,
827
826
documentRegistry : ts . DocumentRegistry ,
828
827
hasExplicitListOfFiles : boolean ,
829
828
compilerOptions : CompilerOptions ,
830
829
private wildcardDirectories : Map < WatchDirectoryFlags > ,
831
830
languageServiceEnabled : boolean ,
832
831
public compileOnSaveEnabled : boolean ) {
833
- super ( ProjectKind . Configured , projectService , documentRegistry , hasExplicitListOfFiles , languageServiceEnabled , compilerOptions , compileOnSaveEnabled ) ;
832
+ super ( configFileName , ProjectKind . Configured , projectService , documentRegistry , hasExplicitListOfFiles , languageServiceEnabled , compilerOptions , compileOnSaveEnabled ) ;
833
+ }
834
+
835
+ getConfigFilePath ( ) {
836
+ return this . getProjectName ( ) ;
834
837
}
835
838
836
839
getProjectRootPath ( ) {
837
- return getDirectoryPath ( this . configFileName ) ;
840
+ return getDirectoryPath ( this . getConfigFilePath ( ) ) ;
838
841
}
839
842
840
843
setProjectErrors ( projectErrors : Diagnostic [ ] ) {
@@ -849,12 +852,8 @@ namespace ts.server {
849
852
return this . typingOptions ;
850
853
}
851
854
852
- getProjectName ( ) {
853
- return this . configFileName ;
854
- }
855
-
856
855
watchConfigFile ( callback : ( project : ConfiguredProject ) => void ) {
857
- this . projectFileWatcher = this . projectService . host . watchFile ( this . configFileName , _ => callback ( this ) ) ;
856
+ this . projectFileWatcher = this . projectService . host . watchFile ( this . getConfigFilePath ( ) , _ => callback ( this ) ) ;
858
857
}
859
858
860
859
watchTypeRoots ( callback : ( project : ConfiguredProject , path : string ) => void ) {
@@ -872,7 +871,7 @@ namespace ts.server {
872
871
return ;
873
872
}
874
873
875
- const directoryToWatch = getDirectoryPath ( this . configFileName ) ;
874
+ const directoryToWatch = getDirectoryPath ( this . getConfigFilePath ( ) ) ;
876
875
this . projectService . logger . info ( `Add recursive watcher for: ${ directoryToWatch } ` ) ;
877
876
this . directoryWatcher = this . projectService . host . watchDirectory ( directoryToWatch , path => callback ( this , path ) , /*recursive*/ true ) ;
878
877
}
@@ -881,7 +880,7 @@ namespace ts.server {
881
880
if ( ! this . wildcardDirectories ) {
882
881
return ;
883
882
}
884
- const configDirectoryPath = getDirectoryPath ( this . configFileName ) ;
883
+ const configDirectoryPath = getDirectoryPath ( this . getConfigFilePath ( ) ) ;
885
884
this . directoriesWatchedForWildcards = reduceProperties ( this . wildcardDirectories , ( watchers , flag , directory ) => {
886
885
if ( comparePaths ( configDirectoryPath , directory , "." , ! this . projectService . host . useCaseSensitiveFileNames ) !== Comparison . EqualTo ) {
887
886
const recursive = ( flag & WatchDirectoryFlags . Recursive ) !== 0 ;
@@ -941,14 +940,14 @@ namespace ts.server {
941
940
942
941
export class ExternalProject extends Project {
943
942
private typingOptions : TypingOptions ;
944
- constructor ( readonly externalProjectName : string ,
943
+ constructor ( externalProjectName : string ,
945
944
projectService : ProjectService ,
946
945
documentRegistry : ts . DocumentRegistry ,
947
946
compilerOptions : CompilerOptions ,
948
947
languageServiceEnabled : boolean ,
949
948
public compileOnSaveEnabled : boolean ,
950
949
private readonly projectFilePath ?: string ) {
951
- super ( ProjectKind . External , projectService , documentRegistry , /*hasExplicitListOfFiles*/ true , languageServiceEnabled , compilerOptions , compileOnSaveEnabled ) ;
950
+ super ( externalProjectName , ProjectKind . External , projectService , documentRegistry , /*hasExplicitListOfFiles*/ true , languageServiceEnabled , compilerOptions , compileOnSaveEnabled ) ;
952
951
}
953
952
954
953
getProjectRootPath ( ) {
@@ -958,7 +957,7 @@ namespace ts.server {
958
957
// if the projectFilePath is not given, we make the assumption that the project name
959
958
// is the path of the project file. AS the project name is provided by VS, we need to
960
959
// normalize slashes before using it as a file name.
961
- return getDirectoryPath ( normalizeSlashes ( this . externalProjectName ) ) ;
960
+ return getDirectoryPath ( normalizeSlashes ( this . getProjectName ( ) ) ) ;
962
961
}
963
962
964
963
getTypingOptions ( ) {
@@ -992,9 +991,5 @@ namespace ts.server {
992
991
}
993
992
this . typingOptions = newTypingOptions ;
994
993
}
995
-
996
- getProjectName ( ) {
997
- return this . externalProjectName ;
998
- }
999
994
}
1000
995
}
0 commit comments