[gnome-builder] plugin: blueprint: Add the blueprint plugin



commit 97004c1d6e357a3af42ad13537b75b3511fb7c08
Author: James Westman <james jwestman net>
Date:   Wed Dec 1 15:24:18 2021 -0600

    plugin: blueprint: Add the blueprint plugin
    
    Adds a language server and syntax highlighting for the blueprint markup
    language.

 build-aux/flatpak/org.gnome.Builder.json  |  11 ++
 meson_options.txt                         |   1 +
 src/plugins/blueprint/blueprint.lang      | 256 ++++++++++++++++++++++++++++++
 src/plugins/blueprint/blueprint.plugin    |  12 ++
 src/plugins/blueprint/blueprint_plugin.py |  38 +++++
 src/plugins/blueprint/meson.build         |  16 ++
 src/plugins/meson.build                   |   1 +
 7 files changed, 335 insertions(+)
---
diff --git a/build-aux/flatpak/org.gnome.Builder.json b/build-aux/flatpak/org.gnome.Builder.json
index c6c2fa862..5d530b9c2 100644
--- a/build-aux/flatpak/org.gnome.Builder.json
+++ b/build-aux/flatpak/org.gnome.Builder.json
@@ -644,6 +644,17 @@
             ]
         },
         "typescript-language-server.json",
+        {
+            "name" : "blueprint-compiler",
+            "buildsystem" : "meson",
+            "sources" : [
+                {
+                    "type" : "git",
+                    "url" : "https://gitlab.gnome.org/jwestman/blueprint-compiler.git";,
+                    "branch" : "main"
+                }
+            ]
+        },
         {
             "name" : "gnome-builder",
             "buildsystem" : "meson",
diff --git a/meson_options.txt b/meson_options.txt
index 1d29f22ac..53f189304 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -21,6 +21,7 @@ option('ctags_path', type: 'string', value: '')
 
 option('plugin_autotools', type: 'boolean')
 option('plugin_beautifier', type: 'boolean')
+option('plugin_blueprint', type: 'boolean')
 option('plugin_c_pack', type: 'boolean')
 option('plugin_cargo', type: 'boolean')
 option('plugin_clang', type: 'boolean')
diff --git a/src/plugins/blueprint/blueprint.lang b/src/plugins/blueprint/blueprint.lang
new file mode 100644
index 000000000..6fc1c74b6
--- /dev/null
+++ b/src/plugins/blueprint/blueprint.lang
@@ -0,0 +1,256 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<language id="blueprint" name="Blueprint" version="2.0" _section="Other">
+  <metadata>
+    <property name="globs">*.blp</property>
+    <property name="block-comment-start">/*</property>
+    <property name="block-comment-end">*/</property>
+    <property name="line-comment-start">//</property>
+  </metadata>
+
+  <styles>
+
+    <!-- global -->
+    <style id="comment"                     name="Comment"                     map-to="def:comment"/>
+    <style id="translator"                  name="Translator Comment"          map-to="def:emphasis"/>
+    <style id="keyword"                     name="Keyword"                     map-to="def:keyword"/>
+    <style id="external"                    name="External"                    map-to="def:inline-code"/>
+    <style id="object_id"                   name="Object ID"                   map-to="def:inline-code"/>
+    <style id="namespace"                   name="Namespace"                   map-to="def:type"/>
+    <style id="class"                       name="Class"                       map-to="def:type"/>
+    <style id="property"                    name="Property"                    map-to="def:identifier"/>
+    <style id="signal"                      name="Signal"                      map-to="def:identifier"/>
+    <style id="identifier"                  name="Identifier"                  map-to="def:identifier"/>
+    <style id="child_type"                  name="Child Type"                  map-to="def:identifier"/>
+
+    <!-- data types -->
+    <style id="escape"                      name="Escape Sequence"             map-to="def:special-char"/>
+    <style id="string"                      name="String"                      map-to="def:string"/>
+    <style id="boolean"                     name="Boolean"                     map-to="def:boolean"/>
+    <style id="number"                      name="Number"                      map-to="def:number"/>
+    <style id="integer"                     name="Integer"                     map-to="def:decimal"/>
+  </styles>
+
+  <definitions>
+    <define-regex id="ident">[A-Za-z_][\d\w\-_]*</define-regex>
+    <define-regex id="quoted">("(\\"|[^"\n])+"|'(\\'|[^'\n])+')</define-regex>
+    <define-regex id="number">([-+]?\d[\d_]*(\.\d[\d_]*)?|0x[A-Fa-f0-9]+)</define-regex>
+    <define-regex id="comment">(/\*[\s\S]*\*/|\/\/[^\n]*)</define-regex>
+    <define-regex id="op">[:=\.=\|&lt;&gt;\+\-/\*]+</define-regex>
+    <define-regex id="escape">\\n|\\"|\\'</define-regex>
+    <define-regex id="block_keyword">accessibility|layout|attributes|menu|submenu|item|section</define-regex>
+
+    <context id="using">
+      <match extended="true">
+        (using)
+        \s+
+        (\%{ident})
+        \s+
+        (\%{number})
+      </match>
+      <include>
+        <context sub-pattern="1" style-ref="keyword"/>
+        <context sub-pattern="2" style-ref="namespace"/>
+        <context sub-pattern="3" style-ref="namespace"/>
+      </include>
+    </context>
+
+    <context id="value">
+      <include>
+        <context ref="child"/>
+        <context id="bool" style-ref="boolean">
+          <match>true|false</match>
+        </context>
+        <context id="number" style-ref="number">
+          <match>\%{number}</match>
+        </context>
+        <context id="quoted" style-ref="string">
+          <start>"</start>
+          <end>"</end>
+          <include>
+            <context id="escape" style-ref="escape">
+              <match>\%{escape}</match>
+            </context>
+          </include>
+        </context>
+        <context id="quoted2" style-ref="string">
+          <start>'</start>
+          <end>'</end>
+          <include>
+            <context id="escape2" style-ref="escape">
+              <match>\%{escape}</match>
+            </context>
+          </include>
+        </context>
+        <context id="ident" style-ref="identifier">
+          <match>\%{ident}</match>
+        </context>
+      </include>
+    </context>
+
+    <context id="comment">
+      <include>
+        <context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" 
class-disabled="no-spell-check">
+          <start>//</start>
+          <include>
+            <context ref="def:in-line-comment"/>
+          </include>
+        </context>
+
+        <context id="multiline-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
+          <start>/\*</start>
+          <end>\*/</end>
+          <include>
+            <context ref="def:in-comment"/>
+            <context id="translator-comment" style-ref="translator">
+              <match case-sensitive="false">translators:</match>
+            </context>
+          </include>
+        </context>
+      </include>
+    </context>
+
+    <context id="attribute">
+      <start extended="true">
+        (\%{ident})
+        \s*
+        :
+      </start>
+      <end>;</end>
+      <include>
+        <context where="start" sub-pattern="1" style-ref="property"/>
+        <context ref="keywords"/>
+        <context ref="value"/>
+      </include>
+    </context>
+
+    <context id="signal">
+      <start extended="true">
+        (\%{ident})
+        \s*
+        =>
+      </start>
+      <end>;</end>
+      <include>
+        <context where="start" sub-pattern="1" style-ref="property"/>
+        <context ref="value"/>
+        <context ref="keywords"/>
+      </include>
+    </context>
+
+    <context id="child-type" style-ref="child_type">
+      <match>\[\%{ident}\]</match>
+    </context>
+
+    <context id="template">
+      <start extended="true">
+        (template)\s*
+        (?&lt;template_id&gt;\%{ident})\s*
+        :\s*
+        ((?&lt;template_ns&gt;\%{ident})?\s*\.)?\s*
+        (?&lt;template_class&gt;\%{ident})\s*
+        {
+      </start>
+      <end>}</end>
+      <include>
+        <context where="start" sub-pattern="1" style-ref="keyword"/>
+        <context where="start" sub-pattern="template_id" style-ref="object_id"/>
+        <context where="start" sub-pattern="template_ns" style-ref="namespace"/>
+        <context where="start" sub-pattern="template_class" style-ref="class"/>
+        <context ref="block-content"/>
+      </include>
+    </context>
+
+    <context id="child">
+      <start extended="true">
+        (
+          ((?&lt;child_ns&gt;\%{ident})?\s*\.)?\s*
+          (?(?=(?&lt;child_kw&gt;\%{block_keyword}))(\%{block_keyword})|(?&lt;child_class&gt;\%{ident}))\s*
+          (?&lt;child_id&gt;\%{ident})?
+        )\s*
+        {
+      </start>
+      <end>}</end>
+      <include>
+        <context where="start" sub-pattern="child_kw" style-ref="keyword"/>
+        <context where="start" sub-pattern="child_ns" style-ref="namespace"/>
+        <context where="start" sub-pattern="child_class" style-ref="class"/>
+        <context where="start" sub-pattern="child_id" style-ref="object_id"/>
+        <context ref="block-content"/>
+      </include>
+    </context>
+
+    <context id="block-content">
+      <include>
+        <context ref="comment"/>
+        <context ref="attribute"/>
+        <context ref="signal"/>
+        <context ref="keywords"/>
+        <context ref="block"/>
+        <context ref="child-type"/>
+        <context ref="list"/>
+        <context ref="args"/>
+        <context ref="child"/>
+      </include>
+    </context>
+
+    <context id="block">
+      <start>{</start>
+      <end>}</end>
+      <include>
+        <context ref="block-content"/>
+      </include>
+    </context>
+
+    <context id="list">
+      <start>\[</start>
+      <end>\]</end>
+      <include>
+        <context ref="comment"/>
+        <context ref="value"/>
+        <context ref="keywords"/>
+      </include>
+    </context>
+
+    <context id="args">
+      <start>\(</start>
+      <end>\)</end>
+      <include>
+        <context ref="comment"/>
+        <context ref="value"/>
+        <context ref="keywords"/>
+      </include>
+    </context>
+
+    <context id="keywords" style-ref="keyword">
+      <keyword>accessibility</keyword>
+      <keyword>bind</keyword>
+      <keyword>item</keyword>
+      <keyword>items</keyword>
+      <keyword>layout</keyword>
+      <keyword>menu</keyword>
+      <keyword>patterns</keyword>
+      <keyword>section</keyword>
+      <keyword>strings</keyword>
+      <keyword>styles</keyword>
+      <keyword>submenu</keyword>
+      <keyword>suffixes</keyword>
+      <keyword>swapped</keyword>
+      <keyword>sync-create</keyword>
+      <keyword>template</keyword>
+      <keyword>mime-types</keyword>
+      <keyword>widgets</keyword>
+    </context>
+
+    <context id="blueprint" class="no-spell-check">
+      <include>
+        <context ref="comment"/>
+        <context ref="using"/>
+        <context ref="template"/>
+        <context ref="keywords"/>
+        <context ref="block"/>
+        <context ref="child"/>
+      </include>
+    </context>
+  </definitions>
+</language>
+
diff --git a/src/plugins/blueprint/blueprint.plugin b/src/plugins/blueprint/blueprint.plugin
new file mode 100644
index 000000000..8177ecbdf
--- /dev/null
+++ b/src/plugins/blueprint/blueprint.plugin
@@ -0,0 +1,12 @@
+[Plugin]
+Builtin=true
+Description=Provides language server integration for blueprint-compiler
+Hidden=true
+Loader=python3
+Module=blueprint_plugin
+Name=Blueprint Language Server Plugin
+X-Builder-ABI=@PACKAGE_ABI@
+X-Code-Action-Languages=blueprint
+X-Diagnostic-Provider-Languages=blueprint
+X-Diagnostic-Provider-Languages-Priority=100
+X-Hover-Provider-Languages=blueprint
diff --git a/src/plugins/blueprint/blueprint_plugin.py b/src/plugins/blueprint/blueprint_plugin.py
new file mode 100644
index 000000000..013357ef5
--- /dev/null
+++ b/src/plugins/blueprint/blueprint_plugin.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+import os
+import json
+import gi
+
+from gi.repository import GLib
+from gi.repository import Gio
+from gi.repository import GObject
+from gi.repository import Ide
+
+class BlueprintService(Ide.LspService):
+    def do_constructed(self):
+        self.set_inherit_stderr(True)
+
+    def do_configure_client(self, client):
+        client.add_language("blueprint")
+
+    def do_configure_launcher(self, launcher):
+        launcher.set_argv(["blueprint-compiler", "lsp"])
+
+
+class BlueprintDiagnosticProvider(Ide.LspDiagnosticProvider, Ide.DiagnosticProvider):
+    def do_load(self):
+        BlueprintService.bind_client(self)
+
+class BlueprintCompletionProvider(Ide.LspCompletionProvider, Ide.CompletionProvider):
+    def do_load(self, context):
+        BlueprintService.bind_client(self)
+
+class BlueprintHoverProvider(Ide.LspHoverProvider):
+    def do_prepare(self):
+        self.props.priority = 100
+        BlueprintService.bind_client(self)
+
+class BlueprintCodeActionProvider(Ide.LspCodeActionProvider, Ide.CodeActionProvider):
+    def do_load(self):
+        BlueprintService.bind_client(self)
diff --git a/src/plugins/blueprint/meson.build b/src/plugins/blueprint/meson.build
new file mode 100644
index 000000000..930e1017f
--- /dev/null
+++ b/src/plugins/blueprint/meson.build
@@ -0,0 +1,16 @@
+if get_option('plugin_blueprint')
+
+install_data('blueprint_plugin.py', install_dir: plugindir)
+
+configure_file(
+          input: 'blueprint.plugin',
+         output: 'blueprint.plugin',
+  configuration: config_h,
+        install: true,
+    install_dir: plugindir,
+)
+
+install_data('blueprint.lang',
+  install_dir: join_paths(get_option('datadir'), 'gtksourceview-4' / 'language-specs'))
+
+endif
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index b969848bf..9efa95505 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -39,6 +39,7 @@ endif
 subdir('auto-save')
 subdir('autotools')
 subdir('beautifier')
+subdir('blueprint')
 subdir('buildconfig')
 subdir('buildsystem')
 subdir('buildui')


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