[gnome-builder/wip/chergert/completion] clang: include comments from clang



commit 667f1de661ec5b2c8cbf2b2fe458fb8369a48dcc
Author: Christian Hergert <chergert redhat com>
Date:   Thu May 31 17:58:33 2018 -0700

    clang: include comments from clang
    
    If we got a comment from clang, we should dipslay that.
    
    We probably also need to add a way to get docs from devhelp but we need
    to think about that API more.

 src/plugins/clang/ide-clang-completion-item.c | 21 ++++++++++++++++++++-
 src/plugins/clang/ide-clang.c                 |  7 +++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/clang/ide-clang-completion-item.c b/src/plugins/clang/ide-clang-completion-item.c
index 8f32bf1ec..ba50f4419 100644
--- a/src/plugins/clang/ide-clang-completion-item.c
+++ b/src/plugins/clang/ide-clang-completion-item.c
@@ -23,8 +23,27 @@
 
 #include "ide-clang-completion-item.h"
 
+static gchar *
+ide_clang_completion_item_get_comment (IdeCompletionProposal *proposal)
+{
+  IdeClangCompletionItem *self = (IdeClangCompletionItem *)proposal;
+  g_autoptr(GVariant) result = ide_clang_completion_item_get_result (self);
+  const gchar *str;
+
+  if (g_variant_lookup (result, "comment", "&s", &str))
+    return g_strdup (str);
+
+  return NULL;
+}
+
+static void
+proposal_iface_init (IdeCompletionProposalInterface *iface)
+{
+  iface->get_comment = ide_clang_completion_item_get_comment;
+}
+
 G_DEFINE_TYPE_WITH_CODE (IdeClangCompletionItem, ide_clang_completion_item, G_TYPE_OBJECT,
-                         G_IMPLEMENT_INTERFACE (IDE_TYPE_COMPLETION_PROPOSAL, NULL))
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_COMPLETION_PROPOSAL, proposal_iface_init))
 
 static void
 ide_clang_completion_item_do_init (IdeClangCompletionItem *self)
diff --git a/src/plugins/clang/ide-clang.c b/src/plugins/clang/ide-clang.c
index 772b6619b..7dc70027d 100644
--- a/src/plugins/clang/ide-clang.c
+++ b/src/plugins/clang/ide-clang.c
@@ -1166,6 +1166,8 @@ ide_clang_build_completion (GVariantBuilder    *builder,
 {
   GVariantBuilder chunks_builder;
   g_autofree gchar *typed_text = NULL;
+  g_auto(CXString) comment = {0};
+  const gchar *comment_cstr;
   guint n_chunks;
 
   g_assert (builder != NULL);
@@ -1173,6 +1175,11 @@ ide_clang_build_completion (GVariantBuilder    *builder,
 
   g_variant_builder_add_parsed (builder, "{%s,<%u>}", "kind", result->CursorKind);
 
+  comment = clang_getCompletionBriefComment (result->CompletionString);
+  comment_cstr = clang_getCString (comment);
+  if (comment_cstr && *comment_cstr)
+    g_variant_builder_add_parsed (builder, "{%s,<%s>}", "comment", comment_cstr);
+
   if (clang_getCompletionAvailability (result->CompletionString))
     g_variant_builder_add_parsed (builder, "{%s,<%u>}", "avail",
                                   clang_getCompletionAvailability (result->CompletionString));


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