Skip to content
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

Analyzer warnings disappear from Error List when the file with the warning is opened #26817

Closed
svick opened this issue May 12, 2018 · 20 comments · Fixed by #66010
Closed

Analyzer warnings disappear from Error List when the file with the warning is opened #26817

svick opened this issue May 12, 2018 · 20 comments · Fixed by #66010

Comments

@svick
Copy link
Contributor

svick commented May 12, 2018

Version Used: VS 15.8.0 Preview 1.1, .Net Core SDK 2.1.4

Steps to Reproduce:

  1. dotnet new classlib

  2. dotnet add package Microsoft.CodeQuality.Analyzers

  3. Change code in Class1.cs to:

    namespace Foo
    {
        public interface IFoo { }
    }
  4. Open the csproj in VS.

  5. Build Solution.

  6. Open Class1.cs.

  7. Wait a few seconds.

Expected Behavior: Whether the analyzer warning "CA1040 Avoid empty interfaces" appears in the Error List should not depend on whether the relevant file is open.

Actual Behavior: When I Build Solution, the analyzer warning "CA1040 Avoid empty interfaces" appears in the Error List. When I open the relevant file, the warning disappears from the Error List after few seconds.

This only happens in the Build + IntelliSense mode. In the Build Only mode, the warning is always visible


I'm assuming this is a general issue. If it's actually an issue with the specific analyzer, I can move this issue to the dotnet/roslyn-analyzers repo.

@BhaaLseN
Copy link

Hm, this sounds familiar...I saw similar behavior running static analysis while having the error list set to "Build & Intellisense". As soon as I selected a message/warning/error in the list that caused a new file to open, it would re-populate the error list with Intellisense messages there were already there from the build, ultimately changing the order making it impossible to go thru them from top to bottom.
The only way around this was switching the error list to "Build only" then performing the analysis and fixing things with it off.

@jinujoseph jinujoseph added this to the Unknown milestone Jul 23, 2018
@HermannGruber
Copy link

I can confirm this using Visual Studio 15.9.2 and Microsoft .NET core 2.1.5.00 (x64). In our team and repo, this can make people push commits that fail the build on the buildserver, which is of course not good. Is there any hope for progress on this?

@brettpostin
Copy link

I confirm this behaviour on 15.9.7. It only appears to happen with one of our analysers (PumaScan).

The behaviour is as described above:

  • Start with all files closed.
  • Build solution.
  • The violation shows in the error list. Double click to open the file.
  • The error disappears from the error list.

If I change the dropdown to "Build Only" it re-appears. Switching back to "Build + IntelliSense" it disappears again.

@aaron-kruse
Copy link

I can also confirm this still happening with Visual Studio 16.4.3 and .NET Core 3.1, and in my case it has been some (but not all) warnings from FxCop analyzers.

FWIW, the specific warnings that I've noticed disappearing when the corresponding file is opened are CA1008, CA1027, and CA1813. A warning in the same file/class that does not disappear is CA1018. It might also be worth noting that in addition to not listing these warnings in the Error List, there doesn't appear to be any visual indication of any problems in the IDE (ex. nothing with "squiggle underlines", no colors in the scrollbar, etc.).

As others have stated, switching from "Build + IntelliSense" to "Build Only" will bring the "missing" warnings back, and switching back to "Build + IntelliSense" will make them disappear again. This specific problem is covered in issue #19693.

@ElectricErger
Copy link

ElectricErger commented Sep 1, 2020

Reproduction of Issue

Reproduced:

  • Create an analyser (DiagnosticAnalyzer only, do not include an associated CodeFixProvider)
  • Customize it to address a unique issue
  • Add the analyser to a project that triggers the Diagnostic.
    When the section comes into view, the error/warning/message disappears from IntelliSense.

Resolved:

Add an associated CodeFixProvider handle to the DiagnosticAnalyzer.

Theory

I'm not too aware of Roslyn and IntelliSense from a systems PoV, but it seems to me that if IntelliSense does not identify a solution it can suggest, it will suppress the error/warning/message. This would explain why when you're not using IntelliSense (e.g. CLI compiling, "Show issues generated" is "Build Only") it shows up, but disappears when you try to incorporate IntelliSense.

If this is all true, then I think we should consider moving this issue over to IntelliSense, unless I.S. get's it's queues from Roslyn (again, I don't claim to understand the core of the technologies).

@sharwell
Copy link
Member

sharwell commented Sep 1, 2020

For the specific case where a diagnostic is reported by a Compilation End analyzer and Full Solution Analysis is disabled, I'm not sure what the current expected behavior is. For other cases, this issue should be fixed by 16.8 Preview 3.

/cc @mavasani for FSA expectations

@mavasani
Copy link
Member

mavasani commented Sep 2, 2020

For the specific case where a diagnostic is reported by a Compilation End analyzer and Full Solution Analysis is disabled, I'm not sure what the current expected behavior is.

Compilation end actions for analyzers are executed only if Full solution analysis is enabled. So, in the default VS mode (Full solution analysis is disabled), these compilation end actions are never executed in live analysis. These are essentially build only diagnostics.

@sharwell
Copy link
Member

sharwell commented Sep 2, 2020

@mavasani it's also possible to trigger the Compilation End actions via the Run Code Analysis command in Solution Explorer

@equin0x80
Copy link

Unfortunately still happening in VS 2022, making it very impractical to do "one-off" code analyses:
Analyze menu > Run Code Analysis > On Solution
Microsoft Visual Studio Community 2022, Version 17.3.6, VisualStudio.17.Release/17.3.6+32929.385

@rolivares
Copy link

Unfortunately still happening in VS 2022, making it very impractical to do "one-off" code analyses: Analyze menu > Run Code Analysis > On Solution Microsoft Visual Studio Community 2022, Version 17.3.6, VisualStudio.17.Release/17.3.6+32929.385

yep, I came here searching about the same error, VS Community 2022 17.3.6

@kiwiant
Copy link

kiwiant commented Dec 8, 2022

Visual Studio 2022 17.4.2 same issue. Run Code Analysis on Project or Solution and issues listed.

Providing you leave as is the list remains but double click an item to fix, file opens and after a few seconds all items disappear (no modifications made to any files).

@Panda-Sharp
Copy link

Panda-Sharp commented Dec 12, 2022

Any update on this? I was running Code Analysis on my project in VS 17.4.2, but every time I click on a message the list disappears, I thought was my issue and I was going crazy, but looks like it's a long-lasting issue... it's useless to run Code Analysis like this :(

@mavasani
Copy link
Member

mavasani commented Dec 13, 2022

@kiwiant @Panda-Sharp Are you able to provide a simple repro for the issues you are seeing? I just ran Run Code Analysis command on projects within Roslyn.sln, and am able to double click on the reported messages and they still hang around on opening the file. They momentarily disappear as we retrigger code analysis in background whenever a new file becomes active file, but they should immediately be populated with the previously reported (and still active) violations. I am thinking that live analysis is likely busted for your scenarios where the error list clearing part happens on opening the file but live analysis is taking too long to re-analyze and report back the violations for activated file. A repro project or a small gif/demo showing the behavior would certainly help here.

@mavasani
Copy link
Member

Alright - I can at least repro one bug: Making any edit in the active file clears out all the code analysis violations reported from prior Run Code Analysis execution. I am going to work on a fix.

@Panda-Sharp
Copy link

@mavasani Thank you for your reply, here you'll can find everything you need, if you need some more details feel free to ask, thanks!

https://github.com/Panda-Sharp/analyzer-repro

mavasani added a commit to mavasani/roslyn that referenced this issue Dec 14, 2022
Fixes dotnet#26817
This PR fixes the regression where in diagnostics reported for a project/solution after executing `Run Code Analysis` command were getting cleared out after editing source files and/or switching active file tabs.

While fixing the above, I also enhanced the `Run Code Analysis` to handle multi-tfm projects so that now we run analysis for all tfm flavors of a multi-tfm project instead of just the current tfm.
mavasani added a commit to mavasani/roslyn that referenced this issue Dec 14, 2022
Fixes dotnet#26817
Fixes [AB#1698190](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1698190)
This PR fixes the regression where in diagnostics reported for a project/solution after executing `Run Code Analysis` command were getting cleared out after editing source files and/or switching active file tabs.

While fixing the above, I also enhanced the `Run Code Analysis` to handle multi-tfm projects so that now we run analysis for all tfm flavors of a multi-tfm project instead of just the current tfm.
@mavasani
Copy link
Member

Thanks! I have a PR out with the fix: #66010

@alexeygritsenko
Copy link

Hi, the problem still exists in VS 2022 Version 17.5.3 when using the analyzer sonar https://marketplace.visualstudio.com/items?itemName=SonarSource.SonarLintforVisualStudio2022

@Sand2Silicon
Copy link

Just updated to Visual Studio Pro Version 17.7.3 and this issue seems to be persisting.

As soon as I start clicking on warnings, I'm looking for 'C++ Core Guidelines' type issues today, the list of intellisense warnings starts whittling itself away until 2200 warning items have vanished before I've fixed a single one.

Since running code-analysis "on a single project", which actually causes it to run on several including the primary library in the solution, took > 14 minutes on a Xeon based workstation, the erratic behavior of the warnings disappearing in the error-list makes this feature unusable.

Was the merged fix included in 17.7.3?

@Panda-Sharp
Copy link

Just updated to Visual Studio Pro Version 17.7.3 and this issue seems to be persisting.

As soon as I start clicking on warnings, I'm looking for 'C++ Core Guidelines' type issues today, the list of intellisense warnings starts whittling itself away until 2200 warning items have vanished before I've fixed a single one.

Since running code-analysis "on a single project", which actually causes it to run on several including the primary library in the solution, took > 14 minutes on a Xeon based workstation, the erratic behavior of the warnings disappearing in the error-list makes this feature unusable.

Was the merged fix included in 17.7.3?

I think I noticed the same last day, but I was not 100% sure, now I'm... with C#

@sharwell sharwell modified the milestones: Backlog, 17.5 P3 Sep 1, 2023
@sharwell
Copy link
Member

sharwell commented Sep 1, 2023

@Sand2Silicon This issue only relates to managed code analysis (C# and Visual Basic). For C++ analysis, you would need to file feedback with the Report a Problem tool in Visual Studio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.