Format issue when TextEditorOptions.TabsToSpaces is false #523

Open
opened 2016-10-28 05:38:35 -05:00 by kyubuns · 0 comments
kyubuns commented 2016-10-28 05:38:35 -05:00 (Migrated from github.com)

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?

This is the problem code. I want to change Space Indent to Tab Indent. ``` csharp // 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?
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-icsharpcode/NRefactory#523
No description provided.