Merge pull request #216 from emmanueltouzery/elixir_treesitter_constants

elixir tree-sitter queries: add constants
This commit is contained in:
Steven Arcangeli 2023-02-06 12:23:30 -08:00 committed by GitHub
commit 9921808e0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 13 deletions

View file

@ -83,6 +83,8 @@ M.elixir = {
local protocol_name = vim.treesitter.query.get_node_text(protocol, bufnr) or "<parse error>"
item.name = string.format("%s > %s", item.name, protocol_name)
end
elseif item.kind == "Constant" then
item.name = string.format("@%s", item.name)
end
end,
}

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