[gnome-builder/wip/gtk4-port] libide/lsp: port completion item to GtkSourceView 5



commit 15226305d132b2fbc4c0a725911990acaf064c85
Author: Christian Hergert <chergert redhat com>
Date:   Sun Apr 3 15:56:23 2022 -0700

    libide/lsp: port completion item to GtkSourceView 5
    
    This adds a display helper to the item so we don't have to go through as
    many function calls from the provider to get access to item data.

 src/libide/lsp/ide-lsp-completion-item.c | 62 ++++++++++++++++++++++++++++++++
 src/libide/lsp/ide-lsp-completion-item.h | 18 ++++++----
 2 files changed, 73 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-completion-item.c b/src/libide/lsp/ide-lsp-completion-item.c
index 70b7021dc..b050608d6 100644
--- a/src/libide/lsp/ide-lsp-completion-item.c
+++ b/src/libide/lsp/ide-lsp-completion-item.c
@@ -114,6 +114,68 @@ ide_lsp_completion_item_get_detail (IdeLspCompletionItem *self)
   return self->detail;
 }
 
+void
+ide_lsp_completion_item_display (IdeLspCompletionItem    *self,
+                                 GtkSourceCompletionCell *cell,
+                                 const char              *typed_text)
+{
+  GtkSourceCompletionColumn column;
+
+  g_return_if_fail (IDE_IS_LSP_COMPLETION_ITEM (self));
+  g_return_if_fail (GTK_SOURCE_IS_COMPLETION_CELL (cell));
+
+  column = gtk_source_completion_cell_get_column (cell);
+
+  switch (column)
+    {
+    case GTK_SOURCE_COMPLETION_COLUMN_ICON:
+      gtk_source_completion_cell_set_icon_name (cell, ide_lsp_completion_item_get_icon_name (self));
+      break;
+
+    case GTK_SOURCE_COMPLETION_COLUMN_TYPED_TEXT:
+      {
+        PangoAttrList *attrs;
+
+        attrs = gtk_source_completion_fuzzy_highlight (self->label, typed_text);
+        gtk_source_completion_cell_set_text_with_attributes (cell, self->label, attrs);
+        pango_attr_list_unref (attrs);
+
+        break;
+      }
+
+    case GTK_SOURCE_COMPLETION_COLUMN_COMMENT:
+      if (self->detail != NULL && self->detail[0] != 0)
+        {
+          const char *endptr = strchr (self->detail, '\n');
+
+          if (endptr == NULL)
+            {
+              gtk_source_completion_cell_set_text (cell, self->detail);
+            }
+          else
+            {
+              g_autofree char *detail = g_strndup (self->detail, endptr - self->detail);
+              gtk_source_completion_cell_set_text (cell, detail);
+            }
+        }
+      break;
+
+    case GTK_SOURCE_COMPLETION_COLUMN_DETAILS:
+      /* TODO: If there is markdown, we *could* use a markedview here
+       * and set_child() with the WebKit view.
+       */
+      gtk_source_completion_cell_set_text (cell, self->detail);
+      break;
+
+    default:
+    case GTK_SOURCE_COMPLETION_COLUMN_AFTER:
+    case GTK_SOURCE_COMPLETION_COLUMN_BEFORE:
+      /* TODO: Can we get this info from LSP? */
+      gtk_source_completion_cell_set_text (cell, NULL);
+      break;
+    }
+}
+
 /**
  * ide_lsp_completion_item_get_snippet:
  * @self: a #IdeLspCompletionItem
diff --git a/src/libide/lsp/ide-lsp-completion-item.h b/src/libide/lsp/ide-lsp-completion-item.h
index 7dd6ff812..3cb800c1c 100644
--- a/src/libide/lsp/ide-lsp-completion-item.h
+++ b/src/libide/lsp/ide-lsp-completion-item.h
@@ -34,18 +34,22 @@ IDE_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (IdeLspCompletionItem, ide_lsp_completion_item, IDE, LSP_COMPLETION_ITEM, GObject)
 
 IDE_AVAILABLE_IN_ALL
-IdeLspCompletionItem *ide_lsp_completion_item_new                       (GVariant             *variant);
+IdeLspCompletionItem *ide_lsp_completion_item_new                       (GVariant                *variant);
 IDE_AVAILABLE_IN_ALL
-const gchar          *ide_lsp_completion_item_get_icon_name             (IdeLspCompletionItem *self);
+const gchar          *ide_lsp_completion_item_get_icon_name             (IdeLspCompletionItem    *self);
 IDE_AVAILABLE_IN_ALL
-const gchar          *ide_lsp_completion_item_get_return_type           (IdeLspCompletionItem *self);
+const gchar          *ide_lsp_completion_item_get_return_type           (IdeLspCompletionItem    *self);
 IDE_AVAILABLE_IN_ALL
-const gchar          *ide_lsp_completion_item_get_detail                (IdeLspCompletionItem *self);
+const gchar          *ide_lsp_completion_item_get_detail                (IdeLspCompletionItem    *self);
 IDE_AVAILABLE_IN_ALL
-GtkSourceSnippet     *ide_lsp_completion_item_get_snippet               (IdeLspCompletionItem *self);
+GtkSourceSnippet     *ide_lsp_completion_item_get_snippet               (IdeLspCompletionItem    *self);
 
 IDE_AVAILABLE_IN_ALL
-GPtrArray            *ide_lsp_completion_item_get_additional_text_edits (IdeLspCompletionItem *self,
-                                                                         GFile                *file);
+GPtrArray            *ide_lsp_completion_item_get_additional_text_edits (IdeLspCompletionItem    *self,
+                                                                         GFile                   *file);
+IDE_AVAILABLE_IN_ALL
+void                  ide_lsp_completion_item_display                   (IdeLspCompletionItem    *self,
+                                                                         GtkSourceCompletionCell *cell,
+                                                                         const char              
*typed_text);
 
 G_END_DECLS


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