nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
[Julia] Some anonymous functions are not covered
Nobody has claimed this yet.
- Dominant language
- Tree-sitter Query
- Stars
- 2.8k
- Forks
- 271
- Avg merge
- 8d 8h
- Merged PRs (30d)
- 1
Description
Describe the bug
Typed arrow anonymous function definition is not captured as function.
map(x::Int64 -> x + 1, [1, 2])
Also, do-block is not captured.
map([1, 2,]) do x
x + 1
end
To Reproduce
# existing
map(x -> x + 1, [])
# not covered (typed arrow func)
map(x::Int64 -> x + 1, [1, 2])
# not covered (do-block)
map([1, 2,]) do x
x + 1
end
Corresponding tree-sitter playground output (line number doesn't match).
typed arrow func
call_expression [24, 0] - [24, 30]
identifier [24, 0] - [24, 3]
argument_list [24, 3] - [24, 30]
arrow_function_expression [24, 4] - [24, 21]
typed_expression [24, 4] - [24, 12]
identifier [24, 4] - [24, 5]
identifier [24, 7] - [24, 12]
binary_expression [24, 16] - [24, 21]
identifier [24, 16] - [24, 17]
operator [24, 18] - [24, 19]
integer_literal [24, 20] - [24, 21]
vector_expression [24, 23] - [24, 29]
integer_literal [24, 24] - [24, 25]
integer_literal [24, 27] - [24, 28]
do-block
call_expression [0, 0] - [2, 3]
identifier [0, 0] - [0, 3]
argument_list [0, 3] - [0, 12]
vector_expression [0, 4] - [0, 11]
integer_literal [0, 5] - [0, 6]
integer_literal [0, 8] - [0, 9]
do_clause [0, 13] - [2, 3]
argument_list [0, 16] - [1, 0]
identifier [0, 16] - [0, 17]
binary_expression [1, 4] - [1, 9]
identifier [1, 4] - [1, 5]
operator [1, 6] - [1, 7]
integer_literal [1, 8] - [1, 9]
Expected behavior
They are treated as the same as other arrow anonymous function definitions.
I was able to fix this with the following textobject queries.
(arrow_function_expression
[
(identifier)
(argument_list)
(typed_expression)
]
"->"
(_) @function.inner) @function.outer
(do_clause
(argument_list)
(_) @function.inner) @function.outer
BTW, I prefer anonymous functions (or closures) are not captured as functions. Is it possible to treat them as "closure"s rather than function?
Output of :checkhealth nvim-treesitter
==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()
Installation ~
- OK
tree-sitter found 0.25.3 (2a835ee029dca1c325e6f1c01dbce40396f6123e) (parser generator, only needed for :TSInstallFromGrammar)
- OK
node found v23.9.0 (only needed for :TSInstallFromGrammar)
- OK
git executable found.
- OK
cc executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
Version: cc (GCC) 14.2.1 20250207
- OK Neovim was compiled with tree-sitter runtime ABI version 15 (required >=13). Parsers must be compatible with runtime ABI.
OS Info:
{
machine = "x86_64",
release = "6.13.7-arch1-1",
sysname = "Linux",
version = "#1 SMP PREEMPT_DYNAMIC Thu, 13 Mar 2025 18:12:00 +0000"
} ~
Parser/Features H L F I J
- angular ✓ ✓ ✓ ✓ ✓
- awk ✓ . . . ✓
- bash ✓ ✓ ✓ . ✓
- bibtex ✓ . ✓ ✓ ✓
- c ✓ ✓ ✓ ✓ ✓
- c_sharp ✓ ✓ ✓ . ✓
- cmake ✓ . ✓ ✓ ✓
- commonlisp ✓ ✓ ✓ . ✓
- cpp ✓ ✓ ✓ ✓ ✓
- css ✓ . ✓ ✓ ✓
- csv ✓ . . . .
- devicetree ✓ ✓ ✓ ✓ ✓
- diff ✓ . ✓ . ✓
- dockerfile ✓ . . . ✓
- dtd ✓ ✓ ✓ . ✓
- fish ✓ ✓ ✓ ✓ ✓
- fortran ✓ . ✓ ✓ ✓
- git_config ✓ . ✓ . ✓
- git_rebase ✓ . . . ✓
- gitcommit ✓ . . . ✓
- gitignore ✓ . . . ✓
- gpg ✓ . . . ✓
- haskell ✓ ✓ ✓ . ✓
- haskell_persistent ✓ . ✓ . .
- html ✓ ✓ ✓ ✓ ✓
- htmldjango ✓ . ✓ ✓ ✓
- ini ✓ . ✓ . ✓
- javascript ✓ ✓ ✓ ✓ ✓
- json ✓ ✓ ✓ ✓ .
- json5 ✓ . . . ✓
- julia ✓ ✓ ✓ ✓ ✓
- kconfig ✓ ✓ ✓ ✓ ✓
- latex ✓ . ✓ . ✓
- lua ✓ ✓ ✓ ✓ ✓
- make ✓ . ✓ . ✓
- markdown ✓ . ✓ ✓ ✓
- markdown_inline ✓ . . . ✓
- mermaid ✓ . ✓ ✓ ✓
- nginx ✓ . ✓ . ✓
- ninja ✓ . ✓ ✓ ✓
- nix ✓ ✓ ✓ ✓ ✓
- passwd ✓ . . . .
- perl ✓ . ✓ . ✓
- powershell ✓ ✓ ✓ ✓ ✓
- properties ✓ ✓ . . ✓
- proto ✓ . ✓ ✓ ✓
- python ✓ ✓ ✓ ✓ ✓
- query ✓ ✓ ✓ ✓ ✓
- r ✓ ✓ . ✓ ✓
- regex ✓ . . . .
- rst ✓ ✓ . . ✓
- rust ✓ ✓ ✓ ✓ ✓
- satysfi ✓ . . ✓ .
- scheme ✓ . ✓ . ✓
- sql ✓ . ✓ ✓ ✓
- ssh_config ✓ ✓ ✓ ✓ ✓
- svelte ✓ ✓ ✓ ✓ ✓
- tcl ✓ . ✓ ✓ ✓
- tmux ✓ . . . ✓
- toml ✓ ✓ ✓ ✓ ✓
- tsv ✓ . . . .
- tsx ✓ ✓ ✓ ✓ ✓
- typescript ✓ ✓ ✓ ✓ ✓
- typst ✓ . ✓ ✓ ✓
- v ✓ ✓ ✓ ✓ ✓
- verilog ✓ . ✓ . ✓
- vhdl ✓ . ✓ . ✓
- vim ✓ ✓ ✓ . ✓
- vimdoc ✓ . . . ✓
- vue ✓ . ✓ ✓ ✓
- xml ✓ ✓ ✓ ✓ ✓
- yaml ✓ ✓ ✓ ✓ ✓
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang} ~
Output of nvim --version
NVIM v0.11.0-dev-1999+ge7627db35f
Build type: RelWithDebInfo
LuaJIT 2.1.1736781742
Run "nvim -V1 -v" for more info
Additional context
My patch now covered all of these codes.
map([1, 2,]) do x
x + 1
end
map([1, 2,]) do x::Int64
x + 1
end
map([1, 2,]) do (x, y)
x + 1
end
map([1, 2,]) do (x::Int64, y::Int64)
x + 1
end
map([1, 2,]) do x::Int64, y::Int64
x + 1
end
function f(x)
x + 1
end
map(x -> x + 1, [1, 2])
map((x, y) -> x + y, [])
map(x::Int64 -> x + 1, [1, 2])
map((x::Int64, y::Int64) -> x + y, [])
map(((x::T, y::T) where T) -> x, [])
map((x::T where {T<:Integer}) -> x, [])
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Julia textobject queries shown in the issue and compare their node patterns with the typed-arrow and do-block trees. Done means all listed anonymous-function examples are captured consistently, with the closure-versus-function naming decision resolved; verify the behavior against those examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia, neovim
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100