diff --git a/OmniSharp.Tests/CodeFormat/CodeFormatTest.cs b/OmniSharp.Tests/CodeFormat/CodeFormatTest.cs index 9cc30ac..4483c62 100644 --- a/OmniSharp.Tests/CodeFormat/CodeFormatTest.cs +++ b/OmniSharp.Tests/CodeFormat/CodeFormatTest.cs @@ -22,7 +22,27 @@ public void Should_format_code() var handler = new CodeFormatHandler(new OmniSharpConfiguration()); var buffer = handler.Format(new CodeFormatRequest {Buffer = code}).Buffer; - buffer.Replace("\r\n", "\n").ShouldEqual(expected); + buffer.Replace("\r\n", "\n").ShouldEqual(expected); + } + + [Test] + public void Obeys_formatting_options() + { + string code = +@"public class Test { +public void ExampleMethod() +{ +} +}"; + + var handler = new CodeFormatHandler(new OmniSharpConfiguration()); + var buffer = handler.Format(new CodeFormatRequest + { + Buffer = code, + TabSize = 4, + TabsToSpaces = false + }).Buffer; + buffer.ShouldContain('\t'); } } } diff --git a/OmniSharp/CodeFormat/CodeFormatHandler.cs b/OmniSharp/CodeFormat/CodeFormatHandler.cs index a9b5052..d1ba824 100644 --- a/OmniSharp/CodeFormat/CodeFormatHandler.cs +++ b/OmniSharp/CodeFormat/CodeFormatHandler.cs @@ -15,6 +15,10 @@ public CodeFormatResponse Format(CodeFormatRequest request) { var options = _config.TextEditorOptions; var policy = _config.CSharpFormattingOptions; + + options.TabsToSpaces = request.TabsToSpaces; + options.TabSize = request.TabSize; + var formatter = new CSharpFormatter(policy, options); formatter.FormattingMode = FormattingMode.Intrusive; var output = formatter.Format(request.Buffer); diff --git a/OmniSharp/CodeFormat/CodeFormatRequest.cs b/OmniSharp/CodeFormat/CodeFormatRequest.cs index ebe1469..78d9621 100644 --- a/OmniSharp/CodeFormat/CodeFormatRequest.cs +++ b/OmniSharp/CodeFormat/CodeFormatRequest.cs @@ -11,5 +11,9 @@ public bool ExpandTab get { return _expandTab; } set { _expandTab = value; } } + + public bool TabsToSpaces { get; set; } = true; + + public int TabSize { get; set; } = 4; } }