-
Notifications
You must be signed in to change notification settings - Fork 420
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
New analyzer API (DiagnosticSuppressor) is not supported #1711
Comments
thanks for the issue, this is indeed currently not supported |
@mavasani did this great job of adding this new DiagnosticSuppressor API. Perhaps supporting this in OmniSharp is not that complicated (host initialization?). -I say this without knowing, I suspect that it's not all that simple, but I just hope :) - |
@sailro, @filipw I think I may have gotten around this issue by enabling roslyn analyzers and editorconfig support. You can configure the rules you want enabled or disabled globally within your Note: After enabling roslyn analyzers and editorconfig support, Omnisharp will require to be restarted in order for the changes to take effect. In addition, OmniSharp needs to be restarted after you make any changes to your Aside from the inconvenience of having to reload OmniSharp everytime I make a changes to my As a user sometimes I would like to be able to exclude specific files or directories from analysis. An example would be auto generated files from an EF Core migration. @savpek do you know if specific files or directories can be excluded from OmniSharp file analysis? |
@loligans have you tested suppres message attributes where specifically following: namespaceanddescendants - (Requires compiler version 3.x or higher and Visual Studio 2019) This scope suppresses warnings in a namespace and all its descendant symbols. The namespaceanddescendants value is ignored by legacy analysis. Which seems roslyn way to do similar thing. However i have never tested those with omnisharp so they may or may not work. If they don't that is very good feature to add 🤔 |
@savpek Sorry, I'm not sure how to do what you're suggesting. What I have tried is to disable the analyzers that pollute the VSCode Problems Pane by using a nested |
@loligans have you tried https://docs.microsoft.com/en-us/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2019#set-rule-severity-of-multiple-analyzer-rules-at-once-in-an-editorconfig-file? Dropping an editorconfig with the following contents in any folder should ensure no analyzer diagnostics reported within it, unless some parent directory is explicitly enabling some rules.
Another approach is trying out .editorconfig with following contents, which will treat the entire folder and sub-folders as generated code, which should filter almost all analyzer diagnostics (except the critical ones like some security rules which explicitly want to flag generated code)
|
NOTE: The suggested features above needs "Visual Studio 2019 version 16.5 or later" |
Thank you for the help @mavasani. Applying the suggested configuration unfortunately did not solve the issue. I should note that I am running on Linux, so I do not have Visual Studio 2019 installed. VSCode Version: 1.44.2 Here is my Omnisharp log if that helps with diagnostics:
|
What version of Roslyn compiler do you have? This is a compiler feature added in version 3.5.0 of the compiler, so should work even in other hosts. |
It's not clear to me exactly how to get the Roslyn compiler version. However, when I run
Is 16.4.0+e901037fe close to what you're looking for? |
That indicates you are on MSBuild toolset that shipped with VS2019 16.4. So you will need 16.5 version of it... |
I can confirm the issue I was experiencing is resolved using the latest build of the vscode extension (
|
Thanks, now officially documented at https://docs.microsoft.com/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2019#configure-generated-code |
Worth noting that |
+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;
} |
So is there no way currently to enable the Unity analyzers on VSCode? Edit: You guys are talking about editor config files, but all the links talk about creating/editing them when using Visual Studio. Isn't this thread about VSCode? Edit 2: I created a .editorconfig file in the root folder of the project and that worked, but the line |
I figured this out more or less, and posted a Reddit thread explaining how to set up the Unity analyzers with Omnisharp in Visual Studio Code. Hope it helps someone because it took me 2 whole days! 😁😁 |
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. |
@filipw That's good to hear! Is there an expected release date for supporting the Unity suppressors (the original intention of this issue)? 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 😅 |
unfortunately the suppressors haven't been looked at yet, I am very sorry. Will try to prioritize this!
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). |
@filipw This functionality is now part of the official VSCode documentation. It would be great to get the supressors working as well! |
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.
|
@filipw any updates on this issue? |
no |
Seems like we are having some updates on this!! microsoft/Microsoft.Unity.Analyzers#170 (comment) |
@filipw I have just upgrade to vscode version 1.62.0. However, I still get issues that I know are suppressed by nunit.analyzers.
I know that the nunit.analyzers are loaded as I can get violations against other rules to show up. Is there anything I need to configure or do the analyzers need to do something different for vs-code to recognize the suppressor? |
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: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:
dotnet/roslyn#36067
The text was updated successfully, but these errors were encountered: