[anjuta] language-support-vala: correctly track whether there are errors



commit 9e0b3b155ad0578cf6a5afd729b5fcb9b888c833
Author: Abderrahim Kitouni <akitouni src gnome org>
Date:   Thu Aug 18 14:32:14 2011 +0100

    language-support-vala: correctly track whether there are errors
    
    This fixes the most common crash I was experiencing

 configure.ac                              |    2 +-
 plugins/language-support-vala/plugin.vala |    4 +-
 plugins/language-support-vala/report.vala |   46 +++++++++++++++++++++-------
 3 files changed, 37 insertions(+), 15 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index bc543e3..9ded49f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,7 +53,7 @@ GLADEUI_REQUIRED=3.9.2
 
 dnl Vala
 VALA12_REQUIRED=0.11.2
-VALA14_REQUIRED=0.13.2
+VALA14_REQUIRED=0.13.3
 
 dnl Introspection
 GI_REQUIRED=0.9.5
diff --git a/plugins/language-support-vala/plugin.vala b/plugins/language-support-vala/plugin.vala
index 7858c5a..9df3635 100644
--- a/plugins/language-support-vala/plugin.vala
+++ b/plugins/language-support-vala/plugin.vala
@@ -104,7 +104,7 @@ public class ValaPlugin : Plugin {
 						}
 					}
 
-					if (report.errors_found () || cancel.is_cancelled ()) {
+					if (report.get_errors () > 0 || cancel.is_cancelled ()) {
 						Vala.CodeContext.pop();
 						return;
 					}
@@ -535,7 +535,7 @@ public class ValaPlugin : Plugin {
 			var ns_ref = new Vala.UsingDirective (new Vala.UnresolvedSymbol (null, "GLib"));
 			file.add_using_directive (ns_ref);
 
-			report.clear_error_indicators ();
+			report.clear_error_indicators (file);
 
 			parse ();
 
diff --git a/plugins/language-support-vala/report.vala b/plugins/language-support-vala/report.vala
index 4dc5374..a18c3e8 100644
--- a/plugins/language-support-vala/report.vala
+++ b/plugins/language-support-vala/report.vala
@@ -23,7 +23,9 @@ public class AnjutaReport : Vala.Report {
 		public string message;
 	}
 	public IAnjuta.DocumentManager docman { get; set; }
-	Vala.List<Error?> errors = new Vala.ArrayList<Error?>();
+	Vala.List<Error?> errors_list = new Vala.ArrayList<Error?>();
+	bool general_error = false;
+
 	public void update_errors (IAnjuta.Editor editor) {
 		var ind = editor as IAnjuta.Indicable;
 		var mark = editor as IAnjuta.Markable;
@@ -35,7 +37,7 @@ public class AnjutaReport : Vala.Report {
 		if (mark != null)
 			mark.delete_all_markers (IAnjuta.MarkableMarker.MESSAGE);
 
-		foreach (var e in errors) {
+		foreach (var e in errors_list) {
 			if (e.source.file.filename.has_suffix (((IAnjuta.Document)editor).get_filename ())) {
 				if (ind != null) {
 					/* begin_iter should be one cell before to select the first character */
@@ -55,8 +57,25 @@ public class AnjutaReport : Vala.Report {
 
 		}
 	}
-	public void clear_error_indicators () {
-		errors = new Vala.ArrayList<Error?>();
+	public void clear_error_indicators (Vala.SourceFile? file = null) {
+		if (file == null) {
+			errors_list = new Vala.ArrayList<Error?>();
+			errors = 0;
+		} else {
+			for (var i = 0; i < errors_list.size; i++) {
+				if (errors_list[i].source.file == file) {
+					if (errors_list[i].error)
+						errors --;
+					else
+						warnings --;
+
+					errors_list.remove_at (i);
+					i --;
+				}
+			}
+			assert (errors_list.size <= errors + warnings);
+		}
+
 		foreach (var doc in docman.get_doc_widgets ()) {
 			if (doc is IAnjuta.Indicable)
 				((IAnjuta.Indicable)doc).clear ();
@@ -65,22 +84,25 @@ public class AnjutaReport : Vala.Report {
 		}
 	}
 	public override void warn (Vala.SourceReference? source, string message) {
+		warnings ++;
+
 		if (source == null)
 			return;
 
-		lock (errors) {
-			errors.add(Error () {source = source, message = message, error = false});
+		lock (errors_list) {
+			errors_list.add(Error () {source = source, message = message, error = false});
 		}
 	}
 	public override void err (Vala.SourceReference? source, string message) {
-		if (source == null)
+		errors ++;
+
+		if (source == null) {
+			general_error = true;
 			return;
+		}
 
-		lock (errors) {
-			errors.add(Error () {source = source, message = message, error = true});
+		lock (errors_list) {
+			errors_list.add(Error () {source = source, message = message, error = true});
 		}
 	}
-	public bool errors_found () {
-		return (errors.size != 0);
-	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]