[gnome-builder/gnome-builder-3-18] vala: inherit from IdeCompletionItem



commit 9d3b32ddf19e8e546ca6b8feb40b26bc7d674502
Author: Christian Hergert <christian hergert me>
Date:   Thu Oct 1 16:56:33 2015 -0700

    vala: inherit from IdeCompletionItem
    
    This still needs to be changed to use IdeCompletionResults.

 plugins/vala-pack/ide-vala-completion-item.vala    |   36 +++++++++++--------
 .../vala-pack/ide-vala-completion-provider.vala    |   12 +-----
 2 files changed, 23 insertions(+), 25 deletions(-)
---
diff --git a/plugins/vala-pack/ide-vala-completion-item.vala b/plugins/vala-pack/ide-vala-completion-item.vala
index 56f2731..32c9559 100644
--- a/plugins/vala-pack/ide-vala-completion-item.vala
+++ b/plugins/vala-pack/ide-vala-completion-item.vala
@@ -22,14 +22,12 @@ using Vala;
 
 namespace Ide
 {
-       public delegate string ValaCompletionMarkupFunc (string name);
-
-       public class ValaCompletionItem: GLib.Object, Gtk.SourceCompletionProposal
+       public class ValaCompletionItem: Ide.CompletionItem, Gtk.SourceCompletionProposal
        {
                static uint hash_seed;
 
                internal Vala.Symbol symbol;
-               ValaCompletionMarkupFunc? markup_func;
+               weak Ide.ValaCompletionProvider? provider;
                string label;
 
                static construct {
@@ -47,9 +45,9 @@ namespace Ide
                        this.build_label ();
                }
 
-               public void set_markup_func (owned ValaCompletionMarkupFunc? func)
+               internal void set_provider (Ide.ValaCompletionProvider? provider)
                {
-                       this.markup_func = func;
+                       this.provider = provider;
                }
 
                public unowned string? get_icon_name ()
@@ -82,13 +80,20 @@ namespace Ide
 
                public bool matches (string? prefix_lower)
                {
+                       uint priority;
+                       bool ret;
+
                        if (prefix_lower == null || prefix_lower [0] == '\0')
                                return true;
 
-                       return gb_str_simple_match (this.symbol.name, prefix_lower);
+                       ret = Ide.CompletionItem.fuzzy_match (this.symbol.name, prefix_lower, out priority);
+                       /* TODO: Save priority to use for sorting. */
+
+                       return ret;
                }
 
-               public string get_label () {
+               public string get_label ()
+               {
                        return this.symbol.name;
                }
 
@@ -137,13 +142,15 @@ namespace Ide
                        this.label = (owned)str.str;
                }
 
-               public string get_markup () {
-                       if (this.markup_func != null)
-                               return this.markup_func (this.label);
+               public string get_markup ()
+               {
+                       if (this.provider != null)
+                               return highlight_full (this.label, this.provider.last_prefix, true, 1);
                        return this.label;
                }
 
-               public string get_text () {
+               public string get_text ()
+               {
                        return this.symbol.name;
                }
 
@@ -157,7 +164,6 @@ namespace Ide
                public string? get_info () { return null; }
        }
 
-       [CCode (cheader_filename = "gb-string.h", cname = "gb_str_simple_match")]
-       extern bool gb_str_simple_match (string? text, string? prefix_lower);
+       [CCode (cheader_filename = "gb-string.h", cname = "gb_str_highlight_full")]
+       extern string? highlight_full (string haystack, string needle, bool insensitive, int type);
 }
-
diff --git a/plugins/vala-pack/ide-vala-completion-provider.vala 
b/plugins/vala-pack/ide-vala-completion-provider.vala
index 7b54487..6061695 100644
--- a/plugins/vala-pack/ide-vala-completion-provider.vala
+++ b/plugins/vala-pack/ide-vala-completion-provider.vala
@@ -50,9 +50,9 @@ namespace Ide
                                             Gtk.SourceCompletionProvider,
                                             Ide.CompletionProvider
        {
+               internal string? last_prefix;
                GenericArray<Ide.ValaCompletionItem>? last_results;
                string? last_line;
-               string? last_prefix;
                int line = -1;
                int column = -1;
 
@@ -154,7 +154,7 @@ namespace Ide
                                        for (int i = 0; i < results.length; i++) {
                                                var item = results.get (i);
                                                list.prepend (item);
-                                               item.set_markup_func (this.markup_func);
+                                               item.set_provider (this);
                                        }
                                        context.add_proposals (this, list, true);
                                }
@@ -215,17 +215,9 @@ namespace Ide
                        return true;
                }
 
-               string markup_func (string name)
-               {
-                       return highlight_full (name, this.last_prefix, true, 1);
-               }
-
                public int get_priority ()
                {
                        return 200;
                }
        }
-
-       [CCode (cheader_filename = "gb-string.h", cname = "gb_str_highlight_full")]
-       extern unowned string? highlight_full (string haystack, string needle, bool insensitive, int type);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]