[gnome-builder] plugins/glsl-language-server: add support for glsl-language-server



commit ef9a75dac7572c080918a81595a4ee4b6fc8db67
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 5 18:02:02 2022 -0700

    plugins/glsl-language-server: add support for glsl-language-server
    
    It only handles diagnostics currently, but that is enough to be useful.
    
    Note that this doesn't support GTK's style of "joined fragment and vertex
    shaders" because glsl-language-server can't identify/split them into
    separate shaders.
    
    Fixes #306

 meson_options.txt                                  |  1 +
 .../gbp-glsl-diagnostic-provider.c                 | 65 ++++++++++++++++++
 .../gbp-glsl-diagnostic-provider.h                 | 31 +++++++++
 .../glsl-language-server/gbp-glsl-service.c        | 80 ++++++++++++++++++++++
 .../glsl-language-server/gbp-glsl-service.h        | 31 +++++++++
 .../glsl-language-server-plugin.c                  | 40 +++++++++++
 .../glsl-language-server.gresource.xml             |  6 ++
 .../glsl-language-server.plugin                    | 16 +++++
 src/plugins/glsl-language-server/meson.build       | 17 +++++
 src/plugins/meson.build                            |  2 +
 10 files changed, 289 insertions(+)
---
diff --git a/meson_options.txt b/meson_options.txt
index 572c67d68..710956644 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -41,6 +41,7 @@ option('plugin_gdb', type: 'boolean')
 option('plugin_gdiagnose', type: 'boolean')
 option('plugin_gettext', type: 'boolean')
 option('plugin_git', type: 'boolean')
+option('plugin_glsl_language_server', type: 'boolean')
 option('plugin_gopls', type: 'boolean')
 option('plugin_gradle', type: 'boolean')
 option('plugin_grep', type: 'boolean')
diff --git a/src/plugins/glsl-language-server/gbp-glsl-diagnostic-provider.c 
b/src/plugins/glsl-language-server/gbp-glsl-diagnostic-provider.c
new file mode 100644
index 000000000..b07bdd428
--- /dev/null
+++ b/src/plugins/glsl-language-server/gbp-glsl-diagnostic-provider.c
@@ -0,0 +1,65 @@
+/* gbp-glsl-diagnostic-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 "gbp-glsl-diagnostic-provider"
+
+#include "config.h"
+
+#include "gbp-glsl-diagnostic-provider.h"
+#include "gbp-glsl-service.h"
+
+struct _GbpGlslDiagnosticProvider
+{
+  IdeLspDiagnosticProvider parent_instance;
+};
+
+static void
+gbp_glsl_diagnostic_provider_load (IdeDiagnosticProvider *provider)
+{
+  g_autoptr(IdeLspServiceClass) klass = NULL;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_GLSL_DIAGNOSTIC_PROVIDER (provider));
+
+  klass = g_type_class_ref (GBP_TYPE_GLSL_SERVICE);
+  ide_lsp_service_class_bind_client (klass, IDE_OBJECT (provider));
+
+  IDE_EXIT;
+}
+
+static void
+diagnostic_provider_iface_init (IdeDiagnosticProviderInterface *iface)
+{
+  iface->load = gbp_glsl_diagnostic_provider_load;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpGlslDiagnosticProvider, gbp_glsl_diagnostic_provider, 
IDE_TYPE_LSP_DIAGNOSTIC_PROVIDER,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_DIAGNOSTIC_PROVIDER, 
diagnostic_provider_iface_init))
+
+static void
+gbp_glsl_diagnostic_provider_class_init (GbpGlslDiagnosticProviderClass *klass)
+{
+}
+
+static void
+gbp_glsl_diagnostic_provider_init (GbpGlslDiagnosticProvider *self)
+{
+}
diff --git a/src/plugins/glsl-language-server/gbp-glsl-diagnostic-provider.h 
b/src/plugins/glsl-language-server/gbp-glsl-diagnostic-provider.h
new file mode 100644
index 000000000..5ee6bf510
--- /dev/null
+++ b/src/plugins/glsl-language-server/gbp-glsl-diagnostic-provider.h
@@ -0,0 +1,31 @@
+/* gbp-glsl-diagnostic-provider.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 <libide-lsp.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_GLSL_DIAGNOSTIC_PROVIDER (gbp_glsl_diagnostic_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpGlslDiagnosticProvider, gbp_glsl_diagnostic_provider, GBP, 
GLSL_DIAGNOSTIC_PROVIDER, IdeLspDiagnosticProvider)
+
+G_END_DECLS
diff --git a/src/plugins/glsl-language-server/gbp-glsl-service.c 
b/src/plugins/glsl-language-server/gbp-glsl-service.c
new file mode 100644
index 000000000..0a93ee0b8
--- /dev/null
+++ b/src/plugins/glsl-language-server/gbp-glsl-service.c
@@ -0,0 +1,80 @@
+/* gbp-glsl-service.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-glsl-service"
+
+#include "config.h"
+
+#include <jsonrpc-glib.h>
+
+#include "gbp-glsl-service.h"
+
+struct _GbpGlslService
+{
+  IdeLspService parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GbpGlslService, gbp_glsl_service, IDE_TYPE_LSP_SERVICE)
+
+static void
+gbp_glsl_service_configure_client (IdeLspService *service,
+                                   IdeLspClient  *client)
+{
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_GLSL_SERVICE (service));
+  g_assert (IDE_IS_LSP_CLIENT (client));
+
+  /* There doesn't currently seem to be a language identifier for glsl */
+  ide_lsp_client_add_language (client, "glsl");
+
+  IDE_EXIT;
+}
+
+static void
+gbp_glsl_service_prepare_run_context (IdeLspService *service,
+                                      IdePipeline   *pipeline,
+                                      IdeRunContext *run_context)
+{
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_GLSL_SERVICE (service));
+  g_assert (IDE_IS_PIPELINE (pipeline));
+  g_assert (IDE_IS_RUN_CONTEXT (run_context));
+
+  ide_run_context_append_argv (run_context, "--stdin");
+
+  IDE_EXIT;
+}
+
+static void
+gbp_glsl_service_class_init (GbpGlslServiceClass *klass)
+{
+  IdeLspServiceClass *lsp_service_class = IDE_LSP_SERVICE_CLASS (klass);
+
+  lsp_service_class->configure_client = gbp_glsl_service_configure_client;
+  lsp_service_class->prepare_run_context = gbp_glsl_service_prepare_run_context;
+}
+
+static void
+gbp_glsl_service_init (GbpGlslService *self)
+{
+  ide_lsp_service_set_program (IDE_LSP_SERVICE (self), "glslls");
+}
diff --git a/src/plugins/glsl-language-server/gbp-glsl-service.h 
b/src/plugins/glsl-language-server/gbp-glsl-service.h
new file mode 100644
index 000000000..8cd9724d7
--- /dev/null
+++ b/src/plugins/glsl-language-server/gbp-glsl-service.h
@@ -0,0 +1,31 @@
+/* gbp-glsl-service.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 <libide-lsp.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_GLSL_SERVICE (gbp_glsl_service_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpGlslService, gbp_glsl_service, GBP, GLSL_SERVICE, IdeLspService)
+
+G_END_DECLS
diff --git a/src/plugins/glsl-language-server/glsl-language-server-plugin.c 
b/src/plugins/glsl-language-server/glsl-language-server-plugin.c
new file mode 100644
index 000000000..defd5fd22
--- /dev/null
+++ b/src/plugins/glsl-language-server/glsl-language-server-plugin.c
@@ -0,0 +1,40 @@
+/* glsl-language-server-plugin.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 "glsl-language-server-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-code.h>
+#include <libide-foundry.h>
+#include <libide-lsp.h>
+
+#include "gbp-glsl-service.h"
+#include "gbp-glsl-diagnostic-provider.h"
+
+_IDE_EXTERN void
+_gbp_glsl_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_DIAGNOSTIC_PROVIDER,
+                                              GBP_TYPE_GLSL_DIAGNOSTIC_PROVIDER);
+}
diff --git a/src/plugins/glsl-language-server/glsl-language-server.gresource.xml 
b/src/plugins/glsl-language-server/glsl-language-server.gresource.xml
new file mode 100644
index 000000000..98f622169
--- /dev/null
+++ b/src/plugins/glsl-language-server/glsl-language-server.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/glsl-language-server">
+    <file>glsl-language-server.plugin</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/glsl-language-server/glsl-language-server.plugin 
b/src/plugins/glsl-language-server/glsl-language-server.plugin
new file mode 100644
index 000000000..d664db334
--- /dev/null
+++ b/src/plugins/glsl-language-server/glsl-language-server.plugin
@@ -0,0 +1,16 @@
+[Plugin]
+Builtin=true
+Copyright=Copyright © 2022 Christian Hergert
+Description=Provides integration with glsl-language-server
+Embedded=_gbp_glsl_register_types
+Module=glsl-language-server
+Name=GLSL Language Server
+X-Category=lsps
+X-Completion-Provider-Languages=glsl
+X-Symbol-Resolver-Languages=glsl
+X-Diagnostic-Provider-Languages=glsl
+X-Highlighter-Languages=glsl
+X-Hover-Provider-Languages=glsl
+X-Rename-Provider-Languages=glsl
+X-Formatter-Languages=glsl
+X-Code-Action-Languages=glsl
diff --git a/src/plugins/glsl-language-server/meson.build b/src/plugins/glsl-language-server/meson.build
new file mode 100644
index 000000000..3b362f513
--- /dev/null
+++ b/src/plugins/glsl-language-server/meson.build
@@ -0,0 +1,17 @@
+if get_option('plugin_glsl_language_server')
+
+plugins_sources += files([
+  'glsl-language-server-plugin.c',
+  'gbp-glsl-diagnostic-provider.c',
+  'gbp-glsl-service.c',
+])
+
+plugin_glsl_resources = gnome.compile_resources(
+  'glsl-language-server-resources',
+  'glsl-language-server.gresource.xml',
+  c_name: 'gbp_glsl',
+)
+
+plugins_sources += plugin_glsl_resources
+
+endif
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 048cf31d8..fc37b2ce8 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -72,6 +72,7 @@ subdir('gdb')
 subdir('gdiagnose')
 subdir('gettext')
 subdir('git')
+subdir('glsl-language-server')
 subdir('gopls')
 subdir('gradle')
 subdir('greeter')
@@ -217,6 +218,7 @@ status += [
   'bash-language-server .......... (Bash) : @0@'.format(get_option('plugin_bash_language_server')),
   'blueprint ................ (Blueprint) : @0@'.format(get_option('plugin_blueprint')),
   'clangd ............... (C, C++, Obj-C) : @0@ **'.format(get_option('plugin_clangd')),
+  'glsl-language-server .......... (GLSL) : @0@'.format(get_option('plugin_glsl_language_server')),
   'gnome-builder-clang .. (C, C++, Obj-C) : @0@'.format(get_option('plugin_clang')),
   'gopls ........................... (Go) : @0@'.format(get_option('plugin_gopls')),
   'intelephense ................... (PHP) : @0@'.format(get_option('plugin_intelephense')),


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