[gnome-builder] clangd: add (disabled) clangd plugin



commit cc18cfa2902aa75c8934fb1b4813098a23e6bb18
Author: Christian Hergert <chergert redhat com>
Date:   Sat Jan 1 17:07:18 2022 -0800

    clangd: add (disabled) clangd plugin
    
    We already bundle clangd, so we might as well have the binding layer to be
    able to use it. Currently this is disabled by default, but we can look at
    enabling it if/when we are comfortable with how it works and if it can
    load all our project build system bits without issue. In particular we need
    to know it will support meson well (and that should be possible with the
    compile_commands.json as long as it discovers it).

 meson_options.txt                   |  1 +
 src/plugins/clangd/clangd.plugin    | 18 +++++++++
 src/plugins/clangd/clangd_plugin.py | 75 +++++++++++++++++++++++++++++++++++++
 src/plugins/clangd/meson.build      | 13 +++++++
 src/plugins/meson.build             |  1 +
 5 files changed, 108 insertions(+)
---
diff --git a/meson_options.txt b/meson_options.txt
index 6f160a564..d6171d7d9 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -25,6 +25,7 @@ option('plugin_blueprint', type: 'boolean')
 option('plugin_c_pack', type: 'boolean')
 option('plugin_cargo', type: 'boolean')
 option('plugin_clang', type: 'boolean')
+option('plugin_clangd', type: 'boolean', value: false)
 option('plugin_clang_format', type: 'boolean')
 option('plugin_cmake', type: 'boolean')
 option('plugin_codespell', type: 'boolean')
diff --git a/src/plugins/clangd/clangd.plugin b/src/plugins/clangd/clangd.plugin
new file mode 100644
index 000000000..a20849d7f
--- /dev/null
+++ b/src/plugins/clangd/clangd.plugin
@@ -0,0 +1,18 @@
+[Plugin]
+Builtin=true
+Copyright=Copyright © 2022 Christian Hergert
+Description=Integration with clangd
+Loader=python3
+Module=clangd_plugin
+Name=Clangd Language Server
+X-Builder-ABI=@PACKAGE_ABI@
+X-Code-Action-Languages=c,chdr,cpp,cpphdr,objc
+X-Completion-Provider-Languages=c,chdr,cpp,cpphdr,objc
+X-Diagnostic-Provider-Languages=c,chdr,cpp,cpphdr,objc
+X-Diagnostic-Provider-Languages-Priority=200
+X-Formatter-Languages=c,chdr,cpp,cpphdr,objc
+X-Highlighter-Languages=c,chdr,cpp,cpphdr,objc
+X-Hover-Provider-Languages=c,chdr,cpp,cpphdr,objc
+X-Rename-Provider-Languages=c,chdr,cpp,cpphdr,objc
+X-Symbol-Resolver-Languages=c,chdr,cpp,cpphdr,objc
+X-Symbol-Resolver-Languages-Priority=200
diff --git a/src/plugins/clangd/clangd_plugin.py b/src/plugins/clangd/clangd_plugin.py
new file mode 100644
index 000000000..0215fcce4
--- /dev/null
+++ b/src/plugins/clangd/clangd_plugin.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+#
+# clangd_plugin.py
+#
+# 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/>.
+#
+
+import gi
+
+from gi.repository import Ide
+
+# Clangd creates a .cache directory within the project
+Ide.g_file_add_ignored_pattern('.cache')
+
+class ClangdService(Ide.LspService):
+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.set_program('clangd')
+
+    def do_configure_client(self, client):
+        client.add_language('c')
+        client.add_language('cpp')
+        client.add_language('objective-c')
+        client.add_language('objective-cpp')
+
+class ClangdDiagnosticProvider(Ide.LspDiagnosticProvider, Ide.DiagnosticProvider):
+    def do_load(self):
+        ClangdService.bind_client(self)
+
+class ClangdCompletionProvider(Ide.LspCompletionProvider, Ide.CompletionProvider):
+    def do_load(self, context):
+        ClangdService.bind_client(self)
+
+    def do_get_priority(self, context):
+        return -1000
+
+class ClangdSymbolResolver(Ide.LspSymbolResolver, Ide.SymbolResolver):
+    def do_load(self):
+        ClangdService.bind_client(self)
+
+class ClangdHighlighter(Ide.LspHighlighter, Ide.Highlighter):
+    def do_load(self):
+        ClangdService.bind_client(self)
+
+class ClangdFormatter(Ide.LspFormatter, Ide.Formatter):
+    def do_load(self):
+        ClangdService.bind_client(self)
+
+class ClangdHoverProvider(Ide.LspHoverProvider, Ide.HoverProvider):
+    def do_prepare(self):
+        self.props.category = 'Clangd'
+        self.props.priority = 200
+        ClangdService.bind_client(self)
+
+class ClangdRenameProvider(Ide.LspRenameProvider, Ide.RenameProvider):
+    def do_load(self):
+        ClangdService.bind_client(self)
+
+class ClangdCodeActionProvider(Ide.LspCodeActionProvider, Ide.CodeActionProvider):
+    def do_load(self):
+        ClangdService.bind_client(self)
+
diff --git a/src/plugins/clangd/meson.build b/src/plugins/clangd/meson.build
new file mode 100644
index 000000000..37fa0441d
--- /dev/null
+++ b/src/plugins/clangd/meson.build
@@ -0,0 +1,13 @@
+if get_option('plugin_clangd')
+
+install_data('clangd_plugin.py', install_dir: plugindir)
+
+configure_file(
+          input: 'clangd.plugin',
+         output: 'clangd.plugin',
+  configuration: config_h,
+        install: true,
+    install_dir: plugindir,
+)
+
+endif
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 49220f9b6..2e3270856 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -47,6 +47,7 @@ subdir('buildui')
 subdir('buffer-monitor')
 subdir('cargo')
 subdir('clang')
+subdir('clangd')
 subdir('clang-format')
 subdir('cmake')
 subdir('codespell')


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