Ejemplo n.º 1
0
        bool AreEqual(HighlightingSegmentTree highlightTree, HighlightingSegmentTree newTree, CancellationToken token)
        {
            if (newTree == null || highlightTree == null || highlightTree.Count != newTree.Count)
            {
                return(false);
            }
            var e1 = highlightTree.GetEnumerator();
            var e2 = newTree.GetEnumerator();
            int i  = 0;

            while (e1.MoveNext() && e2.MoveNext())
            {
                var i1 = e1.Current;
                var i2 = e2.Current;
                if (i++ % 1000 == 0)
                {
                    if (token.IsCancellationRequested)
                    {
                        return(false);
                    }
                }
                if (i1.Offset != i2.Offset ||
                    i1.Length != i2.Length ||
                    i1.Style != i2.Style)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
 void EnsureGuiDocument()
 {
     if (guiDocument != null)
     {
         return;
     }
     try {
         if (File.Exists(Document.FileName))
         {
             guiDocument = IdeApp.Workbench.GetDocument(Document.FileName);
         }
     } catch (Exception) {
         guiDocument = null;
     }
     if (guiDocument != null)
     {
         guiDocument.Closed += delegate {
             if (src != null)
             {
                 src.Cancel();
             }
         };
         guiDocument.DocumentParsed += HandleDocumentParsed;
         highlightedSegmentCache     = new HighlightingSegmentTree();
         highlightedSegmentCache.InstallListener(guiDocument.Editor.Document);
         if (guiDocument.ParsedDocument != null)
         {
             HandleDocumentParsed(this, EventArgs.Empty);
         }
     }
 }
Ejemplo n.º 3
0
 public override void Dispose()
 {
     CancelHighlightingTask();
     if (highlightTree != null)
     {
         highlightTree.RemoveListener();
     }
     highlightTree = null;
     base.Dispose();
 }
Ejemplo n.º 4
0
        protected override void DocumentParsed()
        {
            var parsedDocument = documentContext.ParsedDocument;

            if (parsedDocument == null)
            {
                return;
            }
            var resolver = parsedDocument.GetAst <SemanticModel> ();

            if (resolver == null)
            {
                return;
            }
            CancelHighlightingTask();
            var token = src.Token;
            var theme = editor.Options.GetEditorTheme();

            Task.Run(async delegate {
                try {
                    var root    = await resolver.SyntaxTree.GetRootAsync(token);
                    var newTree = new HighlightingSegmentTree();

                    var visitor = new HighlightingVisitior(theme, resolver, newTree.Add, token, TextSegment.FromBounds(0, root.FullSpan.Length));
                    visitor.Visit(root);
                    var doNotify = !AreEqual(highlightTree, newTree, token);

                    if (!token.IsCancellationRequested)
                    {
                        Gtk.Application.Invoke(delegate {
                            if (token.IsCancellationRequested)
                            {
                                return;
                            }
                            if (highlightTree != null)
                            {
                                highlightTree.RemoveListener();
                            }
                            highlightTree = newTree;
                            highlightTree.InstallListener(editor);
                            if (doNotify)
                            {
                                NotifySemanticHighlightingUpdate();
                            }
                        });
                    }
                } catch (OperationCanceledException) {
                } catch (AggregateException ae) {
                    ae.Flatten().Handle(x => x is OperationCanceledException);
                }
            }, token);
        }