dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.87k stars 675 forks source link

Roslyn analyzer warnings persist in VS Code for files that have been renamed #3478

Open tillig opened 4 years ago

tillig commented 4 years ago

Issue Description

If a Roslyn analyzer warning comes up for a file in VS Code (e.g., SA1649 from StyleCop - file name must match class name) and you rename the file, the issue remains in the "Problems" list in VS Code until you close the whole workspace and reopen it.

Steps to Reproduce

  1. Open a C# / .NET Core project.
  2. Add the StyleCop.Analyzers package if it's not already there.
  3. Add a new file called Foo.cs.
  4. In the file, paste the following code to create a class named Bar:
namespace MyNamespace
{
    public class Bar
    {
    }
}
  1. Notice in the "problems" window there's a warning for Foo.cs - "File name should match first type name. csharp(SA1649)"
  2. Rename the file to Bar.cs - the file name now matches the type name.
  3. Notice in the "problems" window that all the warnings for Foo.cs remain.
  4. Click on one of the warnings and VS Code will prompt you to create the file Foo.cs. Don't do it.
  5. Build the project. The warnings for Foo.cs remain.

Expected Behavior

After renaming the Foo.cs file I expect the warnings/issues for that file to be removed from the "Problems" window. If analysis finds new warnings in the renamed file, those should appear.

Actual Behavior

After renaming the Foo.cs file the warnings/issues for Foo.cs remain in the "Problems" window until you close VS Code and reopen it.

Logs

OmniSharp log

There don't appear to be relevant logs for this issue, though I do see a lot of messages like this:

[info]: OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.CachingCodeFixProviderForProjects
        Skipping code fix provider 'Microsoft.CodeQuality.Analyzers.QualityGuidelines.MarkMembersAsStaticFixer' because its language doesn't match 'C#'.

I find that odd because a lot of the skipped fixes appear to be things I'd expect to be supported in C#, though perhaps these are the VB equivalents.

C# log

There is not a single log line in the C# output window.

Environment information

VSCode version: 1.41.1 C# Extension: 1.21.9

Mono Information OmniSharp using built-in mono
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.100 Commit: cd82f021f4 Runtime Environment: OS Name: Mac OS X OS Version: 10.15 OS Platform: Darwin RID: osx.10.15-x64 Base Path: /usr/local/share/dotnet/sdk/3.1.100/ Host (useful for support): Version: 3.1.0 Commit: 65f04fb6db .NET Core SDKs installed: 2.1.607 [/usr/local/share/dotnet/sdk] 3.1.100 [/usr/local/share/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.14 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.14 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |auto-close-tag|formulahendry|0.5.6| |auto-rename-tag|formulahendry|0.1.1| |azure-account|ms-vscode|0.8.7| |azurerm-vscode-tools|msazurermtools|0.8.3| |beautify|HookyQR|1.5.0| |code-runner|formulahendry|0.9.15| |code-settings-sync|Shan|3.4.3| |color-info|bierner|0.5.1| |cpptools|ms-vscode|0.26.2| |csharp|ms-vscode|1.21.9| |debugger-for-chrome|msjsdiag|4.12.3| |dotenv|mikestead|1.0.1| |dotnet-test-explorer|formulahendry|0.7.1| |ecdc|mitchdenny|1.3.0| |EditorConfig|EditorConfig|0.14.4| |gitlens|eamodio|10.2.0| |Go|ms-vscode|0.11.9| |guides|spywhere|0.9.3| |html-css-class-completion|Zignd|1.19.0| |java|redhat|0.54.2| |markdown-preview-enhanced|shd101wyy|0.5.0| |material-theme|zhuangtongfa|3.2.1| |msbuild-project-tools|tintoy|0.3.2| |mssql|ms-mssql|1.8.0| |nc-gcode|ML|0.13.0| |ng-template|Angular|0.900.3| |npm-intellisense|christian-kohler|1.3.0| |output-colorizer|IBM|0.1.2| |path-intellisense|christian-kohler|1.4.2| |polacode|pnp|0.3.4| |powershell|ms-vscode|2019.12.0| |python|ms-python|2019.11.50794| |remote-wsl|ms-vscode-remote|0.41.6| |restructuredtext|lextudio|116.0.0| |rewrap|stkb|1.9.1| |sort-lines|Tyriar|1.9.0| |sublime-keybindings|ms-vscode|4.0.6| |terraform|mauve|1.4.0| |todo-tree|Gruntfuggly|0.0.162| |vscode-aks-tools|ms-kubernetes-tools|0.0.4| |vscode-arduino|vsciot-vscode|0.2.28| |vscode-docker|ms-azuretools|0.9.0| |vscode-eslint|dbaeumer|2.0.11| |vscode-icons|vscode-icons-team|9.6.0| |vscode-java-debug|vscjava|0.23.0| |vscode-java-dependency|vscjava|0.6.0| |vscode-java-pack|vscjava|0.8.1| |vscode-java-test|vscjava|0.22.0| |vscode-json-stable-stringify|TravisIllig|1.1.0| |vscode-kubernetes-tools|ms-kubernetes-tools|1.0.9| |vscode-markdownlint|DavidAnson|0.33.0| |vscode-maven|vscjava|0.20.1| |vscode-npm-script|eg2|0.3.10| |vscode-typescript-tslint-plugin|ms-vscode|1.2.3| |vscode-yaml|redhat|0.6.1| |vscodeintellicode|VisualStudioExptTeam|1.2.2| |xml|DotJoshJohnson|2.5.0|;
tillig commented 4 years ago

Seems this is a common problem where extensions aren't registering for the right events to handle file close/delete/rename. Enough that VS Code is going to add a 'clear' button to the Problems window. However, it'd still be nice if this extension would handle the events and clean up after itself on delete/rename of files.

JoeRobich commented 4 years ago

This issue may be partially resolved when this PR merges https://github.com/OmniSharp/omnisharp-roslyn/pull/1694