Skip to content

Instantly share code, notes, and snippets.

@ntoxeg
Last active June 7, 2025 08:55
Show Gist options
  • Save ntoxeg/50bb3b7d7af560ebe4f5bfd51ed3f972 to your computer and use it in GitHub Desktop.
Save ntoxeg/50bb3b7d7af560ebe4f5bfd51ed3f972 to your computer and use it in GitHub Desktop.
tree-sitter tags file for Julia
; Modules
(
(module_definition
(identifier) @name) @definition.module
)
; Types (Structs, Abstract, Primitive)
(
(struct_definition
(type_head [
(identifier) @name ; Direct identifier: struct Foo ...
(parametrized_type_expression (identifier) @name .) ; Parametric: struct Foo{T} ...
(binary_expression ; Inheritance: struct Foo <: Bar ... or struct Foo{T} <: Bar{T} ...
[
(identifier) @name
(parametrized_type_expression (identifier) @name .)
]
(operator) ; Operator (e.g., <:) - could be alias too
(_) ; RHS (parent type) - we don't need to capture this
)
])
) @definition.structure
)
(
(abstract_definition
(type_head (identifier) @name)) @definition.abstract
)
(
(primitive_definition
(type_head (identifier) @name)) @definition.primitive
)
; Functions
(
(function_definition
(signature
(call_expression
(identifier) @name))) @definition.function
)
; Macro-wrapped function definition
(
(macrocall_expression
(macro_argument_list
(function_definition
(signature
[ ; Match either direct call or call inside where
(call_expression
(identifier) @name)
(where_expression
(call_expression
(identifier) @name) @ignore)
]
)
)
)
) @definition.function
)
; Short-form function definition
(
(assignment
(call_expression
(identifier) @name)
(operator)
(_expression)
) @definition.function
)
; Macros
(
(macro_definition
(signature
(call_expression
(identifier) @name))) @definition.macro
)
; Constants
(
(const_statement
(assignment
(identifier) @name
"="
(_)
)
) @definition.constant
)
; Struct fields
[
(struct_definition
(identifier) @name @definition.field
)
(struct_definition
(typed_expression (identifier) @name) @definition.field
)
]
@mauro3
Copy link

mauro3 commented May 25, 2025

Tnx for putting this together! I managed to get it to run with tree-sitter 0.25.3, however I had an issue with the locals.scm file https://github.com/tree-sitter/tree-sitter-julia/blob/master/queries/locals.scm :

As soon as I added a tags.scm file to the queries folder, even one which just had a comment in it I got:

$ tree-sitter tags containers.jl                                                                                                         
Invalid capture @local.definition.function. Expected one of: @definition.*, @reference.*, @doc, @name, @local.(scope|definition|reference).

Did you encounter that too? Deleting the .function in the lines 53 and 59 of locals.scm fixed this and let the tags run, but not sure what that would do to the .

Then with your file, I had to comment out the ; Constants block as that gave me an Invalid note type = error. Other than that it ran fine.

Anyways, are you considering doing a PR for this to the tree-sitter-julia and to the aider repos?

@ntoxeg
Copy link
Author

ntoxeg commented Jun 5, 2025

Hmm, I didn't have those issues, @mauro3
I didn't do anything with the locals.scm file, my tree-sitter version is reported as tree-sitter 0.25.3 (2a835ee029dca1c325e6f1c01dbce40396f6123e)

I guess I could PR this into tree-sitter-julia and then to aider, I'm just not 100% sure if this works and I'm unable to reproduce your issues.

@mauro3
Copy link

mauro3 commented Jun 5, 2025

Yes, my tree-sitter verion is the same (on arch linux) and the tree-sitter-julia I had master/main.

A PR would be cool. With a bit of luck the tree-sitter people could help with that issue of ours.

Regarding the tagging for aider, probably leaving away struct fields would be ok. Albeit, I would start with them in there and see how things go.

@mauro3
Copy link

mauro3 commented Jun 7, 2025

I can try to get this going, i.e. the PR to tree sitter, if you want me to using this file. I'd make sure that you are mentioned in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment