void HandleDocumentParsed(object sender, EventArgs e) { if (src != null) { src.Cancel(); } resolver = null; if (guiDocument != null && MonoDevelop.Core.PropertyService.Get("EnableSemanticHighlighting", true)) { var parsedDocument = guiDocument.ParsedDocument; if (parsedDocument != null) { unit = parsedDocument.GetAst <CompilationUnit> (); parsedFile = parsedDocument.ParsedFile as CSharpParsedFile; if (guiDocument.Project != null && guiDocument.IsCompileableInProject) { src = new CancellationTokenSource(); var cancellationToken = src.Token; System.Threading.Tasks.Task.Factory.StartNew(delegate { Thread.Sleep(100); compilation = guiDocument.Compilation; var newResolver = new CSharpAstResolver(compilation, unit, parsedFile); var visitor = new QuickTaskVisitor(newResolver, cancellationToken); unit.AcceptVisitor(visitor); if (!cancellationToken.IsCancellationRequested) { Gtk.Application.Invoke(delegate { if (cancellationToken.IsCancellationRequested) { return; } var editorData = guiDocument.Editor; if (editorData == null) { return; } resolver = newResolver; quickTasks = visitor.QuickTasks; OnTasksUpdated(EventArgs.Empty); var textEditor = editorData.Parent; if (textEditor != null) { var margin = textEditor.TextViewMargin; if (!parsedDocument.HasErrors) { highlightedSegmentCache.Clear(); margin.PurgeLayoutCache(); textEditor.QueueDraw(); } } }); } }, cancellationToken); } } } }
void HandleDocumentParsed(object sender, EventArgs e) { if (src != null) { src.Cancel(); } resolver = null; if (guiDocument.IsProjectContextInUpdate) { return; } if (guiDocument != null && SemanticHighlightingEnabled) { var parsedDocument = guiDocument.ParsedDocument; if (parsedDocument != null) { if (guiDocument.Project != null && guiDocument.IsCompileableInProject) { src = new CancellationTokenSource(); var newResolverTask = guiDocument.GetSharedResolver(); var cancellationToken = src.Token; System.Threading.Tasks.Task.Factory.StartNew(delegate { if (newResolverTask == null) { return; } var newResolver = newResolverTask.Result; if (newResolver == null) { return; } unit = newResolver.RootNode as SyntaxTree; // parsedFile = newResolver.UnresolvedFile; var visitor = new QuickTaskVisitor(newResolver, cancellationToken); try { unit.AcceptVisitor(visitor); } catch (Exception ex) { LoggingService.LogError("Error while analyzing the file for the semantic highlighting.", ex); return; } if (!cancellationToken.IsCancellationRequested) { Gtk.Application.Invoke(delegate { if (cancellationToken.IsCancellationRequested) { return; } var editorData = guiDocument.Editor; if (editorData == null) { return; } // compilation = newResolver.Compilation; resolver = newResolver; quickTasks = visitor.QuickTasks; OnTasksUpdated(EventArgs.Empty); foreach (var kv in lineSegments) { try { kv.Value.tree.RemoveListener(); } catch (Exception) { } } lineSegments.Clear(); var textEditor = editorData.Parent; if (textEditor != null) { if (!parsedDocument.HasErrors) { var margin = textEditor.TextViewMargin; margin.PurgeLayoutCache(); textEditor.QueueDraw(); } } }); } }, cancellationToken); } } } }