Skip to content

Commit

Permalink
Run editor config options provider last (#1559)
Browse files Browse the repository at this point in the history
* run editor config options provider last

* added tests

* removed unused code

* added a bug fix note

* Update CHANGELOG.md
  • Loading branch information
filipw authored and akshita31 committed Jul 15, 2019
1 parent 50c8205 commit 5a5250b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down
43 changes: 43 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -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<string, string>
{
["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<RunCodeActionService>(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")]
Expand Down

0 comments on commit 5a5250b

Please sign in to comment.