[gnome-builder: 67/139] codeui: add codeui plugin



commit 5423911b6edc46edc1a4a682e91f9b3e1b4468b3
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 9 17:08:40 2019 -0800

    codeui: add codeui plugin
    
    This core plugin bridges the diagnostics manager with loaded editor
    buffers.

 src/plugins/codeui/codeui-plugin.c           |  35 +++++
 src/plugins/codeui/codeui.gresource.xml      |   6 +
 src/plugins/codeui/codeui.plugin             |  10 ++
 src/plugins/codeui/gbp-codeui-buffer-addin.c | 203 +++++++++++++++++++++++++++
 src/plugins/codeui/gbp-codeui-buffer-addin.h |  31 ++++
 src/plugins/codeui/meson.build               |  12 ++
 6 files changed, 297 insertions(+)
---
diff --git a/src/plugins/codeui/codeui-plugin.c b/src/plugins/codeui/codeui-plugin.c
new file mode 100644
index 000000000..099edef6f
--- /dev/null
+++ b/src/plugins/codeui/codeui-plugin.c
@@ -0,0 +1,35 @@
+/* codeui-plugin.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
+ */
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+#include <libide-code.h>
+#include <libide-foundry.h>
+
+#include "gbp-codeui-buffer-addin.h"
+
+_IDE_EXTERN void
+_gbp_codeui_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_BUFFER_ADDIN,
+                                              GBP_TYPE_CODEUI_BUFFER_ADDIN);
+}
diff --git a/src/plugins/codeui/codeui.gresource.xml b/src/plugins/codeui/codeui.gresource.xml
new file mode 100644
index 000000000..e0733b815
--- /dev/null
+++ b/src/plugins/codeui/codeui.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/codeui">
+    <file>codeui.plugin</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/codeui/codeui.plugin b/src/plugins/codeui/codeui.plugin
new file mode 100644
index 000000000..17bc396ea
--- /dev/null
+++ b/src/plugins/codeui/codeui.plugin
@@ -0,0 +1,10 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2018 Christian Hergert
+Depends=editor;
+Description=Provides user interface components for code subsystem.
+Embedded=_gbp_codeui_register_types
+Hidden=true
+Module=codeui
+Name=Code UI integration plugin
diff --git a/src/plugins/codeui/gbp-codeui-buffer-addin.c b/src/plugins/codeui/gbp-codeui-buffer-addin.c
new file mode 100644
index 000000000..ca26551f1
--- /dev/null
+++ b/src/plugins/codeui/gbp-codeui-buffer-addin.c
@@ -0,0 +1,203 @@
+/* gbp-codeui-buffer-addin.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-buffer-addin"
+
+#include "config.h"
+
+#include <libide-code.h>
+
+#include "ide-diagnostics-manager-private.h"
+
+#include "gbp-codeui-buffer-addin.h"
+
+struct _GbpCodeuiBufferAddin
+{
+  GObject    parent_instance;
+  IdeBuffer *buffer;
+  GFile     *file;
+};
+
+static void
+gbp_codeui_buffer_addin_queue_diagnose (GbpCodeuiBufferAddin *self,
+                                        IdeBuffer            *buffer)
+{
+  g_autoptr(IdeContext) context = NULL;
+  IdeDiagnosticsManager *manager;
+  g_autoptr(GBytes) contents = NULL;
+  const gchar *lang_id;
+  GFile *file;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_CODEUI_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  context = ide_buffer_ref_context (buffer);
+  manager = ide_diagnostics_manager_from_context (context);
+  file = ide_buffer_get_file (buffer);
+  lang_id = ide_buffer_get_language_id (buffer);
+  contents = ide_buffer_dup_content (buffer);
+
+  _ide_diagnostics_manager_file_changed (manager, file, contents, lang_id);
+}
+
+static void
+gbp_codeui_buffer_addin_change_settled (IdeBufferAddin *addin,
+                                        IdeBuffer      *buffer)
+{
+  GbpCodeuiBufferAddin *self = (GbpCodeuiBufferAddin *)addin;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_CODEUI_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  gbp_codeui_buffer_addin_queue_diagnose (self, buffer);
+}
+
+static void
+gbp_codeui_buffer_addin_file_loaded (IdeBufferAddin *addin,
+                                     IdeBuffer      *buffer,
+                                     GFile          *file)
+{
+  GbpCodeuiBufferAddin *self = (GbpCodeuiBufferAddin *)addin;
+  g_autoptr(IdeContext) context = NULL;
+  IdeDiagnosticsManager *manager;
+  const gchar *lang_id;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_CODEUI_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+  g_assert (G_IS_FILE (file));
+
+  g_set_object (&self->file, file);
+
+  context = ide_buffer_ref_context (buffer);
+  manager = ide_diagnostics_manager_from_context (context);
+  lang_id = ide_buffer_get_language_id (buffer);
+
+  _ide_diagnostics_manager_file_opened (manager, file, lang_id);
+}
+
+static void
+gbp_codeui_buffer_addin_file_saved (IdeBufferAddin *addin,
+                                    IdeBuffer      *buffer,
+                                    GFile          *file)
+{
+  GbpCodeuiBufferAddin *self = (GbpCodeuiBufferAddin *)addin;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_CODEUI_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+  g_assert (G_IS_FILE (file));
+
+  g_set_object (&self->file, file);
+
+  gbp_codeui_buffer_addin_queue_diagnose (self, buffer);
+}
+
+static void
+gbp_codeui_buffer_addin_changed_cb (GbpCodeuiBufferAddin  *self,
+                                    IdeDiagnosticsManager *manager)
+{
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_CODEUI_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_DIAGNOSTICS_MANAGER (manager));
+
+  if (self->file != NULL)
+    {
+      g_autoptr(IdeDiagnostics) diagnostics = NULL;
+
+      diagnostics = ide_diagnostics_manager_get_diagnostics_for_file (manager, self->file);
+      ide_buffer_set_diagnostics (self->buffer, diagnostics);
+    }
+}
+
+static void
+gbp_codeui_buffer_addin_load (IdeBufferAddin *addin,
+                              IdeBuffer      *buffer)
+{
+  GbpCodeuiBufferAddin *self = (GbpCodeuiBufferAddin *)addin;
+  g_autoptr(IdeContext) context = NULL;
+  IdeDiagnosticsManager *manager;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_CODEUI_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  context = ide_buffer_ref_context (buffer);
+  manager = ide_diagnostics_manager_from_context (context);
+
+  self->buffer = g_object_ref (buffer);
+
+  g_signal_connect_object (manager,
+                           "changed",
+                           G_CALLBACK (gbp_codeui_buffer_addin_changed_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+}
+
+static void
+gbp_codeui_buffer_addin_unload (IdeBufferAddin *addin,
+                                IdeBuffer      *buffer)
+{
+  GbpCodeuiBufferAddin *self = (GbpCodeuiBufferAddin *)addin;
+  g_autoptr(IdeContext) context = NULL;
+  IdeDiagnosticsManager *manager;
+  GFile *file;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_CODEUI_BUFFER_ADDIN (self));
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  context = ide_buffer_ref_context (buffer);
+  manager = ide_diagnostics_manager_from_context (context);
+  file = ide_buffer_get_file (buffer);
+
+  g_signal_handlers_disconnect_by_func (manager,
+                                        G_CALLBACK (gbp_codeui_buffer_addin_changed_cb),
+                                        self);
+
+  _ide_diagnostics_manager_file_closed (manager, file);
+
+  g_clear_object (&self->file);
+}
+
+static void
+buffer_addin_iface_init (IdeBufferAddinInterface *iface)
+{
+  iface->change_settled = gbp_codeui_buffer_addin_change_settled;
+  iface->file_saved = gbp_codeui_buffer_addin_file_saved;
+  iface->file_loaded = gbp_codeui_buffer_addin_file_loaded;
+  iface->load = gbp_codeui_buffer_addin_load;
+  iface->unload = gbp_codeui_buffer_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpCodeuiBufferAddin, gbp_codeui_buffer_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_BUFFER_ADDIN, buffer_addin_iface_init))
+
+static void
+gbp_codeui_buffer_addin_class_init (GbpCodeuiBufferAddinClass *klass)
+{
+}
+
+static void
+gbp_codeui_buffer_addin_init (GbpCodeuiBufferAddin *self)
+{
+}
diff --git a/src/plugins/codeui/gbp-codeui-buffer-addin.h b/src/plugins/codeui/gbp-codeui-buffer-addin.h
new file mode 100644
index 000000000..51aa494a4
--- /dev/null
+++ b/src/plugins/codeui/gbp-codeui-buffer-addin.h
@@ -0,0 +1,31 @@
+/* gbp-codeui-buffer-addin.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_BUFFER_ADDIN (gbp_codeui_buffer_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpCodeuiBufferAddin, gbp_codeui_buffer_addin, GBP, CODEUI_BUFFER_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/codeui/meson.build b/src/plugins/codeui/meson.build
new file mode 100644
index 000000000..c374a40cb
--- /dev/null
+++ b/src/plugins/codeui/meson.build
@@ -0,0 +1,12 @@
+plugins_sources += files([
+  'codeui-plugin.c',
+  'gbp-codeui-buffer-addin.c',
+])
+
+plugin_codeui_resources = gnome.compile_resources(
+  'codeui-resources',
+  'codeui.gresource.xml',
+  c_name: 'gbp_codeui',
+)
+
+plugins_sources += plugin_codeui_resources[0]


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