[gnome-builder/wip/chergert/lsp-plugin-loader] libide/lsp: implement dynamic GType registration for code actions
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/lsp-plugin-loader] libide/lsp: implement dynamic GType registration for code actions
- Date: Fri, 14 Oct 2022 02:24:01 +0000 (UTC)
commit dce6afa5d22cd7a381182c9e5af67cd606d1741a
Author: Christian Hergert <chergert redhat com>
Date: Thu Oct 13 21:23:56 2022 -0500
libide/lsp: implement dynamic GType registration for code actions
.../lsp/ide-lsp-plugin-code-action-provider.c | 100 +++++++++++++++++++++
src/libide/lsp/ide-lsp-plugin-private.h | 50 ++++++-----
src/libide/lsp/ide-lsp-plugin.c | 23 +----
src/libide/lsp/meson.build | 1 +
4 files changed, 129 insertions(+), 45 deletions(-)
---
diff --git a/src/libide/lsp/ide-lsp-plugin-code-action-provider.c
b/src/libide/lsp/ide-lsp-plugin-code-action-provider.c
new file mode 100644
index 000000000..672955cd6
--- /dev/null
+++ b/src/libide/lsp/ide-lsp-plugin-code-action-provider.c
@@ -0,0 +1,100 @@
+/* ide-lsp-plugin-code-action-provider.c
+ *
+ * Copyright 2022 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 "ide-lsp-plugin-code-action-provider"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-code.h>
+
+#include "ide-lsp-code-action-provider.h"
+#include "ide-lsp-plugin-private.h"
+#include "ide-lsp-service.h"
+
+typedef struct _IdeLspPluginCodeActionProviderClass
+{
+ IdeLspCodeActionProviderClass parent_class;
+ IdeLspPluginInfo *info;
+} IdeLspPluginCodeActionProviderClass;
+
+static void
+ide_lsp_plugin_code_action_provider_load (IdeCodeActionProvider *provider)
+{
+ IdeLspPluginCodeActionProviderClass *klass = (IdeLspPluginCodeActionProviderClass *)(((GTypeInstance
*)provider)->g_class);
+ g_autoptr(IdeLspServiceClass) service_class = g_type_class_ref (klass->info->service_type);
+
+ ide_lsp_service_class_bind_client (service_class, IDE_OBJECT (provider));
+}
+
+static void
+ide_lsp_plugin_code_action_provider_class_init (IdeLspPluginCodeActionProviderClass *klass,
+ IdeLspPluginInfo *info)
+{
+ klass->info = info;
+}
+
+static void
+ide_lsp_plugin_code_action_provider_iface_init (IdeCodeActionProviderInterface *iface)
+{
+ iface->load = ide_lsp_plugin_code_action_provider_load;
+}
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+GObject *
+ide_lsp_plugin_create_code_action_provider (guint n_parameters,
+ GParameter *parameters,
+ IdeLspPluginInfo *info)
+{
+ ide_lsp_plugin_remove_plugin_info_param (&n_parameters, parameters);
+
+ if G_UNLIKELY (info->code_action_provider_type == G_TYPE_INVALID)
+ {
+ g_autofree char *name = g_strconcat (info->module_name, "+CodeActionProvider", NULL);
+
+ info->code_action_provider_type =
+ g_type_register_static (IDE_TYPE_LSP_CODE_ACTION_PROVIDER,
+ name,
+ &(GTypeInfo) {
+ sizeof (IdeLspPluginCodeActionProviderClass),
+ NULL,
+ NULL,
+ (GClassInitFunc)ide_lsp_plugin_code_action_provider_class_init,
+ NULL,
+ ide_lsp_plugin_info_ref (info),
+ sizeof (IdeLspCodeActionProvider),
+ 0,
+ NULL,
+ NULL,
+ },
+ G_TYPE_FLAG_FINAL);
+ g_type_add_interface_static (info->code_action_provider_type,
+ IDE_TYPE_CODE_ACTION_PROVIDER,
+ &(GInterfaceInfo) {
+ (GInterfaceInitFunc)(void (*)
(void))ide_lsp_plugin_code_action_provider_iface_init,
+ NULL,
+ NULL,
+ });
+ }
+
+ return g_object_newv (info->code_action_provider_type, n_parameters, parameters);
+}
+G_GNUC_END_IGNORE_DEPRECATIONS
diff --git a/src/libide/lsp/ide-lsp-plugin-private.h b/src/libide/lsp/ide-lsp-plugin-private.h
index 144c3a223..a25ee4522 100644
--- a/src/libide/lsp/ide-lsp-plugin-private.h
+++ b/src/libide/lsp/ide-lsp-plugin-private.h
@@ -34,6 +34,7 @@ typedef struct _IdeLspPluginInfo
GBytes *default_settings;
GType service_type;
GType completion_provider_type;
+ GType code_action_provider_type;
GType diagnostic_provider_type;
GType formatter_type;
GType highlighter_type;
@@ -46,29 +47,32 @@ IdeLspPluginInfo *ide_lsp_plugin_info_ref (IdeLspPluginInfo *i
void ide_lsp_plugin_info_unref (IdeLspPluginInfo *info);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-void ide_lsp_plugin_remove_plugin_info_param (guint *n_parameters,
- GParameter *parameters);
-GObject *ide_lsp_plugin_create_completion_provider (guint n_parameters,
- GParameter *parameters,
- IdeLspPluginInfo *info);
-GObject *ide_lsp_plugin_create_diagnostic_provider (guint n_parameters,
- GParameter *parameters,
- IdeLspPluginInfo *info);
-GObject *ide_lsp_plugin_create_formatter (guint n_parameters,
- GParameter *parameters,
- IdeLspPluginInfo *info);
-GObject *ide_lsp_plugin_create_highlighter (guint n_parameters,
- GParameter *parameters,
- IdeLspPluginInfo *info);
-GObject *ide_lsp_plugin_create_hover_provider (guint n_parameters,
- GParameter *parameters,
- IdeLspPluginInfo *info);
-GObject *ide_lsp_plugin_create_rename_provider (guint n_parameters,
- GParameter *parameters,
- IdeLspPluginInfo *info);
-GObject *ide_lsp_plugin_create_symbol_resolver (guint n_parameters,
- GParameter *parameters,
- IdeLspPluginInfo *info);
+void ide_lsp_plugin_remove_plugin_info_param (guint *n_parameters,
+ GParameter *parameters);
+GObject *ide_lsp_plugin_create_code_action_provider (guint n_parameters,
+ GParameter *parameters,
+ IdeLspPluginInfo *info);
+GObject *ide_lsp_plugin_create_completion_provider (guint n_parameters,
+ GParameter *parameters,
+ IdeLspPluginInfo *info);
+GObject *ide_lsp_plugin_create_diagnostic_provider (guint n_parameters,
+ GParameter *parameters,
+ IdeLspPluginInfo *info);
+GObject *ide_lsp_plugin_create_formatter (guint n_parameters,
+ GParameter *parameters,
+ IdeLspPluginInfo *info);
+GObject *ide_lsp_plugin_create_highlighter (guint n_parameters,
+ GParameter *parameters,
+ IdeLspPluginInfo *info);
+GObject *ide_lsp_plugin_create_hover_provider (guint n_parameters,
+ GParameter *parameters,
+ IdeLspPluginInfo *info);
+GObject *ide_lsp_plugin_create_rename_provider (guint n_parameters,
+ GParameter *parameters,
+ IdeLspPluginInfo *info);
+GObject *ide_lsp_plugin_create_symbol_resolver (guint n_parameters,
+ GParameter *parameters,
+ IdeLspPluginInfo *info);
G_GNUC_END_IGNORE_DEPRECATIONS
G_END_DECLS
diff --git a/src/libide/lsp/ide-lsp-plugin.c b/src/libide/lsp/ide-lsp-plugin.c
index 719981fe3..0d8562576 100644
--- a/src/libide/lsp/ide-lsp-plugin.c
+++ b/src/libide/lsp/ide-lsp-plugin.c
@@ -187,27 +187,6 @@ ide_lsp_plugin_register_service_gtype (IdeLspPluginInfo *info)
return g_type_register_static (IDE_TYPE_LSP_SERVICE, type_name, &type_info, G_TYPE_FLAG_FINAL);
}
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-
-static GObject *
-ide_lsp_plugin_factory (IdeLspPluginInfo *info,
- GType type,
- guint n_parameters,
- GParameter *parameters)
-{
- return NULL;
-}
-
-static GObject *
-ide_lsp_plugin_code_action_factory (guint n_parameters,
- GParameter *parameters,
- gpointer user_data)
-{
- return ide_lsp_plugin_factory (user_data, IDE_TYPE_LSP_CODE_ACTION_PROVIDER, n_parameters, parameters);
-}
-
-G_GNUC_END_IGNORE_DEPRECATIONS
-
static void
ide_lsp_plugin_register (PeasObjectModule *object_module,
IdeLspPluginFeatures features,
@@ -283,7 +262,7 @@ ide_lsp_plugin_register (PeasObjectModule *object_module,
if ((features & IDE_LSP_PLUGIN_FEATURES_CODE_ACTION) != 0)
peas_object_module_register_extension_factory (object_module,
IDE_TYPE_CODE_ACTION_PROVIDER,
- ide_lsp_plugin_code_action_factory,
+
(PeasFactoryFunc)ide_lsp_plugin_create_code_action_provider,
ide_lsp_plugin_info_ref (info),
(GDestroyNotify)ide_lsp_plugin_info_unref);
}
diff --git a/src/libide/lsp/meson.build b/src/libide/lsp/meson.build
index 1612b531f..0073aa457 100644
--- a/src/libide/lsp/meson.build
+++ b/src/libide/lsp/meson.build
@@ -56,6 +56,7 @@ libide_lsp_public_sources = [
'ide-lsp-highlighter.c',
'ide-lsp-hover-provider.c',
'ide-lsp-plugin.c',
+ 'ide-lsp-plugin-code-action-provider.c',
'ide-lsp-plugin-completion-provider.c',
'ide-lsp-plugin-diagnostic-provider.c',
'ide-lsp-plugin-formatter.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]