Exemplo n.º 1
0
        public override void OnTheFlyFormat(PolicyContainer policyParent, IEnumerable <string> mimeTypeChain,
                                            TextEditorData data, int startOffset, int endOffset)
        {
            var parser          = new CSharpParser();
            var compilationUnit = parser.ParseSnippet(data);

            if (compilationUnit == null)
            {
                Console.WriteLine("couldn't parse : " + data.Text);
                return;
            }

            if (parser.HasErrors)
            {
                return;
            }

            var policy  = policyParent.Get <CSharpFormattingPolicy> (mimeTypeChain);
            var adapter = new TextEditorDataAdapter(data);

            var formattingVisitor = new ICSharpCode.NRefactory.CSharp.AstFormattingVisitor(policy.CreateOptions(), adapter, new FormattingActionFactory(data))
            {
                HadErrors = parser.HasErrors
            };

            var changes = new List <ICSharpCode.NRefactory.CSharp.Refactoring.Action> ();

            changes.AddRange(formattingVisitor.Changes.
                             Where(c => (startOffset <= c.Offset && c.Offset < endOffset)));
            using (var undo = data.OpenUndoGroup()) {
                MDRefactoringContext.MdScript.RunActions(changes, null);
            }
        }
 public AstNode ParseText(string text)
 {
     using (TextEditorData data = new TextEditorData()) {
         data.Text = text;
         var parser = new CSharpParser();
         return(parser.ParseSnippet(data));
     }
 }
Exemplo n.º 3
0
        private string GetHighlighted()
        {
            var parser = new CSharpParser();

            var nodes = parser.ParseSnippet(ref SourceCode);

            Document = new ReadOnlyDocument(SourceCode);

            foreach (var element in nodes)
            {
                Walk(element);
            }

            var merged  = Merge();
            var cleaned = ExtraCode.Remove(merged);

            return(cleaned);
        }