[gnome-builder/wip/chergert/lsp-plugin-loader: 15/24] plugins/zls: add ziglang language server support




commit d2dcfe9c05216de503c8ee22345b51b10bd28e8e
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 14 11:17:58 2022 -0500

    plugins/zls: add ziglang language server support
    
    Also registers a zig.lang until that is something suitable to move upstream
    into GtkSourceView.

 meson_options.txt                 |   1 +
 src/plugins/meson.build           |   2 +
 src/plugins/zls/meson.build       |  11 +++
 src/plugins/zls/settings.json     |   4 +
 src/plugins/zls/zig.lang          | 154 ++++++++++++++++++++++++++++++++++++++
 src/plugins/zls/zls.gresource.xml |  10 +++
 src/plugins/zls/zls.plugin        |  19 +++++
 7 files changed, 201 insertions(+)
---
diff --git a/meson_options.txt b/meson_options.txt
index 6858e5a6e..e6de9ef10 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -91,3 +91,4 @@ option('plugin_valgrind', type: 'boolean')
 option('plugin_waf', type: 'boolean')
 option('plugin_words', type: 'boolean')
 option('plugin_xml_pack', type: 'boolean')
+option('plugin_zls', type: 'boolean')
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index 5fcd43a50..b6135228d 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -146,6 +146,7 @@ subdir('waf')
 subdir('web-browser')
 subdir('words')
 subdir('xml-pack')
+subdir('zls')
 
 plugins = static_library('plugins', plugins_sources,
          dependencies: plugins_deps,
@@ -232,6 +233,7 @@ status += [
   'rust-analyzer ................. (Rust) : @0@'.format(get_option('plugin_rust_analyzer')),
   'ts-language-server ... (JS/TypeScript) : @0@'.format(get_option('plugin_ts_language_server')),
   'vala-language-server .......... (Vala) : @0@'.format(get_option('plugin_vala_language_server')),
+  'zls ........................ (Ziglang) : @0@'.format(get_option('plugin_zls')),
   '',
   ' ** Denotes plugins not recommended for distribution',
   '',
diff --git a/src/plugins/zls/meson.build b/src/plugins/zls/meson.build
new file mode 100644
index 000000000..12bfd0947
--- /dev/null
+++ b/src/plugins/zls/meson.build
@@ -0,0 +1,11 @@
+if get_option('plugin_zls')
+
+plugin_zls_resources = gnome.compile_resources(
+  'zls-resources',
+  'zls.gresource.xml',
+  c_name: 'gbp_zls',
+)
+
+plugins_sources += plugin_zls_resources
+
+endif
diff --git a/src/plugins/zls/settings.json b/src/plugins/zls/settings.json
new file mode 100644
index 000000000..93fde01bd
--- /dev/null
+++ b/src/plugins/zls/settings.json
@@ -0,0 +1,4 @@
+{
+  "zls" : {
+  }
+}
diff --git a/src/plugins/zls/zig.lang b/src/plugins/zls/zig.lang
new file mode 100644
index 000000000..795841521
--- /dev/null
+++ b/src/plugins/zls/zig.lang
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<language id="zig" name="Zig" version="2.0" _section="Source">
+  <metadata>
+    <property name="globs">*.zig</property>
+    <property name="line-comment-start">//</property>
+  </metadata>
+
+  <styles>
+    <style id="boolean"           name="Boolean"               map-to="def:boolean"/>
+    <style id="builtin"           name="Builtins"              map-to="def:builtin"/>
+    <style id="comment"           name="Comment"               map-to="def:comment"/>
+    <style id="decimal"           name="Decimal"               map-to="def:decimal"/>
+    <style id="escaped-character" name="Escaped Character"     map-to="def:special-char"/>
+    <style id="import"            name="Escaped Character"     map-to="def:special-char"/>
+    <style id="keyword"           name="Keyword"               map-to="def:keyword"/>
+    <style id="string"            name="String"                map-to="def:string"/>
+    <style id="type"              name="Type"                  map-to="def:type"/>
+    <style id="value"             name="Value"                 map-to="def:special-constant"/>
+  </styles>
+
+  <definitions>
+
+    <context id="decimal" style-ref="decimal">
+      <match extended="true">
+        (?&lt;![\w\.])
+        (0|[1-9][0-9]*)[uUlL]*
+        (?![\w\.])
+      </match>
+    </context>
+
+    <define-regex id="escaped-character" extended="true">
+      \\(                   # leading backslash
+      [\\\"\'nrbtfav\?] |   # escaped character
+      [0-7]{1,3} |          # one, two, or three octal digits
+      x[0-9A-Fa-f]+ |       # 'x' followed by hex digits
+      u\{[0-9A-Fa-f]{4}\}   # 'u' followed by 4 hex digits inside {}
+      )
+    </define-regex>
+
+    <context id="string" style-ref="string" end-at-line-end="true" class="string" 
class-disabled="no-spell-check">
+      <start>"</start>
+      <end>"</end>
+      <include>
+        <context id="escaped-character" style-ref="escaped-character">
+          <match>\%{escaped-character}</match>
+        </context>
+      </include>
+    </context>
+
+    <context id="keywords" style-ref="keyword">
+      <keyword>align</keyword>
+      <keyword>allowzero</keyword>
+      <keyword>and</keyword>
+      <keyword>anyframe</keyword>
+      <keyword>anytype</keyword>
+      <keyword>asm</keyword>
+      <keyword>async</keyword>
+      <keyword>await</keyword>
+      <keyword>break</keyword>
+      <keyword>catch</keyword>
+      <keyword>comptime</keyword>
+      <keyword>const</keyword>
+      <keyword>continue</keyword>
+      <keyword>defer</keyword>
+      <keyword>else</keyword>
+      <keyword>enum</keyword>
+      <keyword>errdefer</keyword>
+      <keyword>error</keyword>
+      <keyword>export</keyword>
+      <keyword>extern</keyword>
+      <keyword>fn</keyword>
+      <keyword>for</keyword>
+      <keyword>if</keyword>
+      <keyword>inline</keyword>
+      <keyword>noalias</keyword>
+      <keyword>nosuspend</keyword>
+      <keyword>or</keyword>
+      <keyword>orelse</keyword>
+      <keyword>packed</keyword>
+      <keyword>pub</keyword>
+      <keyword>resume</keyword>
+      <keyword>return</keyword>
+      <keyword>linksection</keyword>
+      <keyword>struct</keyword>
+      <keyword>suspend</keyword>
+      <keyword>switch</keyword>
+      <keyword>test</keyword>
+      <keyword>threadlocal</keyword>
+      <keyword>try</keyword>
+      <keyword>union</keyword>
+      <keyword>unreachable</keyword>
+      <keyword>usingnamespace</keyword>
+      <keyword>var</keyword>
+      <keyword>volatile</keyword>
+      <keyword>while</keyword>
+    </context>
+
+    <context id="boolean" style-ref="boolean">
+      <keyword>true</keyword>
+      <keyword>false</keyword>
+    </context>
+
+    <context id="types" style-ref="type">
+      <keyword>u8</keyword>
+      <keyword>u16</keyword>
+      <keyword>u32</keyword>
+      <keyword>u64</keyword>
+      <keyword>u128</keyword>
+      <keyword>i8</keyword>
+      <keyword>i16</keyword>
+      <keyword>i32</keyword>
+      <keyword>i64</keyword>
+      <keyword>i128</keyword>
+      <keyword>isize</keyword>
+      <keyword>usize</keyword>
+      <keyword>f16</keyword>
+      <keyword>f32</keyword>
+      <keyword>f64</keyword>
+      <keyword>f80</keyword>
+      <keyword>f128</keyword>
+      <keyword>bool</keyword>
+      <keyword>anyopaque</keyword>
+      <keyword>void</keyword>
+      <keyword>noreturn</keyword>
+      <keyword>type</keyword>
+      <keyword>anyerror</keyword>
+      <keyword>comptime_int</keyword>
+      <keyword>comptime_float</keyword>
+    </context>
+
+    <context id="values" style-ref="value">
+      <keyword>null</keyword>
+      <keyword>undefined</keyword>
+    </context>
+
+    <context id="builtins" style-ref="builtin">
+      <match>@[_a-zA-Z][_a-zA-Z0-9]*</match>
+    </context>
+
+    <context id="zig" class="no-spell-check">
+      <include>
+        <context ref="def:c-like-comment" style-ref="comment"/>
+        <context ref="keywords"/>
+        <context ref="boolean"/>
+        <context ref="values"/>
+        <context ref="types"/>
+        <context ref="string"/>
+        <context ref="decimal"/>
+        <context ref="builtins"/>
+      </include>
+    </context>
+  </definitions>
+</language>
+
diff --git a/src/plugins/zls/zls.gresource.xml b/src/plugins/zls/zls.gresource.xml
new file mode 100644
index 000000000..f0e64f7d7
--- /dev/null
+++ b/src/plugins/zls/zls.gresource.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/plugins/zls">
+    <file>zls.plugin</file>
+    <file>settings.json</file>
+  </gresource>
+  <gresource prefix="/org/gnome/builder/gtksourceview/language-specs">
+    <file>zig.lang</file>
+  </gresource>
+</gresources>
diff --git a/src/plugins/zls/zls.plugin b/src/plugins/zls/zls.plugin
new file mode 100644
index 000000000..4ef65ea6e
--- /dev/null
+++ b/src/plugins/zls/zls.plugin
@@ -0,0 +1,19 @@
+[Plugin]
+Authors=Christian Hergert
+Copyright=Copyright 2022 Christian Hergert
+Description=Zig code intelligence provided by zls
+Embedded=ide_lsp_plugin_register_types
+Module=zls
+Name=Zig Language Server
+X-Category=lsps
+X-Code-Action-Languages=zig
+X-Completion-Provider-Languages=zig
+X-Diagnostic-Provider-Languages=zig
+X-Formatter-Languages=zig
+X-Highlighter-Languages=zig
+X-Hover-Provider-Languages=zig
+X-LSP-Command=zls
+X-LSP-Languages=zig
+X-LSP-Settings=settings.json
+X-Rename-Provider-Languages=zig
+X-Symbol-Resolver-Languages=zig


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