[gnome-builder/wip/uajain/word-completion: 1/2] WIP: Improve replaying results
- From: Umang Jain <uajain src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/uajain/word-completion: 1/2] WIP: Improve replaying results
- Date: Wed, 30 Aug 2017 12:58:51 +0000 (UTC)
commit 92102f8bccfc987619b12060e36f0d48109a4a05
Author: Umang Jain <mailumangjain gmail com>
Date: Wed Aug 30 17:44:51 2017 +0530
WIP: Improve replaying results
libide/sourceview/ide-completion-results.c | 44 ++++++++++++++++++++++
libide/sourceview/ide-word-completion-provider.c | 7 +++
2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/libide/sourceview/ide-completion-results.c b/libide/sourceview/ide-completion-results.c
index 89948e1..0a168c8 100644
--- a/libide/sourceview/ide-completion-results.c
+++ b/libide/sourceview/ide-completion-results.c
@@ -53,6 +53,20 @@ typedef struct
*/
GPtrArray *results;
/*
+ * sort_direction is same as PROP_DIRECTION in word-completion-provider.
+ * This is useful to determine how to sort the proposals using offsets
+ * in compare_func. See ide_word_completion_results_compare for details.
+ */
+ gint sort_direction;
+ /*
+ * insert_offset and end_offset helps to determine new relative offsets
+ * in case we can replay the results but in an another location. Hence,
+ * recompute new offsets and sort. See ide_word_completion_results_compare
+ * for details.
+ */
+ gint insert_offset;
+ gint end_offset;
+ /*
* query is the filtering string that was used to create the
* initial set of results. All future queries must have this
* word as a prefix to be reusable.
@@ -93,6 +107,7 @@ DZL_DEFINE_COUNTER (instances, "IdeCompletionResults", "Instances", "Number of I
enum {
PROP_0,
PROP_QUERY,
+ PROP_SORT_DIRECTION,
LAST_PROP
};
@@ -142,6 +157,17 @@ ide_completion_results_finalize (GObject *object)
DZL_COUNTER_DEC (instances);
}
+gint
+ide_completion_results_get_sort_direction (IdeCompletionResults *self)
+{
+ IdeCompletionResultsPrivate *priv = ide_completion_results_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_COMPLETION_RESULTS (self), 0);
+
+ return priv->sort_direction;
+
+}
+
const gchar *
ide_completion_results_get_query (IdeCompletionResults *self)
{
@@ -398,6 +424,10 @@ ide_completion_results_get_property (GObject *object,
g_value_set_string (value, ide_completion_results_get_query (self));
break;
+ case PROP_SORT_DIRECTION:
+ g_value_set_int (value, ide_completion_results_get_sort_direction (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -410,6 +440,7 @@ ide_completion_results_set_property (GObject *object,
GParamSpec *pspec)
{
IdeCompletionResults *self = IDE_COMPLETION_RESULTS (object);
+ IdeCompletionResultsPrivate *priv = ide_completion_results_get_instance_private (self);
switch (prop_id)
{
@@ -417,6 +448,10 @@ ide_completion_results_set_property (GObject *object,
ide_completion_results_set_query (self, g_value_get_string (value));
break;
+ case PROP_SORT_DIRECTION:
+ priv->sort_direction = g_value_get_int (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -438,6 +473,15 @@ ide_completion_results_class_init (IdeCompletionResultsClass *klass)
NULL,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+ properties [PROP_SORT_DIRECTION] =
+ g_param_spec_int ("sort-direction",
+ "Sort direction",
+ "Determines whether to sort with ascending or descending value of offset",
+ -1,
+ 1,
+ 0,
+ (G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_properties (object_class, LAST_PROP, properties);
}
diff --git a/libide/sourceview/ide-word-completion-provider.c
b/libide/sourceview/ide-word-completion-provider.c
index 839a689..0675445 100644
--- a/libide/sourceview/ide-word-completion-provider.c
+++ b/libide/sourceview/ide-word-completion-provider.c
@@ -386,6 +386,13 @@ ide_word_completion_provider_populate (GtkSourceCompletionProvider *provider,
{
if (ide_completion_results_replay (IDE_COMPLETION_RESULTS (priv->results), priv->current_word))
{
+ GValue *value;
+
+ value = g_new0(GValue, 1);
+ g_value_init (value, G_TYPE_INT);
+ g_value_set_int (value, priv->direction);
+ g_object_set_property (G_OBJECT (priv->results), "sort-direction", value);
+
ide_completion_results_present (IDE_COMPLETION_RESULTS (priv->results), provider, context);
IDE_EXIT;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]