Skip to content

Commit

Permalink
Merge pull request #1715 from OmniSharp/bugfix/usings
Browse files Browse the repository at this point in the history
Fixed a bug where organizing usings clashed with other formatting settings
  • Loading branch information
JoeRobich authored Feb 19, 2020
2 parents e72046b + 701112e commit d0dcdc9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Changelog
All changes to the project will be documented in this file.

## [1.34.13] - not yet released
* Fixed a bug where organizing usings clashed with other formatting settings (PR: [#1715](https://github.com/OmniSharp/omnisharp-roslyn/pull/1713))

## [1.34.12] - 2020-02-18
* Fixed out of bounds exception in line mapping ([omnisharp-vscode#3485](https://github.com/OmniSharp/omnisharp-vscode/issues/3485), PR: [#1707](https://github.com/OmniSharp/omnisharp-roslyn/pull/1707))
* Added support for aliases in project references ([#1685](https://github.com/OmniSharp/omnisharp-roslyn/issues/1685), PR: [#1701](https://github.com/OmniSharp/omnisharp-roslyn/pull/1701))
* Raised the lowest discovered VS2019 version to 16.3 ((#1700)[https://github.com/OmniSharp/omnisharp-roslyn/issues/1700], PR: (#1713)(https://github.com/OmniSharp/omnisharp-roslyn/pull/1713))
* Raised the lowest discovered VS2019 version to 16.3 ([#1700](https://github.com/OmniSharp/omnisharp-roslyn/issues/1700), PR: [#1713](https://github.com/OmniSharp/omnisharp-roslyn/pull/1713))

## [1.34.11] - 2020-02-05
* Updated the bundled to Mono 6.8.0 and MSBuild to be copied from Mono 6.8.0 ([#1693](https://github.com/OmniSharp/omnisharp-roslyn/issues/1693), PR: [#1697](https://github.com/OmniSharp/omnisharp-roslyn/pull/1697))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static async Task<Document> FormatDocument(Document document, OmniSharpO
var newDocument = textSpan != null ? await Formatter.FormatAsync(document, textSpan.Value, optionSet) : await Formatter.FormatAsync(document, optionSet);
if (omnisharpOptions.FormattingOptions.OrganizeImports)
{
newDocument = await Formatter.OrganizeImportsAsync(document);
newDocument = await Formatter.OrganizeImportsAsync(newDocument);
}

return newDocument;
Expand Down
32 changes: 32 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/EditorConfigFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,38 @@ class Bar:Foo { }
}
}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task RespectsCSharpFormatSettingsWhenOrganizingUsings(string filename)
{
var testFile = new TestFile(Path.Combine(TestAssets.Instance.TestFilesFolder, filename), @"
using Y;
using X;
class Foo { }
class Bar : Foo { }
");
var expected = @"
using X;
using Y;
class Foo { }
class Bar:Foo { }
";

using (var host = CreateOmniSharpHost(new[] { testFile }, new Dictionary<string, string>
{
["FormattingOptions:EnableEditorConfigSupport"] = "true",
["FormattingOptions:OrganizeImports"] = "true"
}, TestAssets.Instance.TestFilesFolder))
{
var requestHandler = host.GetRequestHandler<CodeFormatService>(OmniSharpEndpoints.CodeFormat);

var request = new CodeFormatRequest { FileName = testFile.FileName };
var response = await requestHandler.Handle(request);

Assert.Equal(expected, response.Buffer);
}
}

[Theory]
[InlineData("dummy.cs")]
Expand Down

0 comments on commit d0dcdc9

Please sign in to comment.