为什么罗斯林不尊重空白琐事,而是强制制表符缩进?

时间:2018-10-07 21:51:53

标签: roslyn

我正在开发一个业余项目,试图在this repository降低C#使其可以被NES编译。在提交9b532f739be时,我的第一个代码修复提供程序上的某些单元测试失败,仅是因为Roslyn忽略了line 90 of the ForbidMuliplicationCodeFixProvider.cs file中来自要替换的节点的空白琐事。我还尝试在具有相同WhiteSpaceTrivia缩进大小的新节点上尝试NormalizeWhiteSpace,并尝试了几次其他尝试失败,但最终总是在修改后的文档上使用标准制表符大小的缩进。我需要忍受这个小错误吗?

  var assignment = SyntaxFactory.AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, variableIdentifier, invocation);
  assignment = assignment.WithTriviaFrom(node);
  var syntaxRoot = await document.GetSyntaxRootAsync();
  var modifiedRoot = syntaxRoot.ReplaceNode(node, assignment);

  var modifiedDocument = document.WithSyntaxRoot(modifiedRoot);
  modifiedDocument = await AddUsingStatementAsync(cancelToken, modifiedDocument);

  return modifiedDocument;

node变量来自WhiteDocumentTrivia中具有6个空格(缩进3层)的原始文档,应该将其复制到替换节点中,但是修改后的文档的输出具有3个缩进选项卡

我的测试失败,并显示以下消息:

The checked string has different spaces than expected one. At line 7, col 12, expected '...     test = NESMath....' was '...           test = NE...'.
The checked string:
    ["using NINNES.Platform.Shims;

namespace NINNES.RoslynAnalyzers.Tests.Assets {
  class MultiplicationAssignment {
    public void Multiply() {
      var test = 2;
            test = NESMath.Multiply(test, 42);
    }
  }
}
"]
The expected string:
    ["using NINNES.Platform.Shims;

namespace NINNES.RoslynAnalyzers.Tests.Assets {
  class MultiplicationAssignment {
    public void Multiply() {
      var test = 2;
      test = NESMath.Multiply(test, 42);
    }
  }
}
"]

顺便说一句:只要学习代码修改方面的知识,对Roslyn代码的评论将不胜感激。

0 个答案:

没有答案