11/// <reference path="../../services/services.ts"/>
22/// <reference path="../utilities.ts"/>
33
4-
5-
64namespace ts . server . typingsInstaller {
75
86 const DefaultTsdSettings = JSON . stringify ( {
@@ -40,18 +38,30 @@ namespace ts.server.typingsInstaller {
4038
4139 // respond with whatever cached typings we have now
4240 this . sendResponse ( this . createResponse ( req , discoverTypingsResult . cachedTypingPaths ) ) ;
41+ // start watching files
4342 this . watchFiles ( discoverTypingsResult . filesToWatch ) ;
44- this . installTypings ( req , discoverTypingsResult . newTypingNames ) ;
43+ // install typings and
44+ this . installTypings ( req , discoverTypingsResult . cachedTypingPaths , discoverTypingsResult . newTypingNames ) ;
4545 }
4646
47- private installTypings ( req : InstallTypingsRequest , typingsToInstall : string [ ] ) {
47+ private installTypings ( req : InstallTypingsRequest , currentlyCachedTypings : string [ ] , typingsToInstall : string [ ] ) {
48+ typingsToInstall = filter ( typingsToInstall , x => ! hasProperty ( this . missingTypings , x ) ) ;
49+ if ( typingsToInstall . length === 0 ) {
50+ return ;
51+ }
52+
4853 // TODO: install typings and send response when they are ready
49- const existingTypings = typingsToInstall . fi
5054 const host = this . getInstallTypingHost ( ) ;
5155 const tsdPath = combinePaths ( req . cachePath , "tsd.json" ) ;
5256 if ( ! host . fileExists ( tsdPath ) ) {
5357 host . writeFile ( tsdPath , DefaultTsdSettings ) ;
5458 }
59+
60+ this . runTsd ( tsdPath , typingsToInstall , installedTypings => {
61+ // TODO: record new missing package names
62+ // TODO: watch project directory
63+ this . sendResponse ( this . createResponse ( req , currentlyCachedTypings . concat ( installedTypings ) ) ) ;
64+ } ) ;
5565 }
5666
5767 private watchFiles ( files : string [ ] ) {
@@ -71,5 +81,6 @@ namespace ts.server.typingsInstaller {
7181 protected abstract installPackage ( packageName : string ) : boolean ;
7282 protected abstract getInstallTypingHost ( ) : InstallTypingHost ;
7383 protected abstract sendResponse ( response : InstallTypingsResponse ) : void ;
84+ protected abstract runTsd ( cachePath : string , typingsToInstall : string [ ] , postInstallAction : ( installedTypings : string [ ] ) => void ) : void ;
7485 }
7586}
0 commit comments