示例#1
0
    public void Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block()
    {
        // Arrange
        var content = @"
<div>
    @result
</div>
<div>
    @(result)
</div>";
        var parsed  = ParseDocument(
            RazorLanguageVersion.Latest,
            content,
            Array.Empty <DirectiveDescriptor>());

        var rewriter = new WhitespaceRewriter();

        // Act
        var rewritten = rewriter.Visit(parsed.Root);

        // Assert
        var rewrittenTree = RazorSyntaxTree.Create(rewritten, parsed.Source, parsed.Diagnostics, parsed.Options);

        BaselineTest(rewrittenTree);
    }
        public static SyntaxNode NormalizeWhiteSpaceHelper(SyntaxNode initialSourceNode)
        {
            if (GeeksProductivityToolsPackage.Instance != null)
            {
                initialSourceNode = Formatter.Format(initialSourceNode, GeeksProductivityToolsPackage.Instance.CleanupWorkingSolution.Workspace);
            }

            initialSourceNode = new BlockRewriter(initialSourceNode).Visit(initialSourceNode);
            initialSourceNode = new WhitespaceRewriter(initialSourceNode).Visit(initialSourceNode);
            return(initialSourceNode);
        }
        public static SyntaxNode NormalizeWhiteSpaceHelper(SyntaxNode initialSourceNode, Options options)
        {
            if (TidyCSharpPackage.Instance != null)
            {
                initialSourceNode = Formatter.Format(initialSourceNode, TidyCSharpPackage.Instance.CleanupWorkingSolution.Workspace);
            }

            initialSourceNode = new BlockRewriter(initialSourceNode, options).Visit(initialSourceNode);
            initialSourceNode = new WhitespaceRewriter(initialSourceNode, options).Apply();
            return(initialSourceNode);
        }
        public SyntaxNode NormalizeWhiteSpaceHelper(SyntaxNode initialSourceNode, Options options)
        {
            if (TidyCSharpPackage.Instance != null)
            {
                initialSourceNode = Formatter.Format(initialSourceNode, TidyCSharpPackage.Instance.CleanupWorkingSolution.Workspace);
            }

            initialSourceNode = new BlockRewriter(initialSourceNode, options).Visit(initialSourceNode);
            initialSourceNode = RefreshResult(initialSourceNode);
            initialSourceNode = new WhitespaceRewriter(initialSourceNode, options).Apply();
            if (CheckOption((int)CleanupTypes.Add_blank_line_between_statements_more_than_one_line))
            {
                initialSourceNode = RefreshResult(initialSourceNode);
                initialSourceNode = new BlankLineRewriter(this.ProjectItemDetails.SemanticModel).Visit(initialSourceNode);
            }
            return(initialSourceNode);
        }
        public RazorSyntaxTree Execute(RazorCodeDocument codeDocument, RazorSyntaxTree syntaxTree)
        {
            if (codeDocument == null)
            {
                throw new ArgumentNullException(nameof(codeDocument));
            }

            if (syntaxTree == null)
            {
                throw new ArgumentNullException(nameof(syntaxTree));
            }

            var whitespaceRewriter = new WhitespaceRewriter();
            var rewritten          = whitespaceRewriter.Visit(syntaxTree.Root);

            var rewrittenSyntaxTree = RazorSyntaxTree.Create(rewritten, syntaxTree.Source, syntaxTree.Diagnostics, syntaxTree.Options);

            return(rewrittenSyntaxTree);
        }