File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -432,19 +432,26 @@ impl GlobalState {
432
432
Ok ( ( ) )
433
433
} ) ?
434
434
. on :: < lsp_types:: notification:: DidCloseTextDocument > ( |this, params| {
435
+ let mut version = None ;
435
436
if let Ok ( path) = from_proto:: vfs_path ( & params. text_document . uri ) {
436
- if this. mem_docs . remove ( & path) . is_none ( ) {
437
- log:: error!( "orphan DidCloseTextDocument: {}" , path)
437
+ match this. mem_docs . remove ( & path) {
438
+ Some ( entry) => version = entry,
439
+ None => log:: error!( "orphan DidCloseTextDocument: {}" , path) ,
438
440
}
441
+
439
442
if let Some ( path) = path. as_path ( ) {
440
443
this. loader . handle . invalidate ( path. to_path_buf ( ) ) ;
441
444
}
442
445
}
446
+
447
+ // Clear the diagnostics for the previously known version of the file.
448
+ // This prevents stale "cargo check" diagnostics if the file is
449
+ // closed, "cargo check" is run and then the file is reopened.
443
450
this. send_notification :: < lsp_types:: notification:: PublishDiagnostics > (
444
451
lsp_types:: PublishDiagnosticsParams {
445
452
uri : params. text_document . uri ,
446
453
diagnostics : Vec :: new ( ) ,
447
- version : None ,
454
+ version,
448
455
} ,
449
456
) ;
450
457
Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments