From 06b5fda797ea4c363e9fe17b160c33818be8d319 Mon Sep 17 00:00:00 2001 From: GodOfAvacyn <59858208+GodOfAvacyn@users.noreply.github.com> Date: Thu, 29 Feb 2024 02:30:33 -0800 Subject: [PATCH] feat: add support for gdshader (#6153) Godot shading language --------- Co-authored-by: ObserverOfTime --- README.md | 1 + lockfile.json | 3 + lua/nvim-treesitter/parsers.lua | 9 ++ queries/gdshader/highlights.scm | 142 ++++++++++++++++++++++++++++++++ queries/gdshader/injections.scm | 2 + 5 files changed, 157 insertions(+) create mode 100644 queries/gdshader/highlights.scm create mode 100644 queries/gdshader/injections.scm diff --git a/README.md b/README.md index c25e98e3a..986ab537c 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,7 @@ We are looking for maintainers to add more parsers and to write query files for - [x] [func](https://github.com/amaanq/tree-sitter-func) (maintained by @amaanq) - [x] [fusion](https://gitlab.com/jirgn/tree-sitter-fusion.git) (maintained by @jirgn) - [x] [Godot (gdscript)](https://github.com/PrestonKnopp/tree-sitter-gdscript) (maintained by @PrestonKnopp) +- [x] [gdshader](https://github.com/GodOfAvacyn/tree-sitter-gdshader) (maintained by @godofavacyn) - [x] [git_config](https://github.com/the-mikedavis/tree-sitter-git-config) (maintained by @amaanq) - [x] [git_rebase](https://github.com/the-mikedavis/tree-sitter-git-rebase) (maintained by @gbprod) - [x] [gitattributes](https://github.com/ObserverOfTime/tree-sitter-gitattributes) (maintained by @ObserverOfTime) diff --git a/lockfile.json b/lockfile.json index 14cb8c036..c87237b91 100644 --- a/lockfile.json +++ b/lockfile.json @@ -194,6 +194,9 @@ "gdscript": { "revision": "b5dea4d852db65f0872d849c24533eb121e03c76" }, + "gdshader": { + "revision": "ffd9f958df13cae04593781d7d2562295a872455" + }, "git_config": { "revision": "9c2a1b7894e6d9eedfe99805b829b4ecd871375e" }, diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index aef843213..89102f405 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -619,6 +619,15 @@ list.gdscript = { readme_name = "Godot (gdscript)", } +list.gdshader = { + install_info = { + url = "https://github.com/GodOfAvacyn/tree-sitter-gdshader", + files = { "src/parser.c" }, + }, + filetype = "gdshaderinc", + maintainers = { "@godofavacyn" }, +} + list.git_rebase = { install_info = { url = "https://github.com/the-mikedavis/tree-sitter-git-rebase", diff --git a/queries/gdshader/highlights.scm b/queries/gdshader/highlights.scm new file mode 100644 index 000000000..797681a0c --- /dev/null +++ b/queries/gdshader/highlights.scm @@ -0,0 +1,142 @@ +[ + "render_mode" + "shader_type" + "group_uniforms" + "global" + "instance" + "const" + "varying" + "uniform" + "struct" +] @keyword + +[ + (precision_qualifier) + (interpolation_qualifier) +] @type.qualifier + +[ + "in" + "out" + "inout" +] @keyword.storage + +[ + "while" + "for" +] @keyword.repeat + +[ + "continue" + "break" + "return" +] @keyword.return + +[ + "if" + "else" + "switch" + "case" + "default" +] @keyword.conditional + +[ + "#" + "include" +] @keyword.directive + +(string) @string + +[ + "=" + "+=" + "-=" + "!" + "~" + "+" + "-" + "*" + "/" + "%" + "||" + "&&" + "|" + "^" + "&" + "==" + "!=" + ">" + ">=" + "<=" + "<" + "<<" + ">>" + "++" + "--" +] @operator + +(boolean) @boolean + +(integer) @number + +(float) @number.float + +[ + "." + "," + ";" +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(builtin_type) @type.builtin + +(ident_type) @type.definition + +[ + (shader_type) + (render_mode) + (hint_name) +] @attribute + +(builtin_variable) @constant.builtin + +(builtin_function) @function.builtin + +(group_uniforms_declaration + group_name: (ident) @property + subgroup_name: (ident) @property) + +(struct_declaration + name: (ident) @type) + +(struct_member + name: (ident) @property) + +(function_declaration + name: (ident) @function) + +(parameter + name: (ident) @variable.parameter) + +(member_expr + member: (ident) @property) + +(call_expr + function: + [ + (ident) + (builtin_type) + ] @function) + +(call_expr + function: (builtin_type) @function.call) + +(comment) @comment @spell diff --git a/queries/gdshader/injections.scm b/queries/gdshader/injections.scm new file mode 100644 index 000000000..2f0e58eb6 --- /dev/null +++ b/queries/gdshader/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment"))