Refresh diagnostics on open, on close, on change, and after R execution #224
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses posit-dev/positron#2155
Part of posit-dev/positron#1005
Okay, after much fiddling, I've come up with the following Alpha level scheme for our diagnostics:
did_open()
: Runs diagnostics for that filedid_change()
: Runs diagnostics for that file if we are up to date on changesdid_close()
: Clears diagnostics for that fileThere is much more we can eventually do, like running diagnostics for the whole workspace, maintaining diagnostics on close (and updating them through a "related documents" feature), etc, but this should be a pretty nice improvement.
I'd also like to make a follow up PR or two that trims down our usage of R while diagnostics are being run. We currently look up the set of installed packages and environment symbols at each diagnostic call, but really I think we can cache these and only update them when we do a diagnostic refresh after R console execution (and on startup).
A few of the high level changes:
lsp_client
with the overarchinglsp_backend
inRMain
, because the backend holds the list of the currently opendocuments
, and we need that to refresh them after an R console executionIndexerStateManager
, this is solely used to ensure that we don't run any diagnostics until the indexer has had a chance to run (30 second timeout). The indexer is a very important part of our diagnostics, and we can return some pretty bad ones if we try to run diagnostics before the indexer has finished. Since the indexer runs in a tokio thread, this is totally possible and does happen for me in dplyr where it takes around 3 second for the indexer to fully run. I think I've managed to make the initialization check pretty cheap.handle_execute_request()
(R execution), we refresh diagnostics in all open documents by requesting anr_async_task()
that loops over the open documents and spawns a task on the LSP tokio runtime for each of them, requesting a diagnostic refresh.Note: We are still undecided on posit-dev/positron#1325, which is about what we should do when you are working on an R package and haven't run
load_all()
yet, or if you have functions in a script with alibrary(dplyr)
call at the top but you haven't run it yet. But the big benefit of this PR is that when you do run them, the diagnostics automatically update.Untitled.mov