Ensure diagnostics are cleared on file deletion#319
Ensure diagnostics are cleared on file deletion#319felixfbecker merged 3 commits intofelixfbecker:masterfrom
Conversation
Previously, error diagnostics would not be cleared when a file was deleted while it was closed. This would result in lingering errors in the problems view that could only be cleared by reloading the language server. This fix addresses the issue by adding support for workspace/didChangeWatchedFiles and automatically clearing diagnostics for deleted files.
Codecov Report
@@ Coverage Diff @@
## master #319 +/- ##
============================================
- Coverage 85.98% 84.15% -1.83%
- Complexity 717 811 +94
============================================
Files 53 59 +6
Lines 1463 1717 +254
============================================
+ Hits 1258 1445 +187
- Misses 205 272 +67
Continue to review full report at Codecov.
|
felixfbecker
left a comment
There was a problem hiding this comment.
Thanks! Implementing didChangeWatchedFiles was on my todo for a long time.
Especially adding or changing a file should cause a (re)index of the file, for example on a branch switch.
Regarding the tests, I think the best would be to use a mocking library like prophecy to mock the LanguageClient and assert that publishDiagnostics was called. I tried that once but failed to get it working so I just went with listening for the message event in the other tests, which works.
Just the code style change to merge this
|
|
||
| $fileEvent = new FileEvent(); | ||
| $fileEvent->uri = 'my uri'; | ||
| $fileEvent->type = FileChangeType::DELETED; |
There was a problem hiding this comment.
I think it makes sense to add a constructor to FileEvent to make this easier to construct
| $fileEvent->type = FileChangeType::DELETED; | ||
|
|
||
| $isDiagnosticsCleared = false; | ||
| $writer->on('message', function (Message $message) use ($fileEvent, & $isDiagnosticsCleared) { |
|
Done, thanks for the feedback! Also made the corresponding PR at felixfbecker/vscode-php-intellisense#83. And with that, I'm off to bed because it's 2am here. 💤 |
Previously, error diagnostics would not be cleared when a file was deleted while it was closed. This would result in lingering errors in the problems view that could only be cleared by reloading the language server. This fix addresses the issue by adding support for workspace/didChangeWatchedFiles and automatically clearing diagnostics for deleted files.
Additional Notes / Questions