Fix #7991 - better updateing of error status and char position of errors
[roobuilder] / src / Palete / CompileError.vala
1 /*
2
3 Object to handle compiler errors
4 so they can be passed off to trees.
5
6 There are a few things we do with diagnostics
7 a) the popup list with a tree of file => { errors} for each type
8 b) the syntax highlighting.
9
10
11
12
13 */
14
15 namespace Palete {
16
17         public class  CompileError : Object
18         {
19                 
20                 public JsRender.JsRender file = null;
21                 public string title = "";
22                 
23                 public GLib.ListStore lines { get; set ; }  // so it triggers updates?
24
25                 //public CompileError? parent = null;
26                 public string category = "";
27                 public string msg = "";
28                 public  int line { get; set; default = -1; }
29                 public Lsp.Diagnostic? diag = null;
30                 
31                 public CompileError.new_jserror(JsRender.JsRender file, string category, int line, string msg) 
32                 {
33                         this.lines = new GLib.ListStore(typeof(CompileError));
34                         this.line = line;
35                         this.msg = msg;
36                         this.file = file;
37                         this.category = category;
38
39                 
40                 }
41
42                 public CompileError.new_from_diagnostic(JsRender.JsRender file, Lsp.Diagnostic diag) 
43                 {
44                         this.file = file;
45                         this.category = diag.category;
46                         this.line = (int) diag.range.start.line;
47                         this.msg = diag.message;   
48                         this.lines = new GLib.ListStore(typeof(CompileError));
49                         this.diag = diag;
50                         //GLib.debug("new error %s : %d  %s %s", file.path, this.line, this.category, this.msg);
51                         
52                         
53                         
54                 }
55                 
56                 public CompileError.new_from_file(JsRender.JsRender file, string category) 
57                 {
58                         this.file = file;
59                         this.category = category;
60                         this.lines = new GLib.ListStore(typeof(CompileError));
61                         this.title =  file.relpath + " (" + lines.get_n_items().to_string() + ")";
62                 }
63  
64                 public string file_line { // sorting?
65                         set {}
66                         owned get { 
67                                 return this.line == -1 ? this.file.relpath : 
68                                         (this.file.relpath + ":" + this.line.to_string("%09d")); 
69                         }
70                 }
71                 public string linemsg {
72                         set {}
73                         owned  get {
74                                 return this.line == -1 ? 
75                                          GLib.Markup.escape_text( this.file.relpath + "(" +  this.lines.n_items.to_string() + ")") :                    
76                                          GLib.Markup.escape_text(this.line.to_string() + ": " + this.msg);
77                         }
78                 }
79                 
80                 public bool hasErrors() {
81                         return this.lines.get_n_items() > 0;
82                 }
83                  
84          
85                 
86         }
87         
88 }