@@ -9,6 +9,14 @@ namespace ts.server {
99 gzipSync ( buf : Buffer ) : Buffer
1010 } = require ( "zlib" ) ;
1111
12+ interface NodeChildProcess {
13+ send ( message : any , sendHandle ?: any ) : void ;
14+ }
15+
16+ const childProcess : {
17+ fork ( modulePath : string ) : NodeChildProcess ;
18+ } = require ( "child_process" ) ;
19+
1220 interface ReadLineOptions {
1321 input : NodeJS . ReadableStream ;
1422 output ?: NodeJS . WritableStream ;
@@ -151,10 +159,65 @@ namespace ts.server {
151159 }
152160 }
153161
162+ class NodeTypingsInstaller implements ITypingsInstaller {
163+ private installer : NodeChildProcess ;
164+ private session : Session ;
165+ private cachePath : string ;
166+
167+ constructor ( private readonly logger : server . Logger ) {
168+ switch ( process . platform ) {
169+ case "win32" :
170+ this . cachePath = normalizeSlashes ( combinePaths ( process . env . LOCALAPPDATA || process . env . APPDATA , "Microsoft/TypeScript" ) ) ;
171+ break ;
172+ case "darwin" :
173+ case "linux" :
174+ // TODO:
175+ break ;
176+ }
177+ }
178+
179+ bind ( session : Session ) {
180+ if ( this . logger . hasLevel ( LogLevel . requestTime ) ) {
181+ this . logger . info ( "Binding..." )
182+ }
183+
184+ this . installer = childProcess . fork ( combinePaths ( __dirname , "typingsInstaller.js" ) ) ;
185+ ( < any > this . installer ) . on ( "message" , ( m : any ) => this . handleMessage ( m ) ) ;
186+ }
187+
188+ enqueueInstallTypingsRequest ( project : Project , typingOptions : TypingOptions ) : void {
189+ const request : InstallTypingsRequest = {
190+ projectName : project . getProjectName ( ) ,
191+ fileNames : project . getFileNames ( ) ,
192+ compilerOptions : project . getCompilerOptions ( ) ,
193+ typingOptions,
194+ projectRootPath : < Path > ( project . projectKind === ProjectKind . Inferred ? "" : getDirectoryPath ( project . getProjectName ( ) ) ) , // TODO: fixme
195+ safeListPath : < Path > ( combinePaths ( process . cwd ( ) , "typingSafeList.json" ) ) , // TODO: fixme
196+ packageNameToTypingLocation : { } , // TODO: fixme
197+ cachePath : this . cachePath
198+ } ;
199+ if ( this . logger . hasLevel ( LogLevel . verbose ) ) {
200+ this . logger . info ( `Sending request: ${ JSON . stringify ( request ) } ` ) ;
201+ }
202+ this . installer . send ( request ) ;
203+ }
204+
205+ C = 1 ;
206+ private handleMessage ( response : InstallTypingsResponse ) {
207+ if ( this . logger . hasLevel ( LogLevel . verbose ) ) {
208+ this . logger . info ( `Received response: ${ JSON . stringify ( response ) } ` )
209+ }
210+ require ( "fs" ) . appendFileSync ( "E:\\sources\\git\\tss.txt" , this . C + " !!!::" + JSON . stringify ( response ) + "\r\n" ) ;
211+ this . C ++ ;
212+ this . session . onTypingsInstalled ( response ) ;
213+ require ( "fs" ) . appendFileSync ( "E:\\sources\\git\\tss.txt" , this . C + " !!!::" + "done" + "\r\n" ) ;
214+ }
215+ }
216+
154217 class IOSession extends Session {
155- constructor ( host : ServerHost , cancellationToken : HostCancellationToken , useSingleInferredProject : boolean , logger : ts . server . Logger ) {
156- // TODO: fixme
157- super ( host , cancellationToken , useSingleInferredProject , undefined , Buffer . byteLength , maxUncompressedMessageSize , compress , process . hrtime , logger ) ;
218+ constructor ( host : ServerHost , cancellationToken : HostCancellationToken , useSingleInferredProject : boolean , logger : server . Logger ) {
219+ super ( host , cancellationToken , useSingleInferredProject , new NodeTypingsInstaller ( logger ) , Buffer . byteLength , maxUncompressedMessageSize , compress , process . hrtime , logger ) ;
220+ ( < NodeTypingsInstaller > this . typingsInstaller ) . bind ( this ) ;
158221 }
159222
160223 exit ( ) {
0 commit comments