fix #7968 - language server support for syntax check and completion
[roobuilder] / src / Palete / Roo.vala
index 04ecd5d..e0b9131 100644 (file)
@@ -23,8 +23,9 @@ namespace Palete {
     public class Roo : Palete {
                
                Gee.ArrayList<string> top_classes;
-               
-               
+               public static Gee.HashMap<string,GirObject>? classes_cache = null;
+               public static Gee.ArrayList<string>? top_classes_cache = null;
         public Roo(Project.Project project)
         {
 
@@ -33,6 +34,10 @@ namespace Palete {
             aconstruct(project);
             this.name = "Roo";
                        this.top_classes =  new Gee.ArrayList<string>();
+                       
+                       this.load(); // ? initialize the roodata?
+
         }
 
                Gee.HashMap<string,GirObject> propsFromJSONArray(string type, Json.Array ar, GirObject cls)
@@ -76,12 +81,23 @@ namespace Palete {
                        if (this.classes != null) {
                                return;
                        }
+                       if (Roo.classes_cache != null) {
+                               this.classes = Roo.classes_cache;
+                               this.top_classes = Roo.top_classes_cache ;
+                               return;
+                       }
+                       
+                       
                        // this.loadUsageFile(BuilderApplication.configDirectory() + "/resources/RooUsage.txt");
                        this.classes = new Gee.HashMap<string,GirObject>();
                        var add_to =  new Gee.HashMap<string,Gee.ArrayList<string>>();
                                
                        var pa = new Json.Parser();
-                       pa.load_from_file(BuilderApplication.configDirectory() + "/resources/roodata.json");
+                       try { 
+                               pa.load_from_file(BuilderApplication.configDirectory() + "/resources/roodata.json");
+                       } catch(GLib.Error e) {
+                               GLib.error("Could not load %s",BuilderApplication.configDirectory() + "/resources/roodata.json");
+                       }
                        var node = pa.get_root();
 
                        var clist =  node.get_object(); /// was in data... .get_object_member("data");
@@ -189,7 +205,8 @@ namespace Palete {
                                        cls.can_drop_onto = add_to.get(cls.name);
                                }
                        }
-                                
+                       Roo.classes_cache = this.classes;
+                       Roo.top_classes_cache  = this.top_classes;
                }
                  
                        
@@ -215,6 +232,8 @@ namespace Palete {
                        
                }
                
+                
+               
                public override Gee.HashMap<string,GirObject> getPropertiesFor(string ename, JsRender.NodePropType ptype)
                {
                        //print("Loading for " + ename);
@@ -248,7 +267,7 @@ namespace Palete {
                                
                                
                                case JsRender.NodePropType.PROP:
-                                       return cls.props;
+                                       return  this.filterProps(cls.props);
                                case JsRender.NodePropType.LISTENER:
                                        return cls.signals;
                                case JsRender.NodePropType.METHOD:
@@ -256,7 +275,7 @@ namespace Palete {
                                case JsRender.NodePropType.CTOR:
                                        return ret;
                                default:
-                                       throw new Error.INVALID_VALUE( "getPropertiesFor called with: " + ptype.to_string());
+                                       GLib.error( "getPropertiesFor called with: " + ptype.to_string()); 
                                        //var ret = new Gee.HashMap<string,GirObject>();
                                        //return ret;
                        
@@ -268,6 +287,45 @@ namespace Palete {
 
                         
                }
+               
+               // removes all the properties where the type contains '.' ?? << disabled now..
+               
+               public Gee.HashMap<string,GirObject>  filterProps(Gee.HashMap<string,GirObject> props)
+               {
+                       // we shold probably cache this??
+                       
+                       var outprops = new Gee.HashMap<string,GirObject>(); 
+                       
+                       foreach(var k in props.keys) {
+                               var val = props.get(k);
+                               
+                               // special props..
+                               switch(k) {
+                                       case "listeners" : 
+                                               continue;
+                                       default:
+                                               break;
+                               }
+                               
+                                
+                                //if (!val.type.contains(".")) {
+                                       outprops.set(k,val);
+                                       continue;
+                                //}
+                               
+                               
+                                
+                               // do nothing? - classes not allowed?
+                               
+                       }
+                       
+                       
+                       return outprops;
+               
+               
+               }
+               
+               
                public string[] getInheritsFor(string ename)
                {
                        string[] ret = {};
@@ -283,12 +341,7 @@ namespace Palete {
 
                }
 
-
-               public override void fillPack(JsRender.Node node,JsRender.Node parent)
-               {   
-
-                        return;
-               }
                /*
                 *  Pulldown options for type
                 */
@@ -320,14 +373,16 @@ namespace Palete {
                         return true;
                         
                }
-               public override  List<SourceCompletionItem> suggestComplete(
+               public override  Gee.ArrayList<CompletionProposal> suggestComplete(
                                JsRender.JsRender file,
                                JsRender.Node? node,
                                JsRender.NodeProp? xxprop,
                                string complete_string
                ) { 
                        
-                       var ret =  new List<SourceCompletionItem>();
+                       var ret =  new Gee.ArrayList<CompletionProposal>();
+                       return ret;
+                       /*
                        // completion rules??
                        
                        // Roo......
@@ -340,17 +395,28 @@ namespace Palete {
                                // offer up this / Roo / javascript keywords... / look for var string = .. in the code..
                                for(var i = 0; i <  JsRender.Lang.match_strings.size ; i++) {
                                        var str = JsRender.Lang.match_strings.get(i);
-                                       if (complete_string != str && str.index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
-                                               ret.append(new SourceCompletionItem (str, str, null, "javascript : " + str));
+                                       if (complete_string != str && str.index_of(complete_string,0) == 0 ) { 
+                                               // should we ignore exact matches... ???tr,str,
+                                               var sci = new CompletionProposal(str,str, "javascript: " + str);
+                                               ret.add(sci);
+                                                
                                        }
                                        
                                        
                                }
-                               if (complete_string != "Roo" && "Roo".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
-                                       ret.append(new SourceCompletionItem ("Roo - A Roo class", "Roo", null, "Roo library"));
+                               if (complete_string != "Roo" && "Roo".index_of(complete_string,0) == 0 ) { 
+                                       // should we ignore exact matches... ???
+                               
+                                       var sci = new CompletionProposal("Roo - A Roo class","Roo", "Roo Library");
+                                       ret.add(sci);
+                                
                                }
-                               if (complete_string != "_this" && "_this".index_of(complete_string,0) == 0 ) { // should we ignore exact matches... ???
-                                       ret.append(new SourceCompletionItem ("_this - the top level element", "_this", null, "Top level element"));
+                               if (complete_string != "_this" && "_this".index_of(complete_string,0) == 0 ) { 
+                                       // should we ignore exact matches... ???
+                                       var sci = new CompletionProposal("_this - Reference to the global pointer to the files main class instance",
+                                               "_this", "Reference to the global pointer to the files main class instance");
+                                       ret.add(sci);
+                                        
                                }
                                return ret;
                        }
@@ -443,12 +509,10 @@ namespace Palete {
                                                if (parts[i].length > 0 && scls.index_of(look,0) != 0) {
                                                        continue;
                                                }
+                                               
                                                // got a starting match..
-                                               ret.append(new SourceCompletionItem (
-                                                       scls,
-                                                       scls, 
-                                                       null, 
-                                                       scls));
+                                               var sci = new CompletionProposal(scls,scls,scls);
+                                               ret.add(sci);
                                        }
                                        return ret;
                                }
@@ -465,11 +529,12 @@ namespace Palete {
                                        }
                                        // got a matching property...
                                        // return type?
-                                       ret.append(new SourceCompletionItem (
-                                                        prop.name + prop.sig + " :  ("+ prop.propertyof + ")", 
-                                                       prevbits + prop.name + "(", 
-                                                       null, 
-                                                       prop.doctxt));
+                                       
+                                       
+                                       var sci = new CompletionProposal(prop.name + prop.sig + " :  ("+ prop.propertyof + ")",
+                                               prevbits + prop.name + "(",prop.doctxt);
+                                       ret.add(sci);
+                                        
                                }
                                
                                // get the properties / methods and subclasses.. of cls..
@@ -481,13 +546,11 @@ namespace Palete {
                                        if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
                                                continue;
                                        }
-                                       // got a matching property...
-                                       
-                                       ret.append(new SourceCompletionItem (
-                                                        prop.name + " : " + prop.type + " ("+ prop.propertyof + ")", 
-                                                       prevbits + prop.name, 
-                                                       null, 
-                                                       prop.doctxt));
+                                       // got a matching property..
+                                       var sci = new CompletionProposal(prop.name + prop.type + " :  ("+ prop.propertyof + ")",
+                                               prevbits + prop.name + "(",prop.doctxt);
+                                       ret.add(sci);
+                               
                                }
                                         
                                        
@@ -505,15 +568,18 @@ namespace Palete {
                        
                        
                        return ret;
+                       */
                }
-               public override string[] getChildList(string in_rval)
+               
+               
+               public override Gee.ArrayList<string> getChildList(string in_rval, bool with_prop)
         {
                if (this.top_classes.size < 1) {
                        this.load();
                }
-               
-               
-               string[] ret = {};
+                
+                
+                
                var ar = this.top_classes;
                if (in_rval != "*top") {
                        if (this.classes.has_key(in_rval)) {
@@ -524,20 +590,35 @@ namespace Palete {
                        }
                }
                
-               foreach(var str in ar) {
-                       ret += str;
-               } 
-               GLib.debug("getChildList for %s returns %s", in_rval, string.joinv(", ", ret));
-               return ret;     
+               if (!with_prop) {
+                       var ret = new Gee.ArrayList<string>();
+                       foreach(var v in ar) {
+                               if (v.contains(":")) {
+                                       continue;
+                               }
+                               ret.add(v);
+                       }
+                       return ret;
+               }
+                
+               GLib.debug("getChildList for %s returns %d items",  in_rval, ar.size);
+               return ar;      
                
                //return this.original_getChildList(  in_rval);
        }
-               public override string[] getDropList(string rval)
+       
+
+       
+               public override Gee.ArrayList<string> getDropList(string rval)
                {
+                       
+                       if (this.dropCache.has_key(rval)) {
+                               return this.dropCache.get(rval);
+                       }
                        // we might be dragging  Roo.bootstrap.layout.Region:center
                        // in which case we need to lookup Roo.bootstrap.layout.Region
                        // and see if it's has can_drop_onto
-                       string[] ret = {};
+                       var  ret = new Gee.ArrayList<string>();
                        var cls = this.classes.get(rval);
                        // cls can be null.
                        if (cls == null && rval.contains(":")) {
@@ -551,15 +632,33 @@ namespace Palete {
                        
                        foreach(var str in cls.can_drop_onto) {
 
-                               ret += str;
+                               ret.add(str);
                        }
-                       GLib.debug("getDropList for %s return[] %s", rval, string.joinv(", ", ret));
+                       //GLib.debug("getDropList for %s return[] %s", rval, string.joinv(", ", ret));
+                       this.dropCache.set(rval,ret);
                        return ret;
                                
                        
                        
                        //return this.default_getDropList(rval);
                }       
+               public override JsRender.Node fqnToNode(string fqn) 
+               {
+                       var ret = new JsRender.Node();
+                       ret.setFqn(fqn);
+                       // any default requred proerties?
+                       
+                       return ret;
+                       
+                       
+                       
+               }
+               
     }
+    
+    
+               
+               
+    
 }