22/// <reference path="utilities.ts"/>
33/// <reference path="scriptInfo.ts"/>
44/// <reference path="lsHost.ts"/>
5+ /// <reference path="typingsCache.ts"/>
56
67namespace ts . server {
78
@@ -25,7 +26,6 @@ namespace ts.server {
2526 private program : ts . Program ;
2627
2728 private languageService : LanguageService ;
28-
2929 /**
3030 * Set of files that was returned from the last call to getChangesSinceVersion.
3131 */
@@ -47,6 +47,8 @@ namespace ts.server {
4747 */
4848 private projectStateVersion = 0 ;
4949
50+ private typingFiles : string [ ] ;
51+
5052 constructor (
5153 readonly projectKind : ProjectKind ,
5254 readonly projectService : ProjectService ,
@@ -74,7 +76,7 @@ namespace ts.server {
7476 this . markAsDirty ( ) ;
7577 }
7678
77- getLanguageService ( ensureSynchronized = true ) : LanguageService {
79+ getLanguageService ( ensureSynchronized = true ) : LanguageService {
7880 if ( ensureSynchronized ) {
7981 this . updateGraph ( ) ;
8082 }
@@ -136,6 +138,21 @@ namespace ts.server {
136138 return this . rootFiles && this . rootFiles . map ( info => info . fileName ) ;
137139 }
138140
141+ getRootFilesLSHost ( ) {
142+ const result : string [ ] = [ ] ;
143+ if ( this . rootFiles ) {
144+ for ( const f of this . rootFiles ) {
145+ result . push ( f . fileName ) ;
146+ }
147+ if ( this . typingFiles ) {
148+ for ( const f of this . typingFiles ) {
149+ result . push ( f ) ;
150+ }
151+ }
152+ }
153+ return result ;
154+ }
155+
139156 getRootScriptInfos ( ) {
140157 return this . rootFiles ;
141158 }
@@ -209,16 +226,35 @@ namespace ts.server {
209226 if ( ! this . languageServiceEnabled ) {
210227 return true ;
211228 }
229+ const hasChanges = this . updateGraphWorker ( ) ;
230+ if ( hasChanges ) {
231+ if ( this . setTypings ( this . projectService . typingsCache . getTypingsForProject ( this ) ) ) {
232+ this . updateGraphWorker ( ) ;
233+ }
234+ this . projectStructureVersion ++ ;
235+ }
236+ return hasChanges ;
237+ }
238+
239+ setTypings ( typings : string [ ] ) : boolean {
240+ if ( typings === this . typingFiles ) {
241+ return false ;
242+ }
243+ this . typingFiles = typings ;
244+ this . markAsDirty ( ) ;
245+ return true ;
246+ }
212247
248+ private updateGraphWorker ( ) {
213249 const oldProgram = this . program ;
214250 this . program = this . languageService . getProgram ( ) ;
215251
216- const oldProjectStructureVersion = this . projectStructureVersion ;
252+ let hasChanges = false ;
217253 // bump up the version if
218254 // - oldProgram is not set - this is a first time updateGraph is called
219255 // - newProgram is different from the old program and structure of the old program was not reused.
220256 if ( ! oldProgram || ( this . program !== oldProgram && ! oldProgram . structureIsReused ) ) {
221- this . projectStructureVersion ++ ;
257+ hasChanges = true ;
222258 if ( oldProgram ) {
223259 for ( const f of oldProgram . getSourceFiles ( ) ) {
224260 if ( this . program . getSourceFileByPath ( f . path ) ) {
@@ -232,8 +268,7 @@ namespace ts.server {
232268 }
233269 }
234270 }
235-
236- return oldProjectStructureVersion === this . projectStructureVersion ;
271+ return hasChanges ;
237272 }
238273
239274 getScriptInfoLSHost ( fileName : string ) {
@@ -392,11 +427,16 @@ namespace ts.server {
392427 documentRegistry : ts . DocumentRegistry ,
393428 hasExplicitListOfFiles : boolean ,
394429 compilerOptions : CompilerOptions ,
430+ private typingOptions : TypingOptions ,
395431 private wildcardDirectories : Map < WatchDirectoryFlags > ,
396432 languageServiceEnabled : boolean ) {
397433 super ( ProjectKind . Configured , projectService , documentRegistry , hasExplicitListOfFiles , languageServiceEnabled , compilerOptions ) ;
398434 }
399435
436+ getTypingOptions ( ) {
437+ return this . typingOptions ;
438+ }
439+
400440 getProjectName ( ) {
401441 return this . configFileName ;
402442 }
0 commit comments