dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 670 forks source link

"Fix all occurrences of a code issue..." lists different issues then in the problems tab. #4119

Open Gryhyphen opened 3 years ago

Gryhyphen commented 3 years ago

Issue Description

I'm using .editorconfig to disable some rules. This works fine for the problems reported, however when I run any of the "Fix all occurrences of a code issue..." from the command palette it sees and will apply disabled rules as valid options.

Steps to Reproduce

  1. Enable Roslyn analyzers and editor config support.
  2. Set a dotnet_diagnostic severity to none.
  3. Bring up an example file that should trigger the rule.
  4. Open the command palette and run a "Fix all occurrences of a code issue..." command. It should bring up a list that includes the disabled rule.

Expected Behavior

I expect that the disabled rules do not appear or apply.

Actual Behavior

The disabled rules do appear and will apply. This is particularly annoying for "fix all issues".

Logs

OmniSharp log

N/a - but it will list that it "fixing" the disabled rules in the log.

C# log

N/a

Environment information

VSCode version: 1.50.1 C# Extension: 1.23.3

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.302 Commit: 41faccf259 Runtime Environment: OS Name: Windows OS Version: 10.0.19041 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.302\ Host (useful for support): Version: 3.1.6 Commit: 3acd9b0cd1 .NET Core SDKs installed: 3.1.302 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |awesome-vhdl|puorc|0.0.1| |csharp|ms-dotnettools|1.23.3| |debugger-for-chrome|msjsdiag|4.12.11| |EditorConfig|EditorConfig|0.15.1| |gml-support|liaronce|1.7.2| |markdown-mermaid|bierner|1.8.1| |mermaid-markdown-syntax-highlighting|bpruitt-goddard|1.0.3| |python|ms-python|2020.9.114305| |unity-debug|Unity|2.7.5| |vscode-eslint|dbaeumer|2.1.10| |vscode-icons|vscode-icons-team|11.0.0| |vscode-nuget-package-manager|jmrog|1.1.6|;
Meligy commented 2 years ago

They also often fail with a message like:

image

Command 'OmniSharp: Fix all occurrences of a code issue within solution' resulted in an error ("System.OperationCanceledException: The operation was canceled.\n   at System.Threading.CancellationToken.ThrowOperationCanceledException()\n   at System.Threading.SemaphoreSlim.WaitUntilCountOrTimeoutAsync(TaskNode asyncWaiter, Int32 millisecondsTimeout, CancellationToken cancellationToken)\n   at OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers.AnalyzeProjectsAsync(Project project, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorkerWithAnalyzers.cs:line 267\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.FixAllDiagnosticProvider.GetAllDiagnosticsAsync(Project project, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 217\n   at Microsoft.CodeAnalysis.CodeFixes.FixAllContext.GetFilteredDiagnosticsAsync(Task`1 getDiagnosticsTask, ImmutableHashSet`1 diagnosticIds, Nullable`1 filterSpan)\n   at Microsoft.CodeAnalysis.CodeFixes.FixAllContext.GetProjectDiagnosticsAsync(Project project, Boolean includeAllDocumentDiagnostics)\n   at Microsoft.CodeAnalysis.CodeFixes.FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(FixAllContext fixAllContext)\n   at Microsoft.CodeAnalysis.CodeFixes.FixAllContext.DiagnosticProvider.<GetDocumentDiagnosticsToFixAsync>g__GetDocumentDiagnosticsToFixWorkerAsync|3_1(FixAllContext fixAllContext)\n   at Microsoft.CodeAnalysis.CodeFixes.FixAllContext.DiagnosticProvider.GetDocumentDiagnosticsToFixAsync(FixAllContext fixAllContext)\n   at Microsoft.CodeAnalysis.CodeFixes.BatchFixAllProvider.DetermineDiagnosticsAsync(FixAllContext fixAllContext, IProgressTracker progressTracker)\n   at Microsoft.CodeAnalysis.CodeFixes.BatchFixAllProvider.FixSingleContextAsync(FixAllContext fixAllContext, IProgressTracker progressTracker, Dictionary`2 docIdToTextMerger)\n   at Microsoft.CodeAnalysis.CodeFixes.BatchFixAllProvider.FixAllContextsAsync(FixAllContext originalFixAllContext, ImmutableArray`1 fixAllContexts)\n   at Microsoft.CodeAnalysis.CodeFixesAndRefactorings.DefaultFixAllProviderHelpers.GetFixAsync[TFixAllContext](String title, TFixAllContext fixAllContext, Func`3 fixAllContextsAsync)\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.FixSpecificDiagnosticIdAsync(Document document, String diagnosticId, FixAllScope scope, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 205\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.Handle(RunFixAllRequest request) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 110\n   at OmniSharp.Endpoint.EndpointHandler`2.AggregateResponsesFromLanguageHandlers(ExportHandler`2[] handlers, TRequest request) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 191\n   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 234\n   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 143\n   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /Users/runner/work/1/s/src/OmniSharp.Stdio/Host.cs:line 258")

There's a broken \n escaping in the message, once replaced with proper line breaks, the message becomes:

Command 'OmniSharp: Fix all occurrences of a code issue within solution' resulted in an error ("System.OperationCanceledException: The operation was canceled.
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Threading.SemaphoreSlim.WaitUntilCountOrTimeoutAsync(TaskNode asyncWaiter, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers.AnalyzeProjectsAsync(Project project, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Workers/Diagnostics/CSharpDiagnosticWorkerWithAnalyzers.cs:line 267
   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.FixAllDiagnosticProvider.GetAllDiagnosticsAsync(Project project, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 217
   at Microsoft.CodeAnalysis.CodeFixes.FixAllContext.GetFilteredDiagnosticsAsync(Task`1 getDiagnosticsTask, ImmutableHashSet`1 diagnosticIds, Nullable`1 filterSpan)
   at Microsoft.CodeAnalysis.CodeFixes.FixAllContext.GetProjectDiagnosticsAsync(Project project, Boolean includeAllDocumentDiagnostics)
   at Microsoft.CodeAnalysis.CodeFixes.FixAllContextHelper.GetDocumentDiagnosticsToFixAsync(FixAllContext fixAllContext)
   at Microsoft.CodeAnalysis.CodeFixes.FixAllContext.DiagnosticProvider.<GetDocumentDiagnosticsToFixAsync>g__GetDocumentDiagnosticsToFixWorkerAsync|3_1(FixAllContext fixAllContext)
   at Microsoft.CodeAnalysis.CodeFixes.FixAllContext.DiagnosticProvider.GetDocumentDiagnosticsToFixAsync(FixAllContext fixAllContext)
   at Microsoft.CodeAnalysis.CodeFixes.BatchFixAllProvider.DetermineDiagnosticsAsync(FixAllContext fixAllContext, IProgressTracker progressTracker)
   at Microsoft.CodeAnalysis.CodeFixes.BatchFixAllProvider.FixSingleContextAsync(FixAllContext fixAllContext, IProgressTracker progressTracker, Dictionary`2 docIdToTextMerger)
   at Microsoft.CodeAnalysis.CodeFixes.BatchFixAllProvider.FixAllContextsAsync(FixAllContext originalFixAllContext, ImmutableArray`1 fixAllContexts)
   at Microsoft.CodeAnalysis.CodeFixesAndRefactorings.DefaultFixAllProviderHelpers.GetFixAsync[TFixAllContext](String title, TFixAllContext fixAllContext, Func`3 fixAllContextsAsync)
   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.FixSpecificDiagnosticIdAsync(Document document, String diagnosticId, FixAllScope scope, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 205
   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.Handle(RunFixAllRequest request) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 110
   at OmniSharp.Endpoint.EndpointHandler`2.AggregateResponsesFromLanguageHandlers(ExportHandler`2[] handlers, TRequest request) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 191
   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 234
   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 143
   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /Users/runner/work/1/s/src/OmniSharp.Stdio/Host.cs:line 258")
BenjaminBrienen commented 1 year ago

This sometimes happens when a refactor/fix takes longer than the timeout. There are other instances where it fails immediately due to various logic errors.

Meligy commented 1 year ago

Is there any setting to increase this timeout? or to find out these logic errors to report? Thanks.

Meligy commented 1 year ago

This doesn't even come up for me with the new C# extension prerelease versions for C# dev kit, and this is even with the dev kit logged in and everything.