icsharpcode / NRefactory

NRefactory - Refactoring Your C# Code
684 stars 262 forks source link

Format issue when TextEditorOptions.TabsToSpaces is false #523

Open kyubuns opened 7 years ago

kyubuns commented 7 years ago

This is the problem code. I want to change Space Indent to Tab Indent.

// use Bridge.NRefactory.5.5.4
using System;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.Editor;

namespace Foo
{
  class MainClass
  {
    public static void Main (string [] args)
    {
      var policy = FormattingOptionsFactory.CreateMono();
      var formatter = new CSharpFormatter(policy);
      formatter.TextEditorOptions.TabsToSpaces = false;

      var text = @"
namespace Foo
{
    public class Bar
    {
        public void MethodA()
        {
            Promise.All
            (
                MethodB(),
                MethodC(),
                () => {}
            );
        }
    }
}
";
      var document = new StringBuilderDocument(text);
      var syntaxTree = SyntaxTree.Parse(document, document.FileName);
      var changes = formatter.AnalyzeFormatting(document, syntaxTree);
      changes.ApplyChanges();

      Console.WriteLine(document.Text.Replace('\t', '>'));
      Console.ReadLine();
    }
  }
}

Output (Replace Tab to ">" for github)

namespace Foo
{
>public class Bar
>{
>>public void MethodA ()
>>{
>>>Promise.All
            (
>>>>MethodB (),
>>>>MethodC (),
>>>>() => {
>>>>}
>>>);
>>}
>}
}

Why does Line 8 have white space indent?