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:

When using VSCode:

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)
Worth noting that
DiagnosticSuppressorsupport 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 😂
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:
@filipw any updates on this issue?
@marcospgp
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.
@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.