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

Added support for formatting that obeys tabsize and tabstospaces #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion OmniSharp.Tests/CodeFormat/CodeFormatTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
4 changes: 4 additions & 0 deletions OmniSharp/CodeFormat/CodeFormatHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions OmniSharp/CodeFormat/CodeFormatRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}