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

DiagnosticSuppressor can no longer suppress compiler diagnostics #7821

Open
svick opened this issue Nov 25, 2024 · 4 comments
Open

DiagnosticSuppressor can no longer suppress compiler diagnostics #7821

svick opened this issue Nov 25, 2024 · 4 comments

Comments

@svick
Copy link

svick commented Nov 25, 2024

Type: Bug

Issue Description

A custom Roslyn DiagnosticSuppressor can no longer suppress diagnostics produced by the compiler.

Steps to Reproduce

Create a custom diagnostic suppressor, pack it as an analyzer and reference the package in a project that normally would report the diagnostics in question.

The suppressor could look like this:

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class Suppressor : DiagnosticSuppressor
{
    SuppressionDescriptor SuppressionDescriptor = new SuppressionDescriptor("Test.Suppress.IDE0052", "IDE0052", "justification");
    SuppressionDescriptor SuppressionDescriptor2 = new SuppressionDescriptor("Test.Suppress.CS0618", "CS0618", "justification");

    public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions => ImmutableArray.Create(SuppressionDescriptor, SuppressionDescriptor2);

    public override void ReportSuppressions(SuppressionAnalysisContext context)
    {
        foreach (var diagnostic in context.ReportedDiagnostics)
        {
            switch (diagnostic.Id)
            {
                case "IDE0052":
                    context.ReportSuppression(Suppression.Create(SuppressionDescriptor, diagnostic));
                    break;
                case "CS0618":
                    context.ReportSuppression(Suppression.Create(SuppressionDescriptor2, diagnostic));
                    break;
            }
        }
    }
}

The code with diagnostics like this:

class C
{
    int i; // IDE0052 is normally reported here

    public C(int i)
    {
        this.i = i;

        new ExecutionEngineException(); // CS0618 is normally reported here
    }
}

Expected Behavior

The diagnostics are not visible.

Actual Behavior

The diagnostics are not visible with C# extension version 2.50.27, as expected.

The diagnostics are visible with C# extension version 2.55.28, which is the problem.

Environment information

Environment information

VSCode version: 1.95.3
C# Extension: 2.55.28
Using OmniSharp: false

Dotnet Information .NET SDK: Version: 9.0.100 Commit: 59db016f11 Workload version: 9.0.100-manifests.c6f19616 MSBuild version: 17.12.7+5b8665660

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100\

.NET workloads installed:
[aspire]
Installation Source: VS 17.12.35506.116, VS 17.13.35507.96
Manifest Version: 8.2.2/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: VS 17.12.35506.116
Manifest Version: 9.0.0/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.0\WorkloadManifest.json
Install Type: Msi

[maccatalyst]
Installation Source: VS 17.12.35506.116
Manifest Version: 18.0.9617/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.0.9617\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: VS 17.12.35506.116
Manifest Version: 18.0.9617/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.0.9617\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 17.12.35506.116
Manifest Version: 35.0.7/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.7\WorkloadManifest.json
Install Type: Msi

Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.0
Architecture: x64
Commit: 9d5a6a9aa4

.NET SDKs installed:
6.0.401 [C:\Program Files\dotnet\sdk]
7.0.100 [C:\Program Files\dotnet\sdk]
7.0.203 [C:\Program Files\dotnet\sdk]
8.0.100-preview.7.23376.3 [C:\Program Files\dotnet\sdk]
8.0.111 [C:\Program Files\dotnet\sdk]
8.0.206 [C:\Program Files\dotnet\sdk]
8.0.307 [C:\Program Files\dotnet\sdk]
9.0.100-rc.1.24452.12 [C:\Program Files\dotnet\sdk]
9.0.100-rc.2.24474.11 [C:\Program Files\dotnet\sdk]
9.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-preview.7.23375.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0-rc.1.24452.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-preview.7.23375.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0-rc.1.24431.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.0-preview.7.23376.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0-rc.1.24452.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0-rc.2.24474.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Visual Studio Code Extensions
Extension Author Version Folder Name
auto-close-tag formulahendry 0.5.15 formulahendry.auto-close-tag-0.5.15
copilot GitHub 1.245.0 github.copilot-1.245.0
copilot-chat GitHub 0.22.4 github.copilot-chat-0.22.4
csdevkit ms-dotnettools 1.13.9 ms-dotnettools.csdevkit-1.13.9-win32-x64
csharp ms-dotnettools 2.55.28 ms-dotnettools.csharp-2.55.28-win32-x64
markdown-mermaid bierner 1.27.0 bierner.markdown-mermaid-1.27.0
msbuild-project-tools tintoy 0.6.6 tintoy.msbuild-project-tools-0.6.6
open-in-external-app YuTengjing 0.10.0 yutengjing.open-in-external-app-0.10.0
remote-explorer ms-vscode 0.4.3 ms-vscode.remote-explorer-0.4.3
remote-ssh ms-vscode-remote 0.115.1 ms-vscode-remote.remote-ssh-0.115.1
remote-ssh-edit ms-vscode-remote 0.87.0 ms-vscode-remote.remote-ssh-edit-0.87.0
vscode-docker ms-azuretools 1.29.3 ms-azuretools.vscode-docker-1.29.3
vscode-dotnet-runtime ms-dotnettools 2.2.3 ms-dotnettools.vscode-dotnet-runtime-2.2.3
vscode-github-actions github 0.27.0 github.vscode-github-actions-0.27.0
vscode-pull-request-github GitHub 0.100.3 github.vscode-pull-request-github-0.100.3
vscodeintellicode-csharp ms-dotnettools 2.2.3 ms-dotnettools.vscodeintellicode-csharp-2.2.3-win32-x64

Extension version: 2.55.28
VS Code version: Code 1.95.3 (f1a4fb101478ce6ec82fe9627c43efbf9e98c813, 2024-11-13T14:50:04.152Z)
OS version: Windows_NT x64 10.0.19045
Modes:

@dibarbet
Copy link
Member

dibarbet commented Nov 25, 2024

@svick would you mind trying the prerelease version of the extension? There was at least one issue with loading custom actions from a package, which might also impact this in the release version

@dibarbet
Copy link
Member

Also possibly related to dotnet/roslyn#75399

@svick
Copy link
Author

svick commented Nov 25, 2024

@dibarbet I can still reproduce the issue on the prerelease version 2.57.28 of the C# extension.

@dibarbet
Copy link
Member

@dibarbet I can still reproduce the issue on the prerelease version 2.57.28 of the C# extension.

Thanks. I suspect dotnet/roslyn#75399 is the problem. A prerelease with the fix should be available sometime next week.

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

No branches or pull requests

2 participants