Ejemplo n.º 1
0
        public static IList <TextChange> GetEditsAfterKeystroke(SyntaxTree syntaxTree, int position, char character, FormattingOptions options)
        {
            var location = syntaxTree.MapRootFilePosition(position);

            // Find span of block / statement terminated by the character just typed.
            var token = ((SyntaxNode)syntaxTree.Root).FindTokenOnLeft(location);

            if (token.Text != character.ToString())
            {
                return(new List <TextChange>());
            }

            // Get span of node containing this token.
            var span = token.Parent.GetTextSpanRoot();

            if (span == null)
            {
                return(new List <TextChange>());
            }

            return(GetEdits(syntaxTree, (SyntaxNode)syntaxTree.Root, span.Value.Span, options));
        }
Ejemplo n.º 2
0
        public static IList <TextChange> GetEdits(SyntaxTree syntaxTree, SyntaxNode syntaxNode, TextSpan textSpan, FormattingOptions options)
        {
            // Format.
            var formattingVisitor = new FormattingVisitor(syntaxTree, textSpan, options);

            formattingVisitor.Visit(syntaxNode);

            return(formattingVisitor.Edits.Values);
        }