@@ -12,6 +12,7 @@ import { DidOpenTextDocumentNotification, DidChangeTextDocumentNotification, Did
12
12
import * as tmp from 'tmp' ;
13
13
import { Range } from 'vscode-languageserver-textdocument' ;
14
14
import { uriToFsPath , URI } from 'vscode-uri' ;
15
+ // import * as chokidar from 'chokidar'
15
16
16
17
// See https://microsoft.github.io/language-server-protocol/specification Abstract Message
17
18
// version is fixed to 2.0
@@ -29,8 +30,8 @@ let shutdownRequestAlreadyReceived = false;
29
30
let diagnosticTimer : null | NodeJS . Timeout = null ;
30
31
31
32
// congrats. A simple UI problem is now a distributed system problem
32
- let stupidFileContentCache : { [ key : string ] : string } = {
33
- }
33
+ let stupidFileContentCache : { [ key : string ] : string } = { }
34
+ let previousDiagnosticFiles : Set < string > = new Set ( )
34
35
35
36
let findDirOfFileNearFile = ( fileToFind : p . DocumentUri , source : p . DocumentUri ) : null | p . DocumentUri => {
36
37
let dir = path . dirname ( source )
@@ -231,7 +232,8 @@ FAILED: src/test.cmj src/test.cmi
231
232
return ret
232
233
}
233
234
234
- let startWatchingCompilerLog = ( root : p . DocumentUri , process : NodeJS . Process ) => {
235
+ let startWatchingCompilerLog = ( process : NodeJS . Process ) => {
236
+ // chokidar.watch()
235
237
// TOOD: setTimeout instead
236
238
let id = setInterval ( ( ) => {
237
239
let openFiles = Object . keys ( stupidFileContentCache ) ;
@@ -246,19 +248,20 @@ let startWatchingCompilerLog = (root: p.DocumentUri, process: NodeJS.Process) =>
246
248
247
249
let files : { [ key : string ] : t . Diagnostic [ ] } = { }
248
250
249
- let res = Array . from ( compilerLogDirs )
250
- . forEach ( compilerLogDir => {
251
- let compilerLogPath = path . join ( compilerLogDir , compilerLogPartialPath ) ;
252
- let content = fs . readFileSync ( compilerLogPath , { encoding : 'utf-8' } ) ;
253
- let filesAndErrors = parseCompilerLogOutput ( content , ":" )
254
- Object . keys ( filesAndErrors ) . forEach ( file => {
255
- // assumption: there's no existing files[file] entry
256
- // this is true; see the lines above. A file can only belong to one .compiler.log root
257
- files [ file ] = filesAndErrors [ file ]
258
- } )
259
- } ) ;
260
-
261
- Object . keys ( files ) . forEach ( file => {
251
+ compilerLogDirs . forEach ( compilerLogDir => {
252
+ let compilerLogPath = path . join ( compilerLogDir , compilerLogPartialPath ) ;
253
+ let content = fs . readFileSync ( compilerLogPath , { encoding : 'utf-8' } ) ;
254
+ let filesAndErrors = parseCompilerLogOutput ( content , ":" )
255
+ Object . keys ( filesAndErrors ) . forEach ( file => {
256
+ // assumption: there's no existing files[file] entry
257
+ // this is true; see the lines above. A file can only belong to one .compiler.log root
258
+ files [ file ] = filesAndErrors [ file ]
259
+ } )
260
+ } ) ;
261
+
262
+ // Send new diagnostic, wipe old ones
263
+ let filePaths = Object . keys ( files )
264
+ filePaths . forEach ( file => {
262
265
let params : p . PublishDiagnosticsParams = {
263
266
uri : file ,
264
267
// there's a new optional version param from https://github.com/microsoft/language-server-protocol/issues/201
@@ -271,7 +274,24 @@ let startWatchingCompilerLog = (root: p.DocumentUri, process: NodeJS.Process) =>
271
274
params : params ,
272
275
} ;
273
276
process . send ! ( notification ) ;
277
+
278
+ // this file's taken care of already now. Remove from old diagnostic files
279
+ previousDiagnosticFiles . delete ( file )
280
+ } )
281
+ // wipe the errors from the files that are no longer erroring
282
+ previousDiagnosticFiles . forEach ( remainingPreviousFile => {
283
+ let params : p . PublishDiagnosticsParams = {
284
+ uri : remainingPreviousFile ,
285
+ diagnostics : [ ] ,
286
+ }
287
+ let notification : m . NotificationMessage = {
288
+ jsonrpc : jsonrpcVersion ,
289
+ method : 'textDocument/publishDiagnostics' ,
290
+ params : params ,
291
+ } ;
292
+ process . send ! ( notification ) ;
274
293
} )
294
+ previousDiagnosticFiles = new Set ( filePaths )
275
295
} , 1000 ) ;
276
296
277
297
return id ;
@@ -332,12 +352,13 @@ process.on('message', (a: (m.RequestMessage | m.NotificationMessage)) => {
332
352
process . send ! ( response ) ;
333
353
} else if ( aa . method === 'initialize' ) {
334
354
let param : p . InitializeParams = aa . params
355
+ // TODO: sigh what's deprecated now?
335
356
let root = param . rootUri
336
357
if ( root == null ) {
337
358
// TODO: handle single file
338
359
console . log ( "not handling single file" )
339
360
} else {
340
- diagnosticTimer = startWatchingCompilerLog ( root , process )
361
+ diagnosticTimer = startWatchingCompilerLog ( process )
341
362
}
342
363
// send the list of things we support
343
364
let result : p . InitializeResult = {
@@ -439,12 +460,10 @@ process.on('message', (a: (m.RequestMessage | m.NotificationMessage)) => {
439
460
} ;
440
461
process . send ! ( response ) ;
441
462
442
- // TODO: make sure the diagnosis diffing takes this into account
463
+ // TODO: make sure the diagnostic diffing takes this into account
443
464
if ( ! compilerLogPresentAndNotEmpty ( filePath ) ) {
444
465
let params2 : p . PublishDiagnosticsParams = {
445
466
uri : params . textDocument . uri ,
446
- // there's a new optional version param from https://github.com/microsoft/language-server-protocol/issues/201
447
- // not using it for now, sigh
448
467
diagnostics : [ ] ,
449
468
}
450
469
let notification : m . NotificationMessage = {
0 commit comments