Updated Makefile.am files after make -f git.mk
[anjuta.git] / plugins / language-support-vala / report.vala
blobad2f4f010cf4c7dfce0d8ca364a6b8b9b5405634
1 /*
2 * Copyright (C) 2008-2009 Abderrahim Kitouni
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 /* A Vala.Report subclass for reporting errors in Anjuta UI */
19 public class AnjutaReport : Vala.Report {
20 struct Error {
21 public Vala.SourceReference source;
22 public bool error;
23 public string message;
25 public IAnjuta.DocumentManager docman { get; set; }
26 Vala.List<Error?> errors_list = new Vala.ArrayList<Error?>();
27 bool general_error = false;
29 public void update_errors (IAnjuta.Editor editor) {
30 var ind = editor as IAnjuta.Indicable;
31 var mark = editor as IAnjuta.Markable;
32 if (ind == null && mark == null)
33 return;
35 if (ind != null)
36 ind.clear ();
37 if (mark != null)
38 mark.delete_all_markers (IAnjuta.MarkableMarker.MESSAGE);
40 foreach (var e in errors_list) {
41 if (e.source.file.filename.has_suffix (((IAnjuta.Document)editor).get_filename ())) {
42 if (ind != null) {
43 /* begin_iter should be one cell before to select the first character */
44 var begin_iter = editor.get_line_begin_position (e.source.begin.line);
45 for (var i = 1; i < e.source.begin.column; i++)
46 begin_iter.next ();
47 var end_iter = editor.get_line_begin_position (e.source.end.line);
48 for (var i = 0; i < e.source.end.column; i++)
49 end_iter.next ();
50 ind.set(begin_iter, end_iter, e.error ? IAnjuta.IndicableIndicator.CRITICAL :
51 IAnjuta.IndicableIndicator.WARNING);
53 if (editor is IAnjuta.Markable) {
54 mark.mark(e.source.begin.line, IAnjuta.MarkableMarker.MESSAGE, e.message);
60 public void clear_error_indicators (Vala.SourceFile? file = null) {
61 if (file == null) {
62 errors_list = new Vala.ArrayList<Error?>();
63 errors = 0;
64 } else {
65 for (var i = 0; i < errors_list.size; i++) {
66 if (errors_list[i].source.file == file) {
67 if (errors_list[i].error)
68 errors --;
69 else
70 warnings --;
72 errors_list.remove_at (i);
73 i --;
76 assert (errors_list.size <= errors + warnings);
79 foreach (var doc in docman.get_doc_widgets ()) {
80 if (doc is IAnjuta.Indicable)
81 ((IAnjuta.Indicable)doc).clear ();
82 if (doc is IAnjuta.Markable)
83 ((IAnjuta.Markable)doc).delete_all_markers (IAnjuta.MarkableMarker.MESSAGE);
86 public override void warn (Vala.SourceReference? source, string message) {
87 warnings ++;
89 if (source == null)
90 return;
92 lock (errors_list) {
93 errors_list.add(Error () {source = source, message = message, error = false});
96 public override void err (Vala.SourceReference? source, string message) {
97 errors ++;
99 if (source == null) {
100 general_error = true;
101 return;
104 lock (errors_list) {
105 errors_list.add(Error () {source = source, message = message, error = true});