I’m trying to write an extension for the Zig language, using the existing tree-sitter-zig parser.
So far it works pretty well. However, I am unable to parse function parameters of a function definition. This is my query in symbols.scm
:
(
(doc_comment)* @doc
.
(TopLevelDecl
(FnProto
function: (IDENTIFIER) @name
(ParamDeclList) @arguments.target
)
) @subtree @_method
(#strip! @doc "^[\\s/]+")
(#select-adjacent! @doc @_method)
(#set! role function)
(#set! arguments.query "arguments.scm")
)
If I understand it correctly, this should issue a subquery to the (ParamDeclList)
subtree using arguments.scm
, which contains this:
(ParamDeclList
(ParamDecl
parameter: (IDENTIFIER) @name
(ParamType) @type
) @subtree
)
For a declared parameter, this is the parsed tree according to the inspector:
a) parameter name
b) parameter type
Based on these, I’d assume the subquery would be able to identify the parameters. However, when using the resulting symbol for completion, the list of parameters is empty. This is in my Completions/Zig.xml
:
<provider name="zig.values">
<syntax>zig</syntax>
<exclude-selector>string, comment</exclude-selector>
<expression>(?:(?<![.@])\b([a-zA-Z_][a-zA-Z0-9_]*))|(?:(?<![a-zA-Z0-9_\.]))</expression>
<symbols type="function">
<behavior>
<arguments prefix="(" suffix=")" separator=", " />
</behavior>
</symbols>
</provider>
Nova is able to complete the parsed functions and appends ()
, but without any arguments in it. Why?