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

Run editor config options provider last #1559

Merged
merged 5 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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