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

Code fixes don't respect formatting settings from EditorConfig #1558

Closed
filipw opened this issue Jul 15, 2019 · 2 comments · Fixed by #1559
Closed

Code fixes don't respect formatting settings from EditorConfig #1558

filipw opened this issue Jul 15, 2019 · 2 comments · Fixed by #1559

Comments

@filipw
Copy link
Member

filipw commented Jul 15, 2019

This is really great, thanks @filipw!

After some experimentation however, it seems like .editorconfig settings aren't being passed through to analyzers, is that right? Using roslynator, omnisharp.json settings appear to be passed through to the analyzer and affect diagnostics and code actions, but not .editorconfig settings.

Example:

// Program.cs
public class Program
{
   public string Something { get; set; }
}
# .editorconfig
root = true
[*.cs]
indent_size = 3
// omnisharp.json
{
   "FormattingOptions": {
      "EnableEditorConfigSupport": true,
      "IndentationSize": 2
   },
   "RoslynExtensionsOptions": {
      "EnableAnalyzersSupport": true,
      "LocationPaths": [
         "C:/Users/Nick/.omnisharp/roslynator"
      ]
   }
}

If I now Format Document, OmniSharp-roslyn correctly sets the indent to 3 (as specified by .editorconfig). However, if I move the cursor to the beginning of line 2 there is a "Fix formatting" code action available from roslynator, and running this sets the indent back to 2 (as specified by omnisharp.json).

Removing the "IndentationSize" line entirely from omnisharp.json results in roslynator using the default of 4.

Similar things occur with newlines, where roslynator applies omnisharp.json preferences and O#-roslyn applies .editorconfig preferences.

Originally posted by @nickspoons in #1526 (comment)

@filipw
Copy link
Member Author

filipw commented Jul 15, 2019

@nickspoons thanks for the issue. The Fix formatting code fix is actually from Roslyn (https://github.com/dotnet/roslyn/blob/master/src/Features/Core/Portable/Formatting/FormattingCodeFixProvider.cs) not from Roslynator.

But it is a nice find - thanks.

All the options are flown correctly to the analyzers but, basically, we run the editorconfig provider before the omnisharp.json-formatting provider which causes all formatting settings to be lost. This doesn't affect internal OmniSharp formatting endpoints, as on those endpoints editorconfig is re-applied again on invoke, but it affects "3rd party" formatting invokers like this code fix.
This only affects formatting rules, other editorconfig options such as naming conventions are not affected and a respected in analyzers, code fixes and refactorings correctly.

I opened #1559 to remedy that.

@nickspoons
Copy link
Member

Brilliant, thanks so much @filipw!

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

Successfully merging a pull request may close this issue.

2 participants