[gnome-builder] clang: raise priority for field access
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] clang: raise priority for field access
- Date: Tue, 26 Jun 2018 06:32:52 +0000 (UTC)
commit 989af8c2a533c8182ddc0f2185c52b544f61c01a
Author: Christian Hergert <chergert redhat com>
Date: Mon Jun 25 23:32:00 2018 -0700
clang: raise priority for field access
If we're completing a field for a struct, we want to make our results
higher than snippets (but only after we've fetched them).
src/plugins/clang/ide-clang-completion-provider.c | 38 +++++++++++++++++++++--
1 file changed, 35 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/clang/ide-clang-completion-provider.c
b/src/plugins/clang/ide-clang-completion-provider.c
index 6eb6098f6..3601f6f0e 100644
--- a/src/plugins/clang/ide-clang-completion-provider.c
+++ b/src/plugins/clang/ide-clang-completion-provider.c
@@ -30,10 +30,41 @@ struct _IdeClangCompletionProvider
IdeClangProposals *proposals;
};
+static gboolean
+is_field_access (IdeCompletionContext *context)
+{
+ GtkTextIter begin, end;
+
+ g_assert (IDE_IS_COMPLETION_CONTEXT (context));
+
+ ide_completion_context_get_bounds (context, &begin, &end);
+
+ if (gtk_text_iter_backward_char (&begin))
+ {
+ if (gtk_text_iter_get_char (&begin) == '>')
+ {
+ if (gtk_text_iter_backward_char (&begin))
+ {
+ if (gtk_text_iter_get_char (&begin) == '-')
+ return TRUE;
+ }
+ }
+
+ if (gtk_text_iter_get_char (&begin) == '.')
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static gint
ide_clang_completion_provider_get_priority (IdeCompletionProvider *provider,
IdeCompletionContext *context)
{
+ /* Place results before snippets */
+ if (is_field_access (context))
+ return -200;
+
return 100;
}
@@ -262,9 +293,10 @@ ide_clang_completion_provider_populate_async (IdeCompletionProvider *provider,
* the user wants will be in the previous list too, and that can drop the
* latency a bit.
*/
- ide_completion_context_set_proposals_for_provider (context,
- provider,
- G_LIST_MODEL (self->proposals));
+ if (!is_field_access (context))
+ ide_completion_context_set_proposals_for_provider (context,
+ provider,
+ G_LIST_MODEL (self->proposals));
ide_clang_proposals_populate_async (self->proposals,
&begin,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]