[gnome-builder/gnome-builder-3-18] vala: sort completion results



commit 0742496f10ef97983c65f56259ce38c0e22e74f9
Author: Christian Hergert <christian hergert me>
Date:   Sun Sep 27 00:15:02 2015 -0700

    vala: sort completion results
    
    Later on, we'll probably want to score these and sort them by the score.
    But that will take a bit more effort and overhead, so this is a good
    start.

 plugins/vala-pack/ide-vala-completion-item.vala    |    2 +-
 .../vala-pack/ide-vala-completion-provider.vala    |   12 +++++++--
 plugins/vala-pack/ide-vala-index.vala              |   23 ++++++++++---------
 3 files changed, 22 insertions(+), 15 deletions(-)
---
diff --git a/plugins/vala-pack/ide-vala-completion-item.vala b/plugins/vala-pack/ide-vala-completion-item.vala
index f29e0b7..3b78c19 100644
--- a/plugins/vala-pack/ide-vala-completion-item.vala
+++ b/plugins/vala-pack/ide-vala-completion-item.vala
@@ -28,7 +28,7 @@ namespace Ide
        {
                static uint hash_seed;
 
-               Vala.Symbol symbol;
+               internal Vala.Symbol symbol;
                ValaCompletionMarkupFunc? markup_func;
                string label;
 
diff --git a/plugins/vala-pack/ide-vala-completion-provider.vala 
b/plugins/vala-pack/ide-vala-completion-provider.vala
index 08ccf46..d538a8d 100644
--- a/plugins/vala-pack/ide-vala-completion-provider.vala
+++ b/plugins/vala-pack/ide-vala-completion-provider.vala
@@ -50,7 +50,7 @@ namespace Ide
                                             Gtk.SourceCompletionProvider,
                                             Ide.CompletionProvider
        {
-               ArrayList<Ide.ValaCompletionItem>? last_results;
+               GenericArray<Ide.ValaCompletionItem>? last_results;
                string? last_line;
                string? last_prefix;
                int line = -1;
@@ -101,7 +101,8 @@ namespace Ide
                                var results = new GLib.List<Gtk.SourceCompletionProposal> ();
 
                                /* See the comment above about optimizing this. */
-                               foreach (var result in this.last_results) {
+                               for (int i = 0; i < this.last_results.length; i++) {
+                                       var result = this.last_results.get (i);
                                        if (result.matches (downcase)) {
                                                var hash = (void*)result.hash ();
                                                if (dedup.contains ((void*)hash))
@@ -160,10 +161,15 @@ namespace Ide
                                        this.column = res_column - 1;
                                }
 
+                               results.sort ((a,b) => {
+                                       return -GLib.strcmp (a.symbol.name, b.symbol.name);
+                               });
+
                                if (!cancellable.is_cancelled ()) {
                                        /* TODO: fix more brain dead slow list conversion stuff */
                                        var list = new GLib.List<Ide.ValaCompletionItem> ();
-                                       foreach (var item in results) {
+                                       for (int i = 0; i < results.length; i++) {
+                                               var item = results.get (i);
                                                list.prepend (item);
                                                item.set_markup_func (this.markup_func);
                                        }
diff --git a/plugins/vala-pack/ide-vala-index.vala b/plugins/vala-pack/ide-vala-index.vala
index 02cec0b..d102efb 100644
--- a/plugins/vala-pack/ide-vala-index.vala
+++ b/plugins/vala-pack/ide-vala-index.vala
@@ -170,17 +170,17 @@ namespace Ide
                        return true;
                }
 
-               public async ArrayList<Ide.ValaCompletionItem> code_complete (GLib.File file,
-                                                                             int line,
-                                                                             int column,
-                                                                             string? line_text,
-                                                                             Ide.UnsavedFiles? unsaved_files,
-                                                                             out int result_line,
-                                                                             out int result_column,
-                                                                             GLib.Cancellable? cancellable)
+               public async GenericArray<Ide.ValaCompletionItem> code_complete (GLib.File file,
+                                                                                int line,
+                                                                                int column,
+                                                                                string? line_text,
+                                                                                Ide.UnsavedFiles? 
unsaved_files,
+                                                                                out int result_line,
+                                                                                out int result_column,
+                                                                                GLib.Cancellable? 
cancellable)
                {
                        var unsaved_files_copy = unsaved_files.to_array ();
-                       var result = new ArrayList<Ide.ValaCompletionItem> ();
+                       var result = new GenericArray<Ide.ValaCompletionItem> ();
 
                        Ide.ThreadPool.push (Ide.ThreadPoolKind.COMPILER, () => {
                                if ((cancellable == null) || !cancellable.is_cancelled ()) {
@@ -269,7 +269,7 @@ namespace Ide
                                      ref int column,
                                      string line_text,
                                      Vala.Symbol? nearest,
-                                     ArrayList<Ide.ValaCompletionItem> results)
+                                     GenericArray<Ide.ValaCompletionItem> results)
                {
                        if (!(nearest is Vala.Block))
                                nearest = null;
@@ -285,7 +285,8 @@ namespace Ide
                        var list = completion.run (ref cursor);
 
                        foreach (var symbol in list) {
-                               results.add (new Ide.ValaCompletionItem (symbol));
+                               if (symbol.name != null && symbol.name[0] != '\0')
+                                       results.add (new Ide.ValaCompletionItem (symbol));
                        }
 
                        line = cursor.line;


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