Unnamed repository; edit this file 'description' to name the repository.
Add `styx` language (#15226)
[styx](https://styx.bearcove.eu/) is a document language. tree-sitter queries are based on the ones provided by the language project itself and then modified and extended to work with Helix.
Kristoffer Plagborg Bak Sørensen 4 months ago
parent 5287e43 · commit 712a4a6
-rw-r--r--book/src/generated/lang-support.md1
-rw-r--r--languages.toml21
-rw-r--r--runtime/queries/styx/highlights.scm42
-rw-r--r--runtime/queries/styx/indents.scm2
-rw-r--r--runtime/queries/styx/injections.scm9
-rw-r--r--runtime/queries/styx/rainbows.scm9
-rw-r--r--runtime/queries/styx/textobjects.scm6
7 files changed, 90 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 8da72615..e17d83a4 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -273,6 +273,7 @@
| starlark | ✓ | ✓ | ✓ | | ✓ | `starpls` |
| strace | ✓ | | | | | |
| strictdoc | ✓ | | | ✓ | | |
+| styx | ✓ | ✓ | ✓ | | ✓ | `styx` |
| supercollider | ✓ | | | | | |
| svelte | ✓ | ✓ | ✓ | | ✓ | `svelteserver` |
| sway | ✓ | ✓ | ✓ | | | `forc` |
diff --git a/languages.toml b/languages.toml
index 37201559..8094641f 100644
--- a/languages.toml
+++ b/languages.toml
@@ -139,6 +139,7 @@ solc = { command = "solc", args = ["--lsp"] }
sourcekit-lsp = { command = "sourcekit-lsp" }
spade-language-server = {command = "spade-language-server"}
starpls = {command = "starpls"}
+styx = { command = "styx", args = ["lsp"] }
svlangserver = { command = "svlangserver", args = [], config.systemverilog.includeIndexing = ["*.{v,vh,sv,svh}", "**/*.{v,vh,sv,svh}"] }
swipl = { command = "swipl", args = [ "-g", "use_module(library(lsp_server))", "-g", "lsp_server:main", "-t", "halt", "--", "stdio" ] }
superhtml = { command = "superhtml", args = ["lsp"]}
@@ -5317,6 +5318,26 @@ indent = { tab-width = 4, unit=" "}
name = "klog"
source = { git = "https://github.com/Ansimorph/tree-sitter-klog/", rev = "0b215fe75bdeb8368546e3cee36aca8c19212d06" }
+[[language]]
+name = "styx"
+scope = "source.styx"
+injection-regex = "styx"
+file-types = ["styx"]
+comment-tokens = ["//", "///"]
+language-servers = ["styx"]
+indent = { tab-width = 2, unit = " " }
+auto-format = true
+
+[language.auto-pairs]
+'(' = ')'
+'{' = '}'
+'"' = '"'
+"'" = "'"
+
+[[grammar]]
+name = "styx"
+source = { git = "https://github.com/bearcove/styx", subpath = "crates/tree-sitter-styx" , rev = "ff7f49629a20a308111810a0c5e6228617133ea7" }
+
# https://docs.tilt.dev/editor.html
[[language]]
name = "tilt"
diff --git a/runtime/queries/styx/highlights.scm b/runtime/queries/styx/highlights.scm
new file mode 100644
index 00000000..eff20bd1
--- /dev/null
+++ b/runtime/queries/styx/highlights.scm
@@ -0,0 +1,42 @@
+(line_comment) @comment.line
+(doc_comment) @comment.line.documentation
+
+(escape_sequence) @constant.character.escape
+
+(bare_scalar) @string
+(quoted_scalar) @string
+(raw_scalar) @string
+(heredoc) @string
+
+; Heredoc language hint (metadata)
+(heredoc_lang) @label
+
+(unit) @constant.builtin
+
+; Tags - styled same as unit since @ is the tag sigil
+(tag) @constant.builtin
+
+; Attributes - key in attribute syntax
+; Use @keyword or @punctuation.special to make > stand out
+(attribute
+ key: (bare_scalar) @variable.other.member
+ ">" @keyword)
+
+; Keys in entries - any scalar in the key position (overrides @string above)
+(entry
+ key: (expr
+ payload: (scalar (_) @variable.other.member)))
+
+; Sequence items are values, not keys (must come AFTER entry key rule to override)
+(sequence
+ (expr
+ payload: (scalar (_) @string)))
+
+[
+ "{"
+ "}"
+ "("
+ ")"
+] @punctuation.bracket
+
+"," @punctuation.delimiter
diff --git a/runtime/queries/styx/indents.scm b/runtime/queries/styx/indents.scm
new file mode 100644
index 00000000..b61157a0
--- /dev/null
+++ b/runtime/queries/styx/indents.scm
@@ -0,0 +1,2 @@
+(object "}" @end) @indent
+(sequence ")" @end) @indent
diff --git a/runtime/queries/styx/injections.scm b/runtime/queries/styx/injections.scm
new file mode 100644
index 00000000..4e79fd18
--- /dev/null
+++ b/runtime/queries/styx/injections.scm
@@ -0,0 +1,9 @@
+([(line_comment) (doc_comment)] @injection.content
+ (#set! injection.language "comment"))
+
+; Heredocs can specify a language: <<SQL,sql
+; The heredoc_lang node captures the language name (e.g., "sql")
+; The heredoc_content node contains the actual content to highlight
+(heredoc
+ (heredoc_lang) @injection.language
+ (heredoc_content) @injection.content)
diff --git a/runtime/queries/styx/rainbows.scm b/runtime/queries/styx/rainbows.scm
new file mode 100644
index 00000000..efb844f6
--- /dev/null
+++ b/runtime/queries/styx/rainbows.scm
@@ -0,0 +1,9 @@
+[
+ (object)
+ (sequence)
+] @rainbow.scope
+
+[
+ "(" ")"
+ "{" "}"
+] @rainbow.bracket
diff --git a/runtime/queries/styx/textobjects.scm b/runtime/queries/styx/textobjects.scm
new file mode 100644
index 00000000..09fcd17d
--- /dev/null
+++ b/runtime/queries/styx/textobjects.scm
@@ -0,0 +1,6 @@
+[(line_comment) (doc_comment)] @comment.inside
+
+(line_comment)+ @comment.around
+(doc_comment)+ @comment.around
+
+(entry value: (_) @entry.inside) @entry.around