Skip to content

Commit f55f992

Browse files
committed
feat: add function def/ref tags
quoting tree-sitter docs: > Tree-sitter can be used in conjunction with its query language as a > part of code navigation systems. [...] A notable application of this > is GitHub's support for search-based code navigation. assuming github is willing to continually run the indexing on a repository with as much activity as nixpkgs, this should mean that clicking a function on github allows you to navigate to/from the definition of the function. On my laptop, for nixpkgs: > $ time bash -c "tree-sitter tags --paths <(git ls-files | rg '[.]nix$') >/dev/null 2>&1" > bash -c 7.40s user 1.14s system 100% cpu 8.501 total Signed-off-by: Nicholas Sielicki <[email protected]>
1 parent 4bd611f commit f55f992

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

queries/tags.scm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
;; https://tree-sitter.github.io/tree-sitter/4-code-navigation.html
2+
3+
;;Function definitions
4+
(binding
5+
attrpath: (attrpath attr: (identifier)) @name
6+
expression: (function_expression) @definition.function)
7+
;;Function/method calls
8+
(apply_expression function: (apply_expression function: (variable_expression name: (identifier) @name)) @reference.call)
9+
10+
;; TODO: (if even applicable?)
11+
;;Interface definitions @definition.interface
12+
;;Interface implementation @reference.implementation
13+
;;Class definitions @definition.class
14+
;;Class reference @reference.class
15+
;;Method definitions @definition.method
16+
;;Module definitions @definition.module

tree-sitter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scope": "source.nix",
99
"file-types": ["nix"],
1010
"injection-regex": "^nix$",
11+
"tags": "queries/tags.scm",
1112
"class-name": "TreeSitterNix"
1213
}
1314
],

0 commit comments

Comments
 (0)