elixir tree-sitter queries: add constants

This commit is contained in:
Emmanuel Touzery 2023-02-05 17:35:42 +01:00
parent 7f09d0d003
commit 7ea5a44778
3 changed files with 34 additions and 13 deletions

View file

@ -25,6 +25,7 @@
) @type
(unary_operator
operator: "@"
operand: (call
target: (identifier) @identifier (#any-of? @identifier "callback" "spec")
(arguments [
@ -36,6 +37,7 @@
) @start
(unary_operator
operator: "@"
operand: (call
target: (identifier) @identifier (#eq? @identifier "module_attribute")
(arguments) @name
@ -43,6 +45,13 @@
(#set! "kind" "Function")
) @start
(unary_operator
operator: "@"
operand: (call target: (identifier) @name (#not-any-of? @name "module_attribute" "callback" "spec")) @type
(#set! "kind" "Constant")
) @start
(do_block
(call
target: (identifier) @identifier (#eq? @identifier "defstruct")) @type

View file

@ -103,34 +103,45 @@ describe("treesitter elixir", function()
level = 0,
lnum = 25,
col = 0,
end_lnum = 27,
end_lnum = 28,
end_col = 3,
children = {
{
kind = "Constant",
name = "constant",
level = 1,
lnum = 26,
col = 2,
end_lnum = 26,
end_col = 13,
},
},
},
{
kind = "Interface",
name = "Example.Protocol",
level = 0,
lnum = 29,
lnum = 30,
col = 0,
end_lnum = 32,
end_lnum = 33,
end_col = 3,
children = {
{
kind = "TypeParameter",
name = "public_function_head",
level = 1,
lnum = 30,
lnum = 31,
col = 2,
end_lnum = 30,
end_lnum = 31,
end_col = 50,
},
{
kind = "Function",
name = "public_function_head",
level = 1,
lnum = 31,
lnum = 32,
col = 2,
end_lnum = 31,
end_lnum = 32,
end_col = 39,
},
},
@ -139,27 +150,27 @@ describe("treesitter elixir", function()
kind = "Class",
name = "Map > Example.Protocol",
level = 0,
lnum = 34,
lnum = 35,
col = 0,
end_lnum = 39,
end_lnum = 40,
end_col = 3,
children = {
{
kind = "TypeParameter",
name = "public_function_head",
level = 1,
lnum = 35,
lnum = 36,
col = 2,
end_lnum = 35,
end_lnum = 36,
end_col = 56,
},
{
kind = "Function",
name = "public_function_head",
level = 1,
lnum = 36,
lnum = 37,
col = 2,
end_lnum = 38,
end_lnum = 39,
end_col = 5,
},
},

View file

@ -23,6 +23,7 @@ defmodule Example.Behaviour do
end
defmodule Example.Struct do
@constant 5
defstruct name: nil, age: nil
end