fix missing ref on property objects, and skip _ as a suggestion
[roobuilder] / src / Lsp.vala
index 7288f72..6bc7166 100644 (file)
@@ -83,7 +83,10 @@ namespace Lsp {
                  (character > other.character ? 1 :
                   (character == other.character ? 0 : -1)) : -1);
         }
-
+        public bool equals(Position o) {
+               return o.line == this.line && o.character == this.character;
+       }
+               
         public string to_string () {
             return @"$line:$character";
         }
@@ -106,6 +109,16 @@ namespace Lsp {
     }
 
     public class Range : Object, Gee.Hashable<Range>, Gee.Comparable<Range> {
+        
+        public Range.simple(uint line, uint pos) {
+               var p =  new Position () {
+                line = line,
+                character = pos
+            };
+               this.start = p;
+               this.end = p;
+               
+        }
         /**
          * The range's start position.
          */
@@ -138,7 +151,7 @@ namespace Lsp {
 
         public bool equal_to (Range other) { return this.to_string () == other.to_string (); }
                public bool equals (Range o) {
-                       return this.filename == o.filename && this.start == o.start && this.end == o.end;
+                       return this.filename == o.filename && this.start.equals(o.start) && this.end.equals(o.end);
                }
 
         public int compare_to (Range other) {
@@ -165,6 +178,16 @@ namespace Lsp {
     }
 
     public class Diagnostic : Object {
+        
+        public Diagnostic.simple ( int line, int character, string message)
+        {
+               this.message = message;
+               this.severity = DiagnosticSeverity.Error;
+               this.range =  new Range.simple(line, character );
+               
+               
+        
+        }
         /**
          * The range at which the message applies.
          */
@@ -209,9 +232,17 @@ namespace Lsp {
                
         }
         public bool equals(Lsp.Diagnostic o) {
-               return this.range.equals(o.range) && this.severity == o.severity && this.message == o.message;
+                       var ret = this.range.equals(o.range) && this.severity == o.severity && this.message == o.message;
+               //GLib.debug("compare %s  (%s == %s)", ret ? "YES" : "NO", this.to_string(), o.to_string()); 
+               
+               
+               return ret;
+        }
+        public string to_string()
+        {
+               return "%s : %d - %s".printf(this.category, (int) this.range.start.line , this.message);
         }
+        
     }
 
     /**
@@ -338,7 +369,7 @@ namespace Lsp {
                 // debug ("subroutine %s found (body @ %s)", sym.get_full_name (),
                 //         body_sref != null ? body_sref.to_string () : null);
                 if (body_sref != null && (body_sref.begin.line < body_sref.end.line ||
-                                          body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
+                                val = GLib.Value (typeof(Gee.ArrayList));                          body_sref.begin.line == body_sref.end.line && body_sref.begin.pos <= body_sref.end.pos)) {
                     this._initial_range = this._initial_range.union (new Range.from_sourceref (body_sref));
                 }
             }
@@ -380,7 +411,7 @@ namespace Lsp {
                if (property_name != "children") {
                    return default_deserialize_property (property_name, out value, pspec, property_node);
                }
-               value = GLib.Value (GLib.Type.BOXED);
+            value = GLib.Value (typeof(Gee.ArrayList));
                if (property_node.get_node_type () != Json.NodeType.ARRAY) {
                    warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
                    return false;
@@ -396,7 +427,7 @@ namespace Lsp {
                   
                });
 
-               value.set_boxed (arguments);
+               value.set_object (arguments);
                return true;
           }
     }
@@ -665,7 +696,7 @@ namespace Lsp {
                if (property_name != "tags") {
                 return default_deserialize_property (property_name, out value, pspec, property_node);
             }
-            value = GLib.Value (GLib.Type.BOXED);
+            value = GLib.Value (typeof(Gee.ArrayList));
             if (property_node.get_node_type () != Json.NodeType.ARRAY) {
                 warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
                 return false;
@@ -681,7 +712,7 @@ namespace Lsp {
                 }
             });
 
-            value.set_boxed (arguments);
+            value.set_object (arguments);
             return true;
        }
     }
@@ -971,7 +1002,7 @@ namespace Lsp {
         public bool deserialize_property (string property_name, out GLib.Value value, GLib.ParamSpec pspec, Json.Node property_node) 
         {
             if (property_name == "arguments") {
-                value = GLib.Value (GLib.Type.BOXED);
+                value = GLib.Value (typeof(Array));
                 if (property_node.get_node_type () != Json.NodeType.ARRAY) {
                     warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
                     return false;
@@ -1090,6 +1121,13 @@ namespace Lsp {
 
        public class Diagnostics : Object, Json.Serializable 
        {
+               public Diagnostics()
+               {
+                       this.diagnostics = new Gee.ArrayList<Diagnostic>((a,b) => {
+                               return a.equals(b);
+                       });
+               }
+               
                public string uri { get; set; }
 
                public int version  { get; set; default = 0; }
@@ -1104,9 +1142,12 @@ namespace Lsp {
                
                public bool deserialize_property (string property_name, out GLib.Value val, GLib.ParamSpec pspec, Json.Node property_node) {
                        if (property_name == "diagnostics") {
-                               var diags =  new Gee.ArrayList<Diagnostic> ();
+                val = GLib.Value (typeof(Gee.ArrayList));
+                               var diags =  new Gee.ArrayList<Diagnostic> ((a,b) => {
+                                       return a.equals(b);
+                               });
                                if (property_node.get_node_type () != Json.NodeType.ARRAY) {
-                                       val = diags;
+                                       val.set_object(diags);
                                        warning ("unexpected property node type for 'arguments' %s", property_node.get_node_type ().to_string ());
                                        return false;
                                }
@@ -1120,7 +1161,7 @@ namespace Lsp {
                                                //warning ("argument %u to command could not be deserialized: %s", index, e.message);
                                         
                                });
-                               val = diags;
+                               val.set_object(diags);
                                 
                                return true;
                        }