diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bd49e30ee..858895dab0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All changes to the project will be documented in this file. } ``` * Added support for *AdditionalFiles* in csproj files ([#1510](https://github.com/OmniSharp/omnisharp-roslyn/issues/1510), PR: [#1547](https://github.com/OmniSharp/omnisharp-roslyn/pull/1547)) +* Fixed a bug in *.editorconfig* where formatting settings were not correctly passed into external code fixes ([#1558](https://github.com/OmniSharp/omnisharp-roslyn/issues/1558), PR: [#1559](https://github.com/OmniSharp/omnisharp-roslyn/pull/1559)) ## [1.33.0] - 2019-07-01 * Added support for `.editorconfig` files to control formatting settings, analyzers, coding styles and naming conventions. The feature is currently opt-into and needs to be enabled using OmniSharp configuration ([#31](https://github.com/OmniSharp/omnisharp-roslyn/issues/31), PR: [#1526](https://github.com/OmniSharp/omnisharp-roslyn/pull/1526)) diff --git a/src/OmniSharp.Roslyn.CSharp/Services/EditorConfigWorkspaceOptionsProvider.cs b/src/OmniSharp.Roslyn.CSharp/Services/EditorConfigWorkspaceOptionsProvider.cs index 3a82a91e1f..94a33a7906 100644 --- a/src/OmniSharp.Roslyn.CSharp/Services/EditorConfigWorkspaceOptionsProvider.cs +++ b/src/OmniSharp.Roslyn.CSharp/Services/EditorConfigWorkspaceOptionsProvider.cs @@ -1,10 +1,7 @@ using System.Composition; using System.IO; -using System.Threading; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Options; using Microsoft.Extensions.Logging; -using Microsoft.VisualStudio.CodingConventions; using OmniSharp.Options; using OmniSharp.Roslyn.CSharp.Services.Formatting.EditorConfig; using OmniSharp.Roslyn.Options; @@ -16,7 +13,7 @@ public class EditorConfigWorkspaceOptionsProvider : IWorkspaceOptionsProvider { private readonly ILoggerFactory _loggerFactory; - public int Order => -100; + public int Order => 200; [ImportingConstructor] public EditorConfigWorkspaceOptionsProvider(ILoggerFactory loggerFactory) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs index 52c2dc2a3a..ed4c61cf87 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -121,6 +122,48 @@ class Bar:Foo { } } } + + [Theory] + [InlineData("dummy.cs")] + [InlineData("dummy.csx")] + public async Task RespectsCSharpFormatSettings_InExecutedCodeActions(string filename) + { + // omnisharp.json sets spacing to true (1 space) + // but .editorconfig sets it to false (0 spaces) + var testFile = new TestFile(Path.Combine(TestAssets.Instance.TestFilesFolder, filename), @" +class Foo { } +class Bar $$ : Foo { } +"); + var expected = @" +class Foo { } +class Bar:Foo { } +"; + using (var host = CreateOmniSharpHost(new[] { testFile }, new Dictionary + { + ["FormattingOptions:EnableEditorConfigSupport"] = "true", + ["FormattingOptions:SpaceAfterColonInBaseTypeDeclaration"] = "true", // this should be ignored because .editorconfig gets higher priority + ["FormattingOptions:SpaceBeforeColonInBaseTypeDeclaration"] = "true", // this should be ignored because .editorconfig gets higher priority + ["RoslynExtensionsOptions:EnableAnalyzersSupport"] = "true" + }, TestAssets.Instance.TestFilesFolder)) + { + var point = testFile.Content.GetPointFromPosition(); + var runRequestHandler = host.GetRequestHandler(OmniSharpEndpoints.V2.RunCodeAction); + var runRequest = new RunCodeActionRequest + { + Line = point.Line, + Column = point.Offset, + FileName = testFile.FileName, + Identifier = "Fix formatting", + WantsTextChanges = false, + WantsAllCodeActionOperations = true, + Buffer = testFile.Content.Code + }; + var runResponse = await runRequestHandler.Handle(runRequest); + + Assert.Equal(expected, ((ModifiedFileResponse)runResponse.Changes.First()).Buffer, ignoreLineEndingDifferences: true); + } + } + [Theory] [InlineData("dummy.cs")] [InlineData("dummy.csx")]