fix #7968 - language server support for syntax check and completion
[roobuilder] / src / JsRender / Roo.vala
index 6633b1a..582984d 100644 (file)
@@ -18,13 +18,15 @@ namespace JsRender {
    
     class Roo : JsRender 
     {
-        string region;
+         
         bool disabled;
 
  
         
-        public Roo(Project.Project project, string path) {
-            aconstruct( project, path);
+        public Roo(Project.Roo project, string path) 
+        {
+            base( project, path);
             this.xtype = "Roo";
              this.language = "js";
             
@@ -113,7 +115,9 @@ namespace JsRender {
                        this.permname = this.jsonHasOrEmpty(obj, "permname");
                        this.title = this.jsonHasOrEmpty(obj, "title");
                        this.modOrder = this.jsonHasOrEmpty(obj, "modOrder");
-
+                       if (obj.has_member("gen_extended")) { // should check type really..
+                               this.gen_extended = obj.get_boolean_member("gen_extended");
+                       }
                        var bjs_version_str = this.jsonHasOrEmpty(obj, "bjs-version");
                        bjs_version_str = bjs_version_str == "" ? "1" : bjs_version_str;
 
@@ -136,60 +140,72 @@ namespace JsRender {
             
         }
         
-        
-       public  override  void save()
-       {
-            
-               GLib.debug("--- JsRender.Roo.save");
-               GLib.debug("save() - reset transStrings\n");
-               this.transStrings = new Gee.HashMap<string,string>();
-               this.namedStrings = new Gee.HashMap<string,string>();
-               this.findTransStrings(this.tree);
-               
-               this.saveBJS();
-
-               // no tree..
-               if (this.tree == null) {
-                       return;
+               public override string targetName()
+               {
+                       string js;
+                       try {
+                               Regex regex = new Regex("\\.(bjs|js)$");
+
+                               js = regex.replace(this.path,this.path.length , 0 , ".js");
+                               return js;
+                       } catch (RegexError e) {
+                               this.name = "???";
+                               print("count not make filename from path");
+                               return this.name + ".js";
+                       }
+                       
                }
-               // now write the js file..
-               string js;
-               try {
-                       Regex regex = new Regex("\\.(bjs|js)$");
+               public  override  void save()
+               {
+                       
+                       GLib.debug("--- JsRender.Roo.save");
+                       GLib.debug("save() - reset transStrings\n");
+                       this.transStrings = new Gee.HashMap<string,string>();
+                       this.namedStrings = new Gee.HashMap<string,string>();
+                       this.findTransStrings(this.tree);
+                       
+                       this.saveBJS();
 
-                       js = regex.replace(this.path,this.path.length , 0 , ".js");
-               } catch (RegexError e) {
-                       this.name = "???";
-                       print("count not make filename from path");
-                       return;
-               }
+                       // no tree..
+                       if (this.tree == null) {
+                               return;
+                       }
+                       // now write the js file..
+                       var  js = this.targetName();
+                        
 
 
-               //var d = new Date();
-               var js_src = this.toSource();            
-               //print("TO SOURCE in " + ((new Date()) - d) + "ms");
-               try {
-                       this.writeFile(js, js_src);            
-               } catch (FileError e ) {
-                       print("Save failed\n");
+                       //var d = new Date();
+                       var js_src = this.toSource();            
+                       //print("TO SOURCE in " + ((new Date()) - d) + "ms");
+                       try {
+                               this.writeFile(js, js_src);            
+                       } catch (GLib.Error e ) {
+                               print("Save failed\n");
+                       }
+                       // for bootstrap - we can write the HTML to the templates directory..
+                                
+                       //var top = this.guessName(this.items[0]);
+                       //print ("TOP = " + top)
+                        
+                       
+                       
+                       
                }
-               // for bootstrap - we can write the HTML to the templates directory..
-                
-            //var top = this.guessName(this.items[0]);
-            //print ("TOP = " + top)
-             
-            
-            
-            
-       }
 
-        
+        public Project.Roo roo_project {
+               set {}  
+               get { 
+                       return (Project.Roo) this.project;
+               }
+       }
+                       
 
         
        public override void saveHTML ( string html )
        {
-               GLib.debug ("SAVEHTML %s\n",  this.project.runhtml);             
-               if (this.project.runhtml == "") {
+               GLib.debug ("SAVEHTML %s\n",  this.roo_project.runhtml);                 
+               if (this.roo_project.runhtml == "") {
                        return;
                }
                 
@@ -227,7 +243,7 @@ namespace JsRender {
           print("SAVE HTML (%d) -- %s\n",html.length, targetdir + "/" +  bn);
                try {
                        this.writeFile(targetdir + "/" +  bn , html);            
-               } catch (FileError e ) {
+               } catch (GLib.Error e ) {
                        print("SaveHtml failed\n");
                }
             
@@ -241,8 +257,9 @@ namespace JsRender {
                        if (node.props.has_key("* xinclude")) {
                                ret.add(node.props.get("* xinclude").val);
                        }
-                       for (var i =0; i < node.items.size; i++) {
-                               this.findxincludes(node.items.get(i), ret);
+                       var items = node.readItems();
+                       for (var i =0; i < items.size; i++) {
+                               this.findxincludes(items.get(i), ret);
                        }
                        return ret;
                                
@@ -296,7 +313,7 @@ namespace JsRender {
                                var chksum = GLib.Checksum.compute_for_string (ChecksumType.MD5, str.strip());
                                
                                if (this.doubleStringProps.index_of(kname) > -1) {
-                                       GLib.debug("flag=%s type=%s name=%s : %s\n", prop.ptype.to_string(),ktype,kname,str);
+                                       //GLib.debug("flag=%s type=%s name=%s : %s\n", prop.ptype.to_string(),ktype,kname,str);
                                        this.transStrings.set(str,  chksum);
                                        named.set("_" + kname, chksum);
                                        continue;
@@ -317,10 +334,10 @@ namespace JsRender {
                                }
                         }
 
-                       
+                       var items = node.readItems();
                        // iterate children..
-                       for (var i =0; i < node.items.size; i++) {
-                               this.findTransStrings(node.items.get(i) );
+                       for (var i =0; i < items.size; i++) {
+                               this.findTransStrings(items.get(i) );
                        }
                
                                
@@ -389,19 +406,20 @@ namespace JsRender {
                        if (xinc.size > 0 ) {
                                for(var i = 0; i < xinc.size; i++) {
                                        print("check xinclude:  %s\n", xinc.get(i));
-                                       var sf = this.project.getByName(xinc.get(i));
+                                       var sf = this.project.getByRelPath(xinc.get(i));
                                        if (sf == null) {
                                                print("Failed to find file by name?\n");
                                                continue;
                                        }
-
-                                       sf.loadItems();
-                                       sf.findTransStrings(sf.tree);
-                                       var xinc_str = sf.toSource();
-                                       
-                                       //string xinc_str;
-                                       //FileUtils.get_contents(js, out xinc_str);
-                                       prefix_data += "\n" + xinc_str + "\n";
+                                       try {
+                                               sf.loadItems();
+                                               sf.findTransStrings(sf.tree);
+                                               var xinc_str = sf.toSource();
+                                               
+                                               //string xinc_str;
+                                               //FileUtils.get_contents(js, out xinc_str);
+                                               prefix_data += "\n" + xinc_str + "\n";
+                                       } catch (GLib.Error e) {}
                                        
                                }
 
@@ -776,50 +794,15 @@ namespace JsRender {
               
         }
             
-        public new string? guessName (Node? ar) // turns the object into full name.
-        {
-             // eg. xns: Roo, xtype: XXX -> Roo.xxx
-            if (ar == null) {
-                return null;
-            }
-            
-            string[] ret = {} ;
-            ret += (ar.get("|xns").length < 1 ? "Roo": ar.get("|xns"));
-             
-            
-            if ( ar.get("xtype").length < 1) {
-                return null;
-            }
-                    
-            var xtype = ar.get("xtype");
-
-            if (xtype[0] == '*') { // prefixes????
-                xtype  = xtype.substring(1);
-            }
-            if (! Regex.match_simple("^Roo", xtype)) {
-                
-                // already starts with roo...
-                ret = {};
-            }
-            ret += xtype;
-            var str =  string.joinv(".", ret);
-            
-            return str;
-           // 
-            //Palete.Palete.factory("Roo").guessName(str);
-            
-                            
-                                 
-        }
         
-        string getHelpUrl(string cls)
-        {
-            return "http://www.roojs.com/roojs1/docs/symbols/" + cls + ".html";
-        }
                 public override string toGlade() 
                {
                        return "Roo files do not convert to glade";
                }
+               public   override string language_id() 
+               {
+                       return "javascript";
+               }
      
     }
 }