1313import java .io .File ;
1414import java .io .IOException ;
1515import java .util .ArrayList ;
16+ import java .util .HashMap ;
1617import java .util .LinkedHashMap ;
1718import java .util .List ;
1819import java .util .Map ;
5051import ts .client .references .ReferencesResponseBody ;
5152import ts .client .rename .RenameResponseBody ;
5253import ts .client .signaturehelp .SignatureHelpItems ;
54+ import ts .cmd .tsc .CompilerOptions ;
5355import ts .internal .FileTempHelper ;
5456import ts .internal .SequenceHelper ;
5557import ts .internal .client .protocol .ChangeRequest ;
7678import ts .internal .client .protocol .NavToRequest ;
7779import ts .internal .client .protocol .NavTreeRequest ;
7880import ts .internal .client .protocol .OccurrencesRequest ;
81+ import ts .internal .client .protocol .OpenExternalProjectRequest ;
7982import ts .internal .client .protocol .OpenRequest ;
8083import ts .internal .client .protocol .ProjectInfoRequest ;
8184import ts .internal .client .protocol .QuickInfoRequest ;
8790import ts .internal .client .protocol .SemanticDiagnosticsSyncRequest ;
8891import ts .internal .client .protocol .SignatureHelpRequest ;
8992import ts .internal .client .protocol .SyntacticDiagnosticsSyncRequest ;
93+ import ts .internal .client .protocol .OpenExternalProjectRequestArgs .ExternalFile ;
9094import ts .nodejs .INodejsLaunchConfiguration ;
9195import ts .nodejs .INodejsProcess ;
9296import ts .nodejs .INodejsProcessListener ;
@@ -164,12 +168,12 @@ private static class PendingRequestEventInfo {
164168 }
165169
166170 public TypeScriptServiceClient (final File projectDir , File tsserverFile , File nodeFile ) throws TypeScriptException {
167- this (projectDir , tsserverFile , nodeFile , false , false , null , null );
171+ this (projectDir , tsserverFile , nodeFile , false , false , null , null , null );
168172 }
169173
170174 public TypeScriptServiceClient (final File projectDir , File typescriptDir , File nodeFile , boolean enableTelemetry ,
171- boolean disableAutomaticTypingAcquisition , String cancellationPipeName , File tsserverPluginsFile )
172- throws TypeScriptException {
175+ boolean disableAutomaticTypingAcquisition , String cancellationPipeName , File tsserverPluginsFile ,
176+ TypeScriptServiceLogConfiguration logConfiguration ) throws TypeScriptException {
173177 this (NodejsProcessManager .getInstance ().create (projectDir ,
174178 tsserverPluginsFile != null ? tsserverPluginsFile
175179 : TypeScriptRepositoryManager .getTsserverFile (typescriptDir ),
@@ -197,6 +201,16 @@ public List<String> createNodeArgs() {
197201 // args.add("--useSingleInferredProject");
198202 return args ;
199203 }
204+
205+ @ Override
206+ public Map <String , String > createNodeEnvironmentVariables () {
207+ Map <String , String > environmentVariables = new HashMap <>();
208+ if (logConfiguration != null ) {
209+ environmentVariables .put ("TSS_LOG" ,
210+ "-level " + logConfiguration .level .name () + " -file " + logConfiguration .file );
211+ }
212+ return environmentVariables ;
213+ }
200214 }, TSSERVER_FILE_TYPE ), cancellationPipeName );
201215 }
202216
@@ -213,6 +227,20 @@ public TypeScriptServiceClient(INodejsProcess process, String cancellationPipeNa
213227 this .cancellationPipeName = cancellationPipeName ;
214228 }
215229
230+ public static enum TypeScriptServiceLogLevel {
231+ verbose , normal , terse , requestTime
232+ }
233+
234+ public static class TypeScriptServiceLogConfiguration {
235+ String file ;
236+ TypeScriptServiceLogLevel level ;
237+
238+ public TypeScriptServiceLogConfiguration (String file , TypeScriptServiceLogLevel level ) {
239+ this .file = file ;
240+ this .level = level ;
241+ }
242+ }
243+
216244 private void dispatchMessage (String message ) {
217245 JsonObject json = GsonHelper .parse (message ).getAsJsonObject ();
218246 JsonElement typeElement = json .get ("type" );
@@ -293,6 +321,12 @@ public void openFile(String fileName, String content, ScriptKindName scriptKindN
293321 execute (new OpenRequest (fileName , null , content , scriptKindName ), false );
294322 }
295323
324+ @ Override
325+ public void openExternalProject (String projectFileName , List <ExternalFile > rootFiles , CompilerOptions options )
326+ throws TypeScriptException {
327+ execute (new OpenExternalProjectRequest (projectFileName , rootFiles , options ), false );
328+ }
329+
296330 @ Override
297331 public void closeFile (String fileName ) throws TypeScriptException {
298332 execute (new CloseRequest (fileName ), false );
@@ -314,7 +348,10 @@ public void changeFile(String fileName, int line, int offset, int endLine, int e
314348 @ Override
315349 public void updateFile (String fileName , String newText ) throws TypeScriptException {
316350 int seq = SequenceHelper .getRequestSeq ();
317- String tempFileName = FileTempHelper .updateTempFile (newText , seq );
351+ String tempFileName = null ;
352+ if (newText != null ) {
353+ tempFileName = FileTempHelper .updateTempFile (newText , seq );
354+ }
318355 try {
319356 execute (new ReloadRequest (fileName , tempFileName , seq ), true ).get (5000 , TimeUnit .MILLISECONDS );
320357 } catch (Exception e ) {
0 commit comments