diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index 51277ef4..177b3951 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 fdf59630..89d94fdb 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 c93fd472..4af3bdf9 100644 --- a/runtime/queries/gdshader/highlights.scm +++ b/runtime/queries/gdshader/highlights.scm @@ -1,38 +1,14 @@ [ - "render_mode" - "shader_type" - "group_uniforms" "global" - "instance" + "group_uniforms" + "uniform" "const" "varying" - "uniform" + "discard" + "render_mode" + "shader_type" ] @keyword -"struct" @keyword.type - -[ - (precision_qualifier) - (interpolation_qualifier) -] @keyword.modifier - -[ - "in" - "out" - "inout" -] @keyword.modifier - -[ - "while" - "for" -] @keyword.repeat - -[ - "continue" - "break" - "return" -] @keyword.return - [ "if" "else" @@ -41,51 +17,42 @@ "default" ] @keyword.conditional +"struct" @keyword.type + +"return" @keyword.return + [ - "#" - "include" + (parameter_qualifier) + (interpolation_specifier) + (precision_specifier) +] @keyword + +[ + "while" + "for" + "do" + "continue" + "break" +] @keyword.repeat + +[ + "#undef" + "#include" + "#if" + "#ifdef" + "#ifndef" + "#elif" + "#else" + "#endif" ] @keyword.directive -(string) @string +"#define" @keyword.directive.define [ - "=" - "+=" - "-=" - "!" - "~" - "+" - "-" - "*" - "/" - "%" - "||" - "&&" - "|" - "^" - "&" - "==" - "!=" - ">" - ">=" - "<=" - "<" - "<<" - ">>" - "++" - "--" -] @operator - -(boolean) @boolean - -(integer) @number - -(float) @number.float - -[ - "." - "," ";" + "." + ":" + "," ] @punctuation.delimiter [ @@ -97,46 +64,201 @@ "}" ] @punctuation.bracket -(builtin_type) @type.builtin - -(ident_type) @type.definition - [ - (shader_type) - (render_mode) - (hint_name) -] @attribute + "=" + "-" + "*" + "/" + "+" + "%" + "~" + "|" + "&" + "^" + "<<" + ">>" + "<" + "<=" + ">=" + ">" + "==" + "!=" + "!" + "&&" + "||" + "-=" + "+=" + "*=" + "/=" + "%=" + "|=" + "&=" + "^=" + ">>=" + "<<=" + "--" + "++" +] @operator -(builtin_variable) @constant.builtin +(comma_expression + operator: "," @operator) -(builtin_function) @function.builtin +(ternary_expression + [ + ":" + "?" + ]) @keyword.conditional.ternary -(group_uniforms_declaration - group_name: (ident) @property - subgroup_name: (ident) @property) +(primitive_type) @type.builtin -(struct_declaration - name: (ident) @type) +(type_identifier) @type -(struct_member - name: (ident) @property) +(integer) @number -(function_declaration - name: (ident) @function) +(float) @number.float -(parameter - name: (ident) @variable.parameter) +(boolean) @boolean -(member_expr - member: (ident) @property) +(case_statement + value: (identifier) @constant) -(call_expr - function: [ - (ident) - (builtin_type) - ] @function) +(shader_type_statement + (shader_type) @keyword + (#any-of? @keyword "spatial" "canvas_item" "particle" "sky" "fog")) -(call_expr - function: (builtin_type) @function.call) +; 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")) + +; 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")) + +; 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")) + +; 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")) + +; fog has no render modes +(identifier) @variable + +(struct_definition + name: (identifier) @type) + +(struct_definition + (struct_fields + (field_definition + declarator: [ + (identifier) @variable.member + (array_declarator + declarator: (identifier) @variable.member) + ]))) + +(preproc_include + path: (_) @string) + +(preproc_undef + argument: (identifier) @constant) (comment) @comment @spell + +; technically an injection site for bbcode TODO: maybe add it? +((comment) @comment.documentation @spell + (#lua-match? @comment.documentation "^/%*%*[^/]")) + +(parameter_declaration + declarator: [ + (identifier) @variable.parameter + (array_declarator + declarator: (identifier) @variable.parameter) + ]) + +(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 00000000..db145902 --- /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 +}