OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.79k stars 420 forks source link

Auto fix incorrectly convert anonymous type to tuple (IDE0050) resulting in compile errors #2231

Open snebjorn opened 3 years ago

snebjorn commented 3 years ago

I'm having an issue where anonymous type are auto converted to tuple when I save my file. It appears to be related to this fixed issue https://github.com/dotnet/roslyn/issues/50468 But I cannot figure out in what version this was released.

Example of auto fix issue:

var res = from p in products
                select new { p.Name, p.Price };

// auto fixed to

var res = from p in products
                select (p.Name, p.Price); // this does not compile

I have the following settings and I'm using an .editorconfig file

{
  "[csharp]": {
    "editor.codeActionsOnSave": {
      "source.fixAll.csharp": true
    }
  },
  "omnisharp.enableEditorConfigSupport": true,
  "omnisharp.enableRoslynAnalyzers": true
}

Rule IDE0050 cannot be configured. Please advice.

VSCode: v1.60
C# ext (ms-dotnettools.csharp): v1.23.15
TargetFramework: net5.0
JoeRobich commented 3 years ago

OminSharp should certainly be using a version of Roslyn with that particular fix.

Does the fix still get auto-applied when you set the severity to none? See https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-options for details.

example:

dotnet_diagnostic.IDE0050.severity = none
JoeRobich commented 3 years ago

OK I think I understand the problem a little better now. I propose we add a VS Code setting that will allow you to filter out particular diagnostics from being applied during FixAll operations.

snebjorn commented 3 years ago

Unfortunately it still runs with

dotnet_diagnostic.IDE0050.severity = none

https://github.com/dotnet/roslyn/issues/50468 says it was fixed by making it a "refactoring" instead of a "code style analyzer". Isn't the underlaying problem then that "fixAll" also runs "refactors"?

// vscode settings
{
  "settings": {
    "[csharp]": {
      "editor.codeActionsOnSave": {
        "source.fixAll.csharp": true,
      }
    }
  }
}