[gnome-builder] plugins/codeui: add hover provider for diagnostics
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/codeui: add hover provider for diagnostics
- Date: Tue, 30 Aug 2022 01:19:19 +0000 (UTC)
commit d760f0fb196d9a0785dddc3adc0a5aedf9b9e078
Author: Christian Hergert <chergert redhat com>
Date: Mon Aug 29 18:19:13 2022 -0700
plugins/codeui: add hover provider for diagnostics
po/POTFILES.in | 1 +
src/plugins/codeui/codeui-plugin.c | 7 +-
src/plugins/codeui/gbp-codeui-hover-provider.c | 131 +++++++++++++++++++++++++
src/plugins/codeui/gbp-codeui-hover-provider.h | 31 ++++++
src/plugins/codeui/meson.build | 1 +
5 files changed, 170 insertions(+), 1 deletion(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d245e6f30..243b47816 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -129,6 +129,7 @@ src/plugins/code-index/gbp-code-index-application-addin.c
src/plugins/code-index/gbp-code-index-service.c
src/plugins/code-index/ide-code-index-index.c
src/plugins/codespell/ide-codespell-diagnostic-provider.c
+src/plugins/codeui/gbp-codeui-hover-provider.c
src/plugins/color-picker/gb-color-picker-editor-addin.c
src/plugins/color-picker/gb-color-picker-prefs.c
src/plugins/color-picker/gb-color-picker-prefs-palette-row.c
diff --git a/src/plugins/codeui/codeui-plugin.c b/src/plugins/codeui/codeui-plugin.c
index ca837a85a..d0237be13 100644
--- a/src/plugins/codeui/codeui-plugin.c
+++ b/src/plugins/codeui/codeui-plugin.c
@@ -21,11 +21,13 @@
#include "config.h"
#include <libpeas/peas.h>
+
#include <libide-code.h>
-#include <libide-foundry.h>
+#include <libide-sourceview.h>
#include <libide-tree.h>
#include "gbp-codeui-buffer-addin.h"
+#include "gbp-codeui-hover-provider.h"
#include "gbp-codeui-tree-addin.h"
_IDE_EXTERN void
@@ -34,6 +36,9 @@ _gbp_codeui_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
IDE_TYPE_BUFFER_ADDIN,
GBP_TYPE_CODEUI_BUFFER_ADDIN);
+ peas_object_module_register_extension_type (module,
+ GTK_SOURCE_TYPE_HOVER_PROVIDER,
+ GBP_TYPE_CODEUI_HOVER_PROVIDER);
peas_object_module_register_extension_type (module,
IDE_TYPE_TREE_ADDIN,
GBP_TYPE_CODEUI_TREE_ADDIN);
diff --git a/src/plugins/codeui/gbp-codeui-hover-provider.c b/src/plugins/codeui/gbp-codeui-hover-provider.c
new file mode 100644
index 000000000..cb0621473
--- /dev/null
+++ b/src/plugins/codeui/gbp-codeui-hover-provider.c
@@ -0,0 +1,131 @@
+/* gbp-codeui-hover-provider.c
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-codeui-hover-provider"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-code.h>
+#include <libide-gui.h>
+#include <libide-sourceview.h>
+#include <libide-threading.h>
+
+#include "gbp-codeui-hover-provider.h"
+
+struct _GbpCodeuiHoverProvider
+{
+ GObject parent_instance;
+};
+
+static gboolean
+gbp_codeui_hover_provider_populate (GtkSourceHoverProvider *provider,
+ GtkSourceHoverContext *context,
+ GtkSourceHoverDisplay *display,
+ GError **error)
+{
+ GbpCodeuiHoverProvider *self = (GbpCodeuiHoverProvider *)provider;
+ g_autoptr(GPtrArray) line_diags = NULL;
+ IdeDiagnostics *diagnostics;
+ GtkTextBuffer *buffer;
+ GtkTextIter iter;
+ GFile *file;
+ guint line;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (GBP_IS_CODEUI_HOVER_PROVIDER (self));
+ g_assert (GTK_SOURCE_IS_HOVER_CONTEXT (context));
+ g_assert (GTK_SOURCE_IS_HOVER_DISPLAY (display));
+
+ if (!gtk_source_hover_context_get_iter (context, &iter))
+ goto handle_error;
+
+ buffer = gtk_text_iter_get_buffer (&iter);
+
+ if (!IDE_IS_BUFFER (buffer))
+ goto handle_error;
+
+ file = ide_buffer_get_file (IDE_BUFFER (buffer));
+ line = gtk_text_iter_get_line (&iter);
+
+ if ((diagnostics = ide_buffer_get_diagnostics (IDE_BUFFER (buffer))) &&
+ (line_diags = ide_diagnostics_get_diagnostics_at_line (diagnostics, file, line)) &&
+ (line_diags->len > 0))
+ {
+ GtkBox *box;
+ GtkLabel *label;
+
+ IDE_PTR_ARRAY_SET_FREE_FUNC (line_diags, g_object_unref);
+
+ box = g_object_new (GTK_TYPE_BOX,
+ "orientation", GTK_ORIENTATION_VERTICAL,
+ NULL);
+ label = g_object_new (GTK_TYPE_LABEL,
+ "label", _("Diagnostics"),
+ "xalign", .0f,
+ "margin-bottom", 3,
+ NULL);
+ gtk_box_append (box, GTK_WIDGET (label));
+
+ for (guint i = 0; i < line_diags->len; i++)
+ {
+ IdeDiagnostic *diag = g_ptr_array_index (line_diags, i);
+ g_autoptr(IdeMarkedContent) content = NULL;
+ g_autofree gchar *text = ide_diagnostic_get_text_for_display (diag);
+ GtkWidget *child;
+
+ content = ide_marked_content_new_from_data (text, strlen (text), ide_diagnostic_get_marked_kind
(diag));
+ child = ide_marked_view_new (content);
+ gtk_box_append (box, child);
+ }
+
+ gtk_source_hover_display_append (display, GTK_WIDGET (box));
+
+ return TRUE;
+ }
+
+handle_error:
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Not supported");
+
+ return FALSE;
+}
+
+static void
+hover_provider_iface_init (GtkSourceHoverProviderInterface *iface)
+{
+ iface->populate = gbp_codeui_hover_provider_populate;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpCodeuiHoverProvider, gbp_codeui_hover_provider, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_HOVER_PROVIDER,
hover_provider_iface_init))
+
+static void
+gbp_codeui_hover_provider_class_init (GbpCodeuiHoverProviderClass *klass)
+{
+}
+
+static void
+gbp_codeui_hover_provider_init (GbpCodeuiHoverProvider *self)
+{
+}
diff --git a/src/plugins/codeui/gbp-codeui-hover-provider.h b/src/plugins/codeui/gbp-codeui-hover-provider.h
new file mode 100644
index 000000000..df2504da7
--- /dev/null
+++ b/src/plugins/codeui/gbp-codeui-hover-provider.h
@@ -0,0 +1,31 @@
+/* gbp-codeui-hover-provider.h
+ *
+ * Copyright 2018-2019 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_CODEUI_HOVER_PROVIDER (gbp_codeui_hover_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpCodeuiHoverProvider, gbp_codeui_hover_provider, GBP, CODEUI_HOVER_PROVIDER, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/codeui/meson.build b/src/plugins/codeui/meson.build
index 928a34315..f13c5c37c 100644
--- a/src/plugins/codeui/meson.build
+++ b/src/plugins/codeui/meson.build
@@ -1,6 +1,7 @@
plugins_sources += files([
'codeui-plugin.c',
'gbp-codeui-buffer-addin.c',
+ 'gbp-codeui-hover-provider.c',
'gbp-codeui-tree-addin.c',
])
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]