Fix #8028 - language server performance, fix warnings and critical errors
[roobuilder] / src / Builder4 / GtkView.vala
index d7a1ee9..c3f9c0e 100644 (file)
@@ -31,11 +31,10 @@ public class Xcls_GtkView : Object
 
                // my vars (def)
        public Gtk.Widget lastObj;
-       public Gtk.CssProvider css;
        public Xcls_MainWindow main_window;
-       public GtkSource.SearchContext searchcontext;
        public int last_error_counter;
        public int last_search_end;
+       public GtkSource.SearchContext searchcontext;
        public JsRender.JsRender file;
 
        // ctor
@@ -55,25 +54,6 @@ public class Xcls_GtkView : Object
                this.el.vexpand = true;
                new Xcls_notebook( _this );
                this.el.append( _this.notebook.el );
-
-               // init method
-
-               {
-               
-                       this.css = new Gtk.CssProvider();
-                        
-                       this.css.load_from_string(
-                               "#gtkview-view-layout { background-color: #ccc; }"
-                       );
-                        
-                       Gtk.StyleContext.add_provider_for_display(
-                               this.el.get_display(),
-                               this.css,
-                               Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
-                       );
-                               
-                       
-               }
        }
 
        // user defined functions
@@ -331,7 +311,7 @@ public class Xcls_GtkView : Object
        
        
         
-               GLib.debug("highlight errors");          
+               //GLib.debug("highlight errors");                
        
                 // we should highlight other types of errors..
        
@@ -345,9 +325,14 @@ public class Xcls_GtkView : Object
                }
                var ar = this.file.getErrors();
                if (ar.size < 1) {
-                       buf.remove_source_marks (start, end, null);
+                       buf.remove_tag_by_name ("ERR", start, end);
+                       buf.remove_tag_by_name ("WARN", start, end);
+                       buf.remove_tag_by_name ("DEPR", start, end);
+                       buf.remove_source_marks (start, end, "ERR");
+                       buf.remove_source_marks (start, end, "WARN");
+                       buf.remove_source_marks (start, end, "DEPR");
                        this.last_error_counter = file.error_counter ;
-                       GLib.debug("higjlight has no errors");
+                       //GLib.debug("higjlight has no errors");
                        return;
                }
                if (this.last_error_counter == file.error_counter) {
@@ -362,14 +347,19 @@ public class Xcls_GtkView : Object
                
         
                 
-               buf.remove_source_marks (start, end, null);
+               buf.remove_source_marks (start, end, "ERR");
+               buf.remove_source_marks (start, end, "WARN");
+               buf.remove_source_marks (start, end, "DEPR");
+               buf.remove_tag_by_name ("ERR", start, end);
+               buf.remove_tag_by_name ("WARN", start, end);
+               buf.remove_tag_by_name ("DEPR", start, end);
                foreach(var diag in ar) { 
                
                        
                     Gtk.TextIter iter;
        //        print("get inter\n");
                    var eline = (int)diag.range.start.line ;
-                   
+                   var eline_to = (int)diag.range.end.line;
                    if (eline > tlines || eline < 0) {
                        return;
                    }
@@ -377,6 +367,12 @@ public class Xcls_GtkView : Object
                    
                    buf.get_iter_at_line( out iter, eline);
                   
+                        buf.get_iter_at_line_offset( out start, 
+                       eline, (int)diag.range.start.character); 
+                   buf.get_iter_at_line_offset( out end, 
+                       eline_to, (int)diag.range.end.character); 
+                       
+                   buf.apply_tag_by_name(diag.category, start, end);
                   
                   
                        var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
@@ -433,10 +429,10 @@ public class Xcls_GtkView : Object
                        this.el.overflow = Gtk.Overflow.VISIBLE;
                        new Xcls_label_preview( _this );
                        new Xcls_label_code( _this );
-                       var child_3 = new Xcls_ScrolledWindow5( _this );
+                       var child_3 = new Xcls_ScrolledWindow4( _this );
                        child_3.ref();
                        this.el.append_page ( child_3.el , _this.label_preview.el );
-                       var child_4 = new Xcls_Box8( _this );
+                       var child_4 = new Xcls_Box7( _this );
                        child_4.ref();
                        this.el.append_page ( child_4.el , _this.label_code.el );
                }
@@ -489,7 +485,7 @@ public class Xcls_GtkView : Object
                // user defined functions
        }
 
-       public class Xcls_ScrolledWindow5 : Object
+       public class Xcls_ScrolledWindow4 : Object
        {
                public Gtk.ScrolledWindow el;
                private Xcls_GtkView  _this;
@@ -498,7 +494,7 @@ public class Xcls_GtkView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
+               public Xcls_ScrolledWindow4(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.ScrolledWindow();
@@ -562,7 +558,7 @@ public class Xcls_GtkView : Object
 
 
 
-       public class Xcls_Box8 : Object
+       public class Xcls_Box7 : Object
        {
                public Gtk.Box el;
                private Xcls_GtkView  _this;
@@ -571,7 +567,7 @@ public class Xcls_GtkView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Box8(Xcls_GtkView _owner )
+               public Xcls_Box7(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
@@ -581,7 +577,7 @@ public class Xcls_GtkView : Object
                        // set gobject values
                        new Xcls_sourceviewscroll( _this );
                        this.el.append( _this.sourceviewscroll.el );
-                       var child_2 = new Xcls_Box13( _this );
+                       var child_2 = new Xcls_Box12( _this );
                        child_2.ref();
                        this.el.append( child_2.el );
                }
@@ -621,9 +617,7 @@ public class Xcls_GtkView : Object
 
                        // my vars (def)
                public bool loading;
-               public bool zallow_node_scroll;
                public string prop_selected;
-               public Gtk.CssProvider css;
                public JsRender.Node? node_selected;
 
                // ctor
@@ -635,7 +629,6 @@ public class Xcls_GtkView : Object
 
                        // my vars (dec)
                        this.loading = false;
-                       this.zallow_node_scroll = true;
                        this.prop_selected = "";
 
                        // set gobject values
@@ -643,86 +636,66 @@ public class Xcls_GtkView : Object
                        this.el.editable = false;
                        this.el.show_line_marks = true;
                        this.el.show_line_numbers = true;
+                       this.el.css_classes = { "code-editor" };
                        this.el.tab_width = 4;
                        new Xcls_buffer( _this );
                        this.el.set_buffer ( _this.buffer.el  );
-                       var child_2 = new Xcls_EventControllerKey12( _this );
+                       var child_2 = new Xcls_EventControllerKey11( _this );
                        child_2.ref();
                        this.el.add_controller(  child_2.el );
 
                        // init method
 
                        {
-                          
-                          
-                               this.css = new Gtk.CssProvider();
-                                
-                               this.css.load_from_string("#gtkview-view { font: 10px monospace ;}");
-                                
-                               Gtk.StyleContext.add_provider_for_display(
-                                       this.el.get_display(),
-                                       this.css,
-                                       Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
-                               );
-                                       
-                                        
-                           this.loading = true;
-                           
-                         
+                       
                          
-                           var attrs = new GtkSource.MarkAttributes();
-                           var  pink =   Gdk.RGBA();
-                           pink.parse ( "pink");
-                           attrs.set_background ( pink);
-                           attrs.set_icon_name ( "process-stop");    
-                           attrs.query_tooltip_text.connect(( mark) => {
-                               //print("tooltip query? %s\n", mark.name);
-                               return mark.name;
-                           });
-                           
-                           this.el.set_mark_attributes ("ERR", attrs, 1);
-                           
-                            var wattrs = new GtkSource.MarkAttributes();
-                           var  blue =   Gdk.RGBA();
-                           blue.parse ( "#ABF4EB");
-                           wattrs.set_background ( blue);
-                           wattrs.set_icon_name ( "process-stop");    
-                           wattrs.query_tooltip_text.connect(( mark) => {
-                               //print("tooltip query? %s\n", mark.name);
-                               return mark.name;
-                           });
-                           
-                           this.el.set_mark_attributes ("WARN", wattrs, 1);
-                           
-                        
-                           
-                            var dattrs = new GtkSource.MarkAttributes();
-                           var  purple =   Gdk.RGBA();
-                           purple.parse ( "#EEA9FF");
-                           dattrs.set_background ( purple);
-                           dattrs.set_icon_name ( "process-stop");    
-                           dattrs.query_tooltip_text.connect(( mark) => {
-                               //print("tooltip query? %s\n", mark.name);
-                               return mark.name;
-                           });
-                           
-                           this.el.set_mark_attributes ("DEPR", dattrs, 1);
-                           
-                           
-                           var gattrs = new GtkSource.MarkAttributes();
-                           var  grey =   Gdk.RGBA();
-                           grey.parse ( "#ccc");
-                           gattrs.set_background ( grey);
+                               this.loading = true;
+                       
                         
-                           
-                           this.el.set_mark_attributes ("grey", gattrs, 1);
-                           
-                           
-                           
-                           
-                           
-                           
-                       }
+                               var attrs = new GtkSource.MarkAttributes();
+                                attrs.set_icon_name ( "process-stop");    
+                               attrs.query_tooltip_text.connect(( mark) => {
+                                       //print("tooltip query? %s\n", mark.name);
+                                       return mark.name;
+                               });
+                       
+                               this.el.set_mark_attributes ("ERR", attrs, 1);
+                       
+                                var wattrs = new GtkSource.MarkAttributes();
+                                 wattrs.set_icon_name ( "process-stop");    
+                               wattrs.query_tooltip_text.connect(( mark) => {
+                                       //print("tooltip query? %s\n", mark.name);
+                                       return mark.name;
+                               });
+                       
+                               this.el.set_mark_attributes ("WARN", wattrs, 1);
+                       
+                       
+                       
+                                var dattrs = new GtkSource.MarkAttributes();
+                               dattrs.set_icon_name ( "process-stop");    
+                               dattrs.query_tooltip_text.connect(( mark) => {
+                                       //print("tooltip query? %s\n", mark.name);
+                                       return mark.name;
+                               });
+                       
+                               this.el.set_mark_attributes ("DEPR", dattrs, 1);
+                       
+                       
+                               var gattrs = new GtkSource.MarkAttributes();
+                               var  grey =   Gdk.RGBA();
+                               grey.parse ( "#ccc");
+                               gattrs.set_background ( grey);
+                       
+                       
+                               this.el.set_mark_attributes ("grey", gattrs, 1);
+                       
+                       
+                       
+                       
+                       
+                       
+                               }
 
                        //listeners
                        this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
@@ -764,7 +737,7 @@ public class Xcls_GtkView : Object
                    this.loading = true;
                    var buf = this.el.get_buffer();
                    buf.set_text("",0);
-                   var sbuf = (GtkSource.Buffer) buf;
+                
                        var cpos = buf.cursor_position;
                    
                        print("BEFORE LOAD cursor = %d\n", cpos);
@@ -928,6 +901,23 @@ public class Xcls_GtkView : Object
 
                        // set gobject values
 
+                       // init method
+
+                       var buf = this.el;
+                       buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
+                       buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
+                       buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
+                       buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
+                       buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
+                       buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
+                       buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
+                       buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
+                       
+                       
+                       buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
+                       buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
+                       buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
+
                        //listeners
                        this.el.cursor_moved.connect( ( ) => {
                        GLib.debug("cursor moved called");
@@ -963,7 +953,7 @@ public class Xcls_GtkView : Object
                // user defined functions
        }
 
-       public class Xcls_EventControllerKey12 : Object
+       public class Xcls_EventControllerKey11 : Object
        {
                public Gtk.EventControllerKey el;
                private Xcls_GtkView  _this;
@@ -972,7 +962,7 @@ public class Xcls_GtkView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_EventControllerKey12(Xcls_GtkView _owner )
+               public Xcls_EventControllerKey11(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.EventControllerKey();
@@ -1006,7 +996,7 @@ public class Xcls_GtkView : Object
 
 
 
-       public class Xcls_Box13 : Object
+       public class Xcls_Box12 : Object
        {
                public Gtk.Box el;
                private Xcls_GtkView  _this;
@@ -1015,7 +1005,7 @@ public class Xcls_GtkView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Box13(Xcls_GtkView _owner )
+               public Xcls_Box12(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
@@ -1033,7 +1023,7 @@ public class Xcls_GtkView : Object
                        this.el.append( _this.nextBtn.el );
                        new Xcls_backBtn( _this );
                        this.el.append( _this.backBtn.el );
-                       var child_5 = new Xcls_MenuButton19( _this );
+                       var child_5 = new Xcls_MenuButton18( _this );
                        child_5.ref();
                        this.el.append( child_5.el );
                }
@@ -1063,24 +1053,10 @@ public class Xcls_GtkView : Object
                        this.el.hexpand = true;
                        this.el.placeholder_text = "Press enter to search";
                        this.el.search_delay = 3;
-                       var child_1 = new Xcls_EventControllerKey15( _this );
+                       var child_1 = new Xcls_EventControllerKey14( _this );
                        child_1.ref();
                        this.el.add_controller(  child_1.el );
 
-                       // init method
-
-                       this.css = new Gtk.CssProvider();
-                       
-                       this.css.load_from_string("
-                               #gtkview-search-entry { font: 10px monospace ;}"
-                       );
-                       
-                       Gtk.StyleContext.add_provider_for_display(
-                               this.el.get_display(),
-                               this.css,
-                               Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
-                       );
-
                        //listeners
                        this.el.search_changed.connect( () => {
                                 
@@ -1125,7 +1101,7 @@ public class Xcls_GtkView : Object
                        
                }
        }
-       public class Xcls_EventControllerKey15 : Object
+       public class Xcls_EventControllerKey14 : Object
        {
                public Gtk.EventControllerKey el;
                private Xcls_GtkView  _this;
@@ -1134,7 +1110,7 @@ public class Xcls_GtkView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_EventControllerKey15(Xcls_GtkView _owner )
+               public Xcls_EventControllerKey14(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.EventControllerKey();
@@ -1284,7 +1260,7 @@ public class Xcls_GtkView : Object
                // user defined functions
        }
 
-       public class Xcls_MenuButton19 : Object
+       public class Xcls_MenuButton18 : Object
        {
                public Gtk.MenuButton el;
                private Xcls_GtkView  _this;
@@ -1294,7 +1270,7 @@ public class Xcls_GtkView : Object
                public bool always_show_image;
 
                // ctor
-               public Xcls_MenuButton19(Xcls_GtkView _owner )
+               public Xcls_MenuButton18(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.MenuButton();
@@ -1329,14 +1305,14 @@ public class Xcls_GtkView : Object
                        // my vars (dec)
 
                        // set gobject values
-                       var child_1 = new Xcls_Box21( _this );
+                       var child_1 = new Xcls_Box20( _this );
                        child_1.ref();
                        this.el.set_child ( child_1.el  );
                }
 
                // user defined functions
        }
-       public class Xcls_Box21 : Object
+       public class Xcls_Box20 : Object
        {
                public Gtk.Box el;
                private Xcls_GtkView  _this;
@@ -1345,7 +1321,7 @@ public class Xcls_GtkView : Object
                        // my vars (def)
 
                // ctor
-               public Xcls_Box21(Xcls_GtkView _owner )
+               public Xcls_Box20(Xcls_GtkView _owner )
                {
                        _this = _owner;
                        this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );