Esempio n. 1
0
        public CodeSnapshot ApplySyntaxRewriters(List <SyntaxRewriter> rewriters)
        {
            var newSolution = code.Solution;

            var res = new CodeSnapshot();
            var allDocsIdsToModify = rewriters.SelectMany(r => r.GetDocumentsIdsToModify()).ToList();

            foreach (var id in allDocsIdsToModify)
            {
                var cb = code.CodeBulksAndDocumentsIds[id];
                res.PreviousCode[cb] = cb.Tree;
            }

            foreach (var rewriter in rewriters)
            {
                var docsToModify = rewriter.GetDocumentsIdsToModify();
                var newTrees     = new Dictionary <DocumentId, SyntaxNode>();
                foreach (var id in docsToModify)
                {
                    newTrees[id] = rewriter.Visit(code.Solution.GetDocument(id).GetSyntaxRootAsync().Result);
                }

                foreach (var id in docsToModify)
                {
                    code.CodeBulksAndDocumentsIds[id].Tree = newTrees[id].SyntaxTree;
                    newSolution = newSolution.WithDocumentSyntaxRoot(id, newTrees[id]);
                }
            }

            code.SetSolution(newSolution);

            return(res);
        }
Esempio n. 2
0
        public CodeSnapshot Merge(CodeSnapshot snapshot)
        {
            foreach (var kv in snapshot.PreviousCode)
            {
                if (!PreviousCode.ContainsKey(kv.Key))
                {
                    PreviousCode[kv.Key] = kv.Value;
                }
            }

            return(this);
        }
Esempio n. 3
0
        public CodeSnapshot RemoveNode(string annotation, CodeBulk codeBulk)
        {
            var res = new CodeSnapshot();

            res.PreviousCode[codeBulk] = codeBulk.Tree;

            var node = codeBulk.Tree.GetRoot().GetAnnotatedNodes(annotation).Single();

            codeBulk.Tree = codeBulk.Tree.GetRoot().RemoveNode(node, SyntaxRemoveOptions.KeepNoTrivia).SyntaxTree;

            return(res);
        }
Esempio n. 4
0
        public CodeSnapshot InsertAfter(SyntaxNode node, string annotation, CodeBulk codeBulk)
        {
            var res = new CodeSnapshot();

            res.PreviousCode[codeBulk] = codeBulk.Tree;

            var mark = codeBulk.Tree.GetRoot().GetAnnotatedNodes(annotation).Single();

            codeBulk.Tree = codeBulk.Tree.GetRoot().InsertNodesAfter(mark, new[] { node }).SyntaxTree;

            return(res);
        }
Esempio n. 5
0
        public void ApplySnapshot(CodeSnapshot snapshot)
        {
            var newSolution = code.Solution;

            foreach (var kv in snapshot.PreviousCode)
            {
                kv.Key.Tree = kv.Value;
                newSolution = newSolution.WithDocumentSyntaxRoot(code.CodeBulksAndDocumentsIds[kv.Key], kv.Value.GetRoot());
            }

            code.SetSolution(newSolution);
        }