Skip to content

feat: add tagging for github code navigation #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sielicki
Copy link

@sielicki sielicki commented Apr 1, 2025

https://tree-sitter.github.io/tree-sitter/4-code-navigation.html

Code Navigation Systems

Tree-sitter can be used in conjunction with its query language as a part of code navigation systems. An example of such a system can be seen in the tree-sitter tags command, which emits a textual dump of the interesting syntactic nodes in its file argument. A notable application of this is GitHub's support for search-based code navigation. This document exists to describe how to integrate with such systems, and how to extend this functionality to any language with a Tree-sitter grammar.

See also: github docs on code navigation.

tl;dr: I expect that we can get code navigation within nixpkgs such as:

image

Provided that our grammar supports the tag generation and github is willing to run it. This PR adds two queries that will do that.

Commit:     Nicholas Sielicki <[email protected]>
CommitDate: Mon Mar 31 23:45:39 2025 -0700

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]>

2 files changed, 17 insertions(+)
queries/tags.scm | 16 ++++++++++++++++
tree-sitter.json |  1 +

@sielicki sielicki force-pushed the feat/tagging branch 2 times, most recently from 08d147b to f55f992 Compare April 1, 2025 07:07
sielicki added 2 commits April 1, 2025 00:08
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]>
@sielicki
Copy link
Author

sielicki commented Apr 1, 2025

I wonder if this can be improved further -- right now, package definitions are just all going to resolve to top-level.nix

I'm not sure whether there's enough flexibility in the tagging scheme to properly disambiguate through callPackage/mkDerivation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant