diff options
| author | Tayfun Bocek <tayfunbocek@live.ca> | 2025-10-30 16:59:19 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-30 14:59:19 +0100 |
| commit | 64f4755b9d6ea9008265b09eb79fd91727311682 (patch) | |
| tree | 411bab3208dfd169e6b654bc22efb3ce54cec7ca | |
| parent | feat(install): remove node requirement (diff) | |
| download | nvim-treesitter-64f4755b9d6ea9008265b09eb79fd91727311682.tar nvim-treesitter-64f4755b9d6ea9008265b09eb79fd91727311682.tar.gz nvim-treesitter-64f4755b9d6ea9008265b09eb79fd91727311682.tar.bz2 nvim-treesitter-64f4755b9d6ea9008265b09eb79fd91727311682.tar.lz nvim-treesitter-64f4755b9d6ea9008265b09eb79fd91727311682.tar.xz nvim-treesitter-64f4755b9d6ea9008265b09eb79fd91727311682.tar.zst nvim-treesitter-64f4755b9d6ea9008265b09eb79fd91727311682.zip | |
feat!(gdshader): replace gdshader parser and queries (#8244)
Switch parser to https://github.com/airblast-dev/tree-sitter-gdshader
| -rw-r--r-- | SUPPORTED_LANGUAGES.md | 2 | ||||
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 6 | ||||
| -rw-r--r-- | runtime/queries/gdshader/highlights.scm | 296 | ||||
| -rw-r--r-- | tests/query/highlights/gdshader/test.gdshader | 26 |
4 files changed, 239 insertions, 91 deletions
diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index 51277ef41..177b3951a 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -92,7 +92,7 @@ ecma (queries only)[^ecma] | unstable | `HFIJL` | @steelsojka [gap](https://github.com/gap-system/tree-sitter-gap)[^gap] | unstable | `HF JL` | @reiniscirpons [gaptst](https://github.com/gap-system/tree-sitter-gaptst)[^gaptst] | unstable | `HF J ` | @reiniscirpons [gdscript](https://github.com/PrestonKnopp/tree-sitter-gdscript)[^gdscript] | unmaintained | `HFIJL` | -[gdshader](https://github.com/GodOfAvacyn/tree-sitter-gdshader) | unstable | `H J ` | @godofavacyn +[gdshader](https://github.com/airblast-dev/tree-sitter-gdshader) | unstable | `H J ` | @airblast-dev [git_config](https://github.com/the-mikedavis/tree-sitter-git-config) | unstable | `HF J ` | @amaanq [git_rebase](https://github.com/the-mikedavis/tree-sitter-git-rebase) | unstable | `H J ` | @gbprod [gitattributes](https://github.com/tree-sitter-grammars/tree-sitter-gitattributes) | unstable | `H JL` | @ObserverOfTime diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index fdf596304..89d94fdbe 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -660,10 +660,10 @@ return { }, gdshader = { install_info = { - revision = '14e834063e136fa69b6d91f711f4f1981acf424b', - url = 'https://github.com/GodOfAvacyn/tree-sitter-gdshader', + revision = '0dab84552f7d33a0084b469b7e38237302bf8e91', + url = 'https://github.com/airblast-dev/tree-sitter-gdshader', }, - maintainers = { '@godofavacyn' }, + maintainers = { '@airblast-dev' }, tier = 2, }, git_config = { diff --git a/runtime/queries/gdshader/highlights.scm b/runtime/queries/gdshader/highlights.scm index c93fd4721..4af3bdf97 100644 --- a/runtime/queries/gdshader/highlights.scm +++ b/runtime/queries/gdshader/highlights.scm @@ -1,142 +1,264 @@ [ - "render_mode" - "shader_type" - "group_uniforms" "global" - "instance" + "group_uniforms" + "uniform" "const" "varying" - "uniform" + "discard" + "render_mode" + "shader_type" ] @keyword +[ + "if" + "else" + "switch" + "case" + "default" +] @keyword.conditional + "struct" @keyword.type -[ - (precision_qualifier) - (interpolation_qualifier) -] @keyword.modifier +"return" @keyword.return [ - "in" - "out" - "inout" -] @keyword.modifier + (parameter_qualifier) + (interpolation_specifier) + (precision_specifier) +] @keyword [ "while" "for" -] @keyword.repeat - -[ + "do" "continue" "break" - "return" -] @keyword.return +] @keyword.repeat [ - "if" - "else" - "switch" - "case" - "default" -] @keyword.conditional + "#undef" + "#include" + "#if" + "#ifdef" + "#ifndef" + "#elif" + "#else" + "#endif" +] @keyword.directive + +"#define" @keyword.directive.define [ - "#" - "include" -] @keyword.directive + ";" + "." + ":" + "," +] @punctuation.delimiter -(string) @string +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket [ "=" - "+=" - "-=" - "!" - "~" - "+" "-" "*" "/" + "+" "%" - "||" - "&&" + "~" "|" - "^" "&" - "==" - "!=" - ">" - ">=" - "<=" - "<" + "^" "<<" ">>" - "++" + "<" + "<=" + ">=" + ">" + "==" + "!=" + "!" + "&&" + "||" + "-=" + "+=" + "*=" + "/=" + "%=" + "|=" + "&=" + "^=" + ">>=" + "<<=" "--" + "++" ] @operator -(boolean) @boolean +(comma_expression + operator: "," @operator) + +(ternary_expression + [ + ":" + "?" + ]) @keyword.conditional.ternary + +(primitive_type) @type.builtin + +(type_identifier) @type (integer) @number (float) @number.float -[ - "." - "," - ";" -] @punctuation.delimiter +(boolean) @boolean -[ - "(" - ")" - "[" - "]" - "{" - "}" -] @punctuation.bracket +(case_statement + value: (identifier) @constant) -(builtin_type) @type.builtin +(shader_type_statement + (shader_type) @keyword + (#any-of? @keyword "spatial" "canvas_item" "particle" "sky" "fog")) -(ident_type) @type.definition +; spatial +(source_file + (shader_type_statement + (shader_type) @_shader_type) + (#eq? @_shader_type "spatial") + (render_mode_statement + (render_mode) @keyword) + (#any-of? @keyword + "blend_mix" "blend_add" "blend_sub" "blend_mul" "blend_premul_alpha" "depth_draw_opaque" + "depth_draw_always" "depth_draw_never" "depth_prepass_alpha" "depth_test_disabled" + "sss_mode_skin" "cull_back" "cull_front" "cull_disabled" "unshaded" "wireframe" + "debug_shadow_splits" "diffuse_burley" "diffuse_lambert" "diffuse_lambert_wrap" "diffuse_toon" + "specular_schlick_ggx" "specular_toon" "specular_disabled" "skip_vertex_transform" + "world_vertex_coords" "ensure_correct_normals" "shadows_disabled" "ambient_light_disabled" + "shadow_to_opacity" "vertex_lighting" "particle_trails" "alpha_to_coverage" + "alpha_to_coverage_and_one" "fog_disabled")) -[ - (shader_type) - (render_mode) - (hint_name) -] @attribute +; canvas_item +(source_file + (shader_type_statement + (shader_type) @_shader_type) + (#eq? @_shader_type "canvas_item") + (render_mode_statement + (render_mode) @keyword) + (#any-of? @keyword + "blend_mix" "blend_add" "blend_sub" "blend_mul" "blend_premul_alpha" "blend_disabled" "unshaded" + "light_only" "skip_vertex_transform" "world_vertex_coords")) -(builtin_variable) @constant.builtin +; particle +(source_file + (shader_type_statement + (shader_type) @_shader_type) + (#eq? @_shader_type "particle") + (render_mode_statement + (render_mode) @keyword) + (#any-of? @keyword "keep_data" "disable_force" "disable_velocity" "collision_use_scale")) -(builtin_function) @function.builtin +; sky +(source_file + (shader_type_statement + (shader_type) @_shader_type) + (#eq? @_shader_type "sky") + (render_mode_statement + (render_mode) @keyword) + (#any-of? @keyword "use_half_res_pass" "use_quarter_res_pass" "disable_fog")) -(group_uniforms_declaration - group_name: (ident) @property - subgroup_name: (ident) @property) +; fog has no render modes +(identifier) @variable -(struct_declaration - name: (ident) @type) +(struct_definition + name: (identifier) @type) -(struct_member - name: (ident) @property) +(struct_definition + (struct_fields + (field_definition + declarator: [ + (identifier) @variable.member + (array_declarator + declarator: (identifier) @variable.member) + ]))) -(function_declaration - name: (ident) @function) +(preproc_include + path: (_) @string) -(parameter - name: (ident) @variable.parameter) +(preproc_undef + argument: (identifier) @constant) -(member_expr - member: (ident) @property) +(comment) @comment @spell -(call_expr - function: [ - (ident) - (builtin_type) - ] @function) +; technically an injection site for bbcode TODO: maybe add it? +((comment) @comment.documentation @spell + (#lua-match? @comment.documentation "^/%*%*[^/]")) -(call_expr - function: (builtin_type) @function.call) +(parameter_declaration + declarator: [ + (identifier) @variable.parameter + (array_declarator + declarator: (identifier) @variable.parameter) + ]) -(comment) @comment @spell +(function_definition + declarator: (identifier) @function) + +(call_expression + function: (identifier) @function.call) + +(field_expression + field: (_) @property) + +((call_expression + function: (identifier) @function.builtin) + (#any-of? @function.builtin + ; taken from: https://docs.godotengine.org/en/stable/tutorials/shaders/shader_reference/shader_functions.html + ; trigonometric builtins + "radians" "degrees" "sin" "cos" "tan" "asin" "acos" "atan" "sinh" "cosh" "tanh" "asinh" "acosh" + "atanh" + ; exponential and math builtins + "pow" "exp" "exp2" "log" "log2" "sqrt" "inversesqrt" "abs" "sign" "floor" "round" "roundEven" + "trunc" "ceil" "fract" "mod" "modf" "min" "max" "clamp" "mix" "fma" "step" "smoothstep" "isnan" + "isinf" "floatBitsToInt" "floatBitsToUint" "intBitsToFloat" "uintBitsToFloat" + ; geometric builtins + "length" "distance" "dot" "cross" "normalize" "reflect" "refract" "faceforward" "matrixCompMult" + "outerProduct" "transpose" "determinant" "inverse" + ; comparison builtins + "lessThan" "greaterThan" "lessThanEqual" "equal" "notEqual" "any" "all" "not" + ; texture builtins + "textureSize" "textureQueryLod" "textureQueryLevels" "texture" "textureProj" "textureLod" + "textureProjLod" "textureGrad" "textureProjGrad" "texelFetch" "textureGather" "dFdx" + "dFdxCoarse" "dFdxFine" "dFdy" "dFdyCoarse" "dFdyFine" "fwidth" "fwidthCoarse" "fwidthFine" + ; packing unpacking builtins + "packHalf2x16" "unpackHalf2x16" "packUnorm2x16" "unpackUnorm2x16" "packSnorm2x16" + "unpackSnorm2x16" "packUnorm4x8" "unpackUnorm4x8" "packSnorm4x8" "unpackSnorm4x8" + ; bitwise builtins + "bitfieldExtract" "bitfieldInsert" "bitfieldReverse" "bitCount" "findLSB" "findMSB" "imulExtend" + "umulExtend" "uaddCarry" "usubBorrow" "ldexp" "frexp")) + +; assume all uppercase variables as constants +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + +((identifier) @constant.builtin + (#any-of? @constant.builtin + ; common / declared in all shader types + "PI" "E" "TAU" "CURRENT_RENDERER" "RENDERER_COMPATIBILITY" "RENDERER_MOBILE" + "RENDERER_FORWARD_PLUS"; TODO: add more builtins + )) + +((identifier) @variable.builtin + (#eq? @variable.builtin "TIME")) + +(type_hint + [ + (identifier) @attribute + (call_expression + function: (_) @attribute) + ]) diff --git a/tests/query/highlights/gdshader/test.gdshader b/tests/query/highlights/gdshader/test.gdshader new file mode 100644 index 000000000..db1459028 --- /dev/null +++ b/tests/query/highlights/gdshader/test.gdshader @@ -0,0 +1,26 @@ +shader_type spatial; + +render_mode unshaded, wireframe; +// <- @keyword +// ^^^^^^^^ @keyword +// ^^^^^^^^^ @keyword + +/** My Doc comment*/ +//^^^^^^^^^^^^^^^^^^ @comment.documentation +uniform float MY_VALUE: interesting_hint = 1.0; +//<- @keyword +// ^^^^^ type.builtin +// ^^^^^^^^ constant +// ^ @punctuation.delimiter +// ^^^^^^^^^^^^^^^^ @attribute +// ^ @operator +// ^^^ @number.float +// ^ punctuation.delimiter + +void vertex() { +// <- type.builtin +// ^^^^^^ @function + do {} while (123< 2231); +//^^ keyword.repeat +// ^^^^^ keyword.repeat +} |
