-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run Code Analysis command does not report any violations when LSP pull diagnostics is enabled #65967
Comments
@dibarbet @arkalyanms |
Yep this definitely will need support in some way on the client side. I can think of a couple ways to tackle this, depending on if this command is more widely applicable to various languages
I kind of lean towards 1 if this only applicable to C#, especially since the UI behavior doesn't seem to be that complex. Open to other thoughts |
I'm amenable to us doing something specialized in Roslyn. Esp. as a stopgap to unblock pull diags. So '1' is ok with me. However, the main way I would think about this though is: does this command make sense for other languages (like f#/c++/TS/etc. If so, Roslyn should likely not own it). |
This command is used by all languages. I know for sure that C++ uses it. |
@mavasani do you think this is something you can do? We really need to get on pull diagnostics, and chasing this tail had been going on for several years now. |
@CyrusNajmabadi We need to first figure out how we'd like to implement this functionality and where all the pieces will live.
I feel @dibarbet is probably the right person to make this call, as I am not aware of how doc outline custom client is implemented and if it is simple enough for us to go that route. We will need to ensure that the diagnostics reported from this custom client play well with normal live and build diagnostics, with all the de-duping and priority things sorted out. I can definitely help in the implementation once we have figured out the exact way we would like to implement this. In the longer term, I believe the following pieces are required:
|
@mavasani in the short term, can we still just have roslyn handle this command? As you mentioned, it can just call through the relevant apis and populate the error list itself. That way we can ship pull diagnostics for everything else (squiggles, error list, suggestions, fading) in the short term, while not regressing this. Then, in the medium term, we work with the platform to lsp-ify this command. Would that be possible? |
We talked about this a bit more offline, and have a proposal on how to implement this command for LSP pull diagnostics mode. First, let me start with a brief overview of how this command is implemented today in non-LSP pull diagnostics world. Documentation for Run Code Analysis: https://learn.microsoft.com/visualstudio/code-quality/how-to-run-code-analysis-manually-for-managed-code Current Implementation
Proposal
I believe majority of the work here is porting over existing code from Roslyn into LSP client, and hooking up correct calls into Roslyn's pull handler. Roslyn side implementation should be a very trivial change once we know the diagnostics params that will be passed in to indicate the special flag and the project ID to scope analysis. |
Fixes dotnet#65967 Prior to this change, Run Code Analysis command force executed all the analyzers on the selected project/solution, but the reported analyzer diagnostics were not getting reported from LSP pull handlers. This PR makes the following changes to ensure these diagnostics get reported as workspace pull diagnostics: 1. Modify WorkspacePullDiagnosticHandler so that it reports diagnostics when either of the following conditions are met: 1. Full solution analysis is enabled (it was already doing so prior to this PR) 2. Project was already force analyzed and has cached diagnostics (it could be via Run Code Analysis command or any other client in future). 2. Update the Workspace and Project diagnostic sources added by the Workspace pull handler to do the following: 1. If full solution analysis is enabled, compute and report the closed file diagnostics for the latest solution snapshot 2. Otherwise, return the already cached closed file diagnostics, which may be from a prior snapshot (this matches the non-LSP behavior when Run Code Analysis command is executed) 3. Update the `DiagnosticAnalyzerService.ForceAnalyzeAsync` command that is invoked during Run Code Analysis to keep track of projects that were force analyzed. Additionally, also send a workspace diagnostic refresh request to the LSP client after each project has finished analysis. With the above changes, Run Code Analysis command executes and reports diagnostics as expected in LSP pull diagnostics mode. There is still a considerable delay (10 sec) in error list getting populated with diagnostics from this command as the workspace diagnostic refresh is triggered at a delay. We will be addressing this in a separate follow-up change, where in we will trigger a new kind of diagnostic refresh request specifically catered to code analysis execution, such that the client does the workspace pull without any delay. We are still unsure if we need to pass in the project context around in this refresh request OR let it be a full refresh, given the server is only going to attempt to return workspace diagnostics from the cache, so a full refresh request may not incur any significant cost. TBD: Add unit tests for this scenario. I am going to do this in a follow-up PR so that dotnet#70040 does not stay blocked on the product changes here.
Documentation: https://learn.microsoft.com/visualstudio/code-quality/how-to-run-code-analysis-manually-for-managed-code
Version Used: Latest 17.5 Preview2
Steps to Reproduce:
Microsoft.CodeAnalysis.csproj
in the solution explorer and runAnalyze -> Run Code Analysis
Messages
tabExpected Behavior:
Same set of code analysis message diagnostics are reported as in Step 4.
Actual Behavior:
No code analysis message diagnostics are reported.
Run code analysis command ends up invoking the below method which basically force completes analyzer execution for the selected project/solution node:
roslyn/src/VisualStudio/Core/Def/Diagnostics/VisualStudioDiagnosticAnalyzerService.cs
Lines 304 to 351 in 6392f2f
The text was updated successfully, but these errors were encountered: