[gnome-builder/wip/chergert/lsp-plugin-loader] wip on custom lsp types
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/lsp-plugin-loader] wip on custom lsp types
- Date: Tue, 11 Oct 2022 15:34:34 +0000 (UTC)
commit 7428a1e77dc7a5d6ffe446e5fe291f51f7df9176
Author: Christian Hergert <chergert redhat com>
Date: Tue Oct 11 10:34:21 2022 -0500
wip on custom lsp types
.../bash-language-server.plugin | 13 +-
src/plugins/lspui/gbp-lspui-application-addin.c | 188 +++++++++++++++++++++
src/plugins/lspui/gbp-lspui-application-addin.h | 31 ++++
src/plugins/lspui/gbp-lspui-gtype.c | 60 +++++++
src/plugins/lspui/gbp-lspui-gtype.h | 30 ++++
src/plugins/lspui/lspui-plugin.c | 37 ++++
src/plugins/lspui/lspui.gresource.xml | 6 +
src/plugins/lspui/lspui.plugin | 11 ++
src/plugins/lspui/meson.build | 13 ++
src/plugins/meson.build | 1 +
10 files changed, 381 insertions(+), 9 deletions(-)
---
diff --git a/src/plugins/bash-language-server/bash-language-server.plugin
b/src/plugins/bash-language-server/bash-language-server.plugin
index 0ee5bcea1..a7e48f084 100644
--- a/src/plugins/bash-language-server/bash-language-server.plugin
+++ b/src/plugins/bash-language-server/bash-language-server.plugin
@@ -2,15 +2,10 @@
Builtin=true
Copyright=Copyright © 2021 Günther Wagner, Copyright © 2022 Christian Hergert
Description=Provides integration with bash-language-server for Bash
-Embedded=_gbp_bash_register_types
+Loader=lsp
Module=bash-language-server
Name=Bash Language Server
X-Category=lsps
-X-Completion-Provider-Languages=sh
-X-Symbol-Resolver-Languages=sh
-X-Diagnostic-Provider-Languages=sh
-X-Highlighter-Languages=sh
-X-Hover-Provider-Languages=sh
-X-Rename-Provider-Languages=sh
-X-Formatter-Languages=sh
-X-Code-Action-Languages=sh
+X-LSP-Command=bash-language-server start
+X-Lsp-Config=config.json
+X-Lsp-Languages=sh
diff --git a/src/plugins/lspui/gbp-lspui-application-addin.c b/src/plugins/lspui/gbp-lspui-application-addin.c
new file mode 100644
index 000000000..a4b0f6c44
--- /dev/null
+++ b/src/plugins/lspui/gbp-lspui-application-addin.c
@@ -0,0 +1,188 @@
+/* gbp-lspui-application-addin.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 "gbp-lspui-application-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-code.h>
+#include <libide-gui.h>
+
+#include "gbp-lspui-application-addin.h"
+#include "gbp-lspui-gtype.h"
+
+struct _GbpLspuiApplicationAddin
+{
+ GObject parent_instance;
+ GRWLock type_lock;
+ GHashTable *types;
+};
+
+typedef struct
+{
+ const char *module_name;
+ GType extension_type;
+ GType gtype;
+} TypeInfo;
+
+static guint
+type_info_hash (gconstpointer data)
+{
+ const TypeInfo *info = data;
+ return g_str_hash (info->module_name) ^ g_str_hash (G_OBJECT_TYPE_NAME (info->extension_type));
+}
+
+static gboolean
+type_info_equal (gconstpointer aptr,
+ gconstpointer bptr)
+{
+ const TypeInfo *a = aptr;
+ const TypeInfo *b = bptr;
+
+ /* module name is interned in hashtable, but not in key */
+ return a->extension_type == b->extension_type &&
+ g_str_equal (a->module_name, b->module_name);
+}
+
+static void
+type_info_free (gpointer data)
+{
+ g_free (data);
+}
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+static PeasExtension *
+gbp_lspui_application_addin_lsp_factory (PeasPluginInfo *plugin_info,
+ GType extension_type,
+ guint n_parameters,
+ GParameter *parameters,
+ gpointer user_data)
+{
+ GbpLspuiApplicationAddin *self = user_data;
+ TypeInfo *found;
+ TypeInfo key;
+
+ g_assert (GBP_IS_LSPUI_APPLICATION_ADDIN (self));
+ g_assert (plugin_info != NULL);
+
+ key.extension_type = extension_type;
+ key.module_name = peas_plugin_info_get_module_name (plugin_info);
+
+ g_rw_lock_reader_lock (&self->type_lock);
+ if (!g_hash_table_lookup_extended (self->types, &key, NULL, (gpointer *)&found))
+ found = NULL;
+ g_rw_lock_reader_unlock (&self->type_lock);
+
+ if G_UNLIKELY (found == NULL)
+ {
+ g_rw_lock_writer_lock (&self->type_lock);
+ if G_LIKELY (!g_hash_table_lookup_extended (self->types, &key, NULL, (gpointer *)&found))
+ {
+ found = g_new0 (TypeInfo, 1);
+ found->module_name = g_intern_string (key.module_name);
+ found->extension_type = extension_type;
+ found->gtype = gbp_lspui_create_extension_type (plugin_info, extension_type);
+ g_hash_table_insert (self->types, found, found);
+ }
+ g_rw_lock_writer_unlock (&self->type_lock);
+ }
+
+ g_assert (found != NULL);
+ g_assert (found->gtype == G_TYPE_INVALID || g_type_is_a (found->gtype, extension_type));
+
+ if (found->gtype == G_TYPE_INVALID)
+ return NULL;
+
+ return g_object_newv (found->gtype, n_parameters, parameters);
+}
+G_GNUC_END_IGNORE_DEPRECATIONS
+
+static void
+gbp_lspui_application_addin_handle_command_line (IdeApplicationAddin *addin,
+ IdeApplication *app,
+ GApplicationCommandLine *cmdline)
+{
+ IDE_ENTRY;
+
+ g_assert (GBP_IS_LSPUI_APPLICATION_ADDIN (addin));
+ g_assert (IDE_IS_APPLICATION (app));
+ g_assert (G_IS_APPLICATION_COMMAND_LINE (cmdline));
+
+ peas_engine_register_factory (peas_engine_get_default (),
+ "lsp",
+ gbp_lspui_application_addin_lsp_factory,
+ NULL, NULL);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_lspui_application_addin_add_option_entries (IdeApplicationAddin *addin,
+ IdeApplication *app)
+{
+ g_assert (GBP_IS_LSPUI_APPLICATION_ADDIN (addin));
+ g_assert (IDE_IS_APPLICATION (app));
+
+ g_application_add_main_option (G_APPLICATION (app),
+ "clone",
+ 0,
+ G_OPTION_FLAG_IN_MAIN,
+ G_OPTION_ARG_STRING,
+ _("Begin cloning project from URI"),
+ "URI");
+}
+
+static void
+application_addin_iface_init (IdeApplicationAddinInterface *iface)
+{
+ iface->add_option_entries = gbp_lspui_application_addin_add_option_entries;
+ iface->handle_command_line = gbp_lspui_application_addin_handle_command_line;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpLspuiApplicationAddin, gbp_lspui_application_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_APPLICATION_ADDIN,
application_addin_iface_init))
+
+static void
+gbp_lspui_application_addin_finalize (GObject *object)
+{
+ GbpLspuiApplicationAddin *self = (GbpLspuiApplicationAddin *)object;
+
+ g_clear_pointer (&self->types, g_hash_table_unref);
+ g_rw_lock_clear (&self->type_lock);
+
+ G_OBJECT_CLASS (gbp_lspui_application_addin_parent_class)->finalize (object);
+}
+
+static void
+gbp_lspui_application_addin_class_init (GbpLspuiApplicationAddinClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gbp_lspui_application_addin_finalize;
+}
+
+static void
+gbp_lspui_application_addin_init (GbpLspuiApplicationAddin *self)
+{
+ g_rw_lock_init (&self->type_lock);
+ self->types = g_hash_table_new_full (type_info_hash, type_info_equal, NULL, type_info_free);
+}
diff --git a/src/plugins/lspui/gbp-lspui-application-addin.h b/src/plugins/lspui/gbp-lspui-application-addin.h
new file mode 100644
index 000000000..c5541ee51
--- /dev/null
+++ b/src/plugins/lspui/gbp-lspui-application-addin.h
@@ -0,0 +1,31 @@
+/* gbp-lspui-application-addin.h
+ *
+ * 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
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_LSPUI_APPLICATION_ADDIN (gbp_lspui_application_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpLspuiApplicationAddin, gbp_lspui_application_addin, GBP, LSPUI_APPLICATION_ADDIN,
GObject)
+
+G_END_DECLS
diff --git a/src/plugins/lspui/gbp-lspui-gtype.c b/src/plugins/lspui/gbp-lspui-gtype.c
new file mode 100644
index 000000000..fc9475375
--- /dev/null
+++ b/src/plugins/lspui/gbp-lspui-gtype.c
@@ -0,0 +1,60 @@
+/* gbp-lspui-gtype.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 "gbp-lspui-gtype"
+
+#include "config.h"
+
+#include <libide-code.h>
+#include <libide-lsp.h>
+
+#include "gbp-lspui-gtype.h"
+
+GType
+gbp_lspui_create_extension_type (PeasPluginInfo *plugin_info,
+ GType extension_type)
+{
+ GType parent_type = G_TYPE_INVALID;
+
+ g_return_val_if_fail (plugin_info != NULL, G_TYPE_INVALID);
+ g_return_val_if_fail (g_type_is_a (extension_type, G_TYPE_OBJECT), G_TYPE_INVALID);
+
+ if (extension_type == IDE_TYPE_DIAGNOSTIC_PROVIDER)
+ parent_type = IDE_TYPE_LSP_DIAGNOSTIC_PROVIDER;
+ else if (extension_type == GTK_SOURCE_TYPE_COMPLETION_PROVIDER)
+ parent_type = IDE_TYPE_LSP_COMPLETION_PROVIDER;
+ else if (extension_type == IDE_TYPE_FORMATTER)
+ parent_type = IDE_TYPE_LSP_FORMATTER;
+ else if (extension_type == IDE_TYPE_SYMBOL_RESOLVER)
+ parent_type = IDE_TYPE_LSP_SYMBOL_RESOLVER;
+ else if (extension_type == IDE_TYPE_CODE_ACTION_PROVIDER)
+ parent_type = IDE_TYPE_LSP_CODE_ACTION_PROVIDER;
+ else if (extension_type == IDE_TYPE_RENAME_PROVIDER)
+ parent_type = IDE_TYPE_LSP_RENAME_PROVIDER;
+ else if (extension_type == GTK_SOURCE_TYPE_HOVER_PROVIDER)
+ parent_type = IDE_TYPE_LSP_HOVER_PROVIDER;
+ else if (extension_type == IDE_TYPE_HIGHLIGHTER)
+ parent_type = IDE_TYPE_LSP_HIGHLIGHTER;
+
+ if (parent_type == G_TYPE_INVALID)
+ return G_TYPE_INVALID;
+
+ return G_TYPE_INVALID;
+}
diff --git a/src/plugins/lspui/gbp-lspui-gtype.h b/src/plugins/lspui/gbp-lspui-gtype.h
new file mode 100644
index 000000000..6f83b81fc
--- /dev/null
+++ b/src/plugins/lspui/gbp-lspui-gtype.h
@@ -0,0 +1,30 @@
+/* gbp-lspui-gtype.h
+ *
+ * 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
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+GType gbp_lspui_create_extension_type (PeasPluginInfo *plugin_info,
+ GType extension_type);
+
+G_END_DECLS
diff --git a/src/plugins/lspui/lspui-plugin.c b/src/plugins/lspui/lspui-plugin.c
new file mode 100644
index 000000000..162616fe6
--- /dev/null
+++ b/src/plugins/lspui/lspui-plugin.c
@@ -0,0 +1,37 @@
+/* lspui-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
+ */
+
+#define G_LOG_DOMAIN "lspui-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-gui.h>
+
+#include "gbp-lspui-application-addin.h"
+
+_IDE_EXTERN void
+_gbp_lspui_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_APPLICATION_ADDIN,
+ GBP_TYPE_LSPUI_APPLICATION_ADDIN);
+}
diff --git a/src/plugins/lspui/lspui.gresource.xml b/src/plugins/lspui/lspui.gresource.xml
new file mode 100644
index 000000000..05b7e5db9
--- /dev/null
+++ b/src/plugins/lspui/lspui.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/plugins/lspui">
+ <file>lspui.plugin</file>
+ </gresource>
+</gresources>
diff --git a/src/plugins/lspui/lspui.plugin b/src/plugins/lspui/lspui.plugin
new file mode 100644
index 000000000..0afb962cd
--- /dev/null
+++ b/src/plugins/lspui/lspui.plugin
@@ -0,0 +1,11 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2022 Christian Hergert
+Depends=editorui;
+Description=Bridges LSP plugins into Builder
+Embedded=_gbp_lspui_register_types
+Hidden=true
+Module=lspui
+Name=LSP interface extensions
+X-At-Startup=true
diff --git a/src/plugins/lspui/meson.build b/src/plugins/lspui/meson.build
new file mode 100644
index 000000000..4cc9250bd
--- /dev/null
+++ b/src/plugins/lspui/meson.build
@@ -0,0 +1,13 @@
+plugins_sources += files([
+ 'lspui-plugin.c',
+ 'gbp-lspui-application-addin.c',
+ 'gbp-lspui-gtype.c',
+])
+
+plugin_lspui_resources = gnome.compile_resources(
+ 'lspui-resources',
+ 'lspui.gresource.xml',
+ c_name: 'gbp_lspui',
+)
+
+plugins_sources += plugin_lspui_resources
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index ef0ae4fe6..8985b876e 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -85,6 +85,7 @@ subdir('jdtls')
subdir('jedi-language-server')
subdir('jhbuild')
subdir('ls')
+subdir('lspui')
subdir('lua-language-server')
subdir('make')
subdir('make-templates')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]