omnisharp-roslyn: New analyzer API (DiagnosticSuppressor) is not supported

I’m using a pack of Roslyn Analyzers built from: https://github.com/microsoft/Microsoft.Unity.Analyzers

On a Unity project (Game engine) available here: https://learn.unity.com/project/roll-a-ball-tutorial

When using Visual Studio: image

When using VSCode: image

Omnisharp is able to correctly consume regular Analyzers (see UNT0009). But Diagnostic suppressors are not supported:

"Private member 'ReadmeEditor.Awake' is unused. [Assembly-CSharp-Editor]"

This message is correctly suppressed in the VS context, but not within VSCode.

The code for this suppressor is here: https://github.com/microsoft/Microsoft.Unity.Analyzers/blob/master/src/Microsoft.Unity.Analyzers/UnusedMessageSuppressor.cs

The Roslyn team added a new API regarding programmatic suppression of diagnostics: https://github.com/dotnet/roslyn/pull/36067

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 14
  • Comments: 27 (5 by maintainers)

Most upvoted comments

Worth noting that DiagnosticSuppressor support is important for Microsoft’s Unity analyzers.

no

unfortunately the suppressors haven’t been looked at yet, I am very sorry. Will try to prioritize this! I usually put highest priority on things that I personally use 😂

It’s interesting that Unity & Microsoft are sort of partnering up to get Unity working well with VSCode, but the workhorse under the whole thing is being maintained entirely by you 😅

That is very kind of you to say! but there are over 100 contributors here https://github.com/OmniSharp/omnisharp-roslyn/graphs/contributors and currently a group of 4 maintainers (the ones seen on PR reviews).

+1 for Unity Analyzers. This could especially be useful to silence invalid warnings from other analyzers on Unity methods:

// CA1822: Member 'Awake' does not access instance data and can be marked as static. 
// IDE0051 : Private member 'TouchOnScreenTest.Awake' is unused. 
private void Awake()
{
	Application.targetFrameRate = 120;
}

unfortunately the suppressors haven’t been looked at yet, I am very sorry. Will try to prioritize this!

@filipw any updates on this issue?

@marcospgp

Edit 2: I created a .editorconfig file in the root folder of the project and that worked, but the line generated_code = true just silenced all of my warnings. What was that supposed to solve?

I solved this in the root .editorconfig by creating a separate header and then adding the generated code line. In this way I could turn off all warning for downloaded or imported code, e.g., TextMesh Pro.

[Assets/TextMesh Pro/**.cs]
generated_code = true

@sbaranov this was fixed in https://github.com/OmniSharp/omnisharp-roslyn/pull/2028 which will be in the next release

There is a problem in omnisharp support for .editorconfig. Whenever the project is updated outside of vscode, omnisharp dynamically reloads the project, but forgets to use .editorconfig at that point, so all settings gets reset - all warnings become enabled, all formatting rules switch to defaults, etc. This means that whenever you switch git branches, or make any change in Unity that affects the project such as adding a new script, you suddenly see thousands of unrelated warnings in vscode that shouldn’t be there. One workaround is to restart vscode every time omnisharp lost its settings, which basically becomes every few minutes if you’re actively editing.