From 7815bfb10886e65621ee738a9aaf977b3fad8132 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Mon, 13 Oct 2025 18:11:11 -0700 Subject: [PATCH] feat(starlark): build targets as locals Problem: I have very big BUILD files I want to navigate quickly. I have Telescope, so I can use `:Telescope treesitter` for an outline, but build targets aren't emitted as definitions. Solution: Add a query that catches build targets. One thing I'm unclear on is: - I want to filter to just build targets. - Build targets are absolutely not any of the mentioned types in the CONTRIBUTING file. - Build targets do not actually create identifiers in buck2/bazel: they create objects which are observable to the outside world and which the user generally *cares* about, but they aren't in the same namespace as normal identifiers. This means that they *especially* don't fit into any of the existing categories. I would like guidance as to whether this is the right approach. --- .tsqueryrc.json | 1 + CONTRIBUTING.md | 1 + runtime/queries/starlark/locals.scm | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/.tsqueryrc.json b/.tsqueryrc.json index cd3a692d5..0c456a4fe 100644 --- a/.tsqueryrc.json +++ b/.tsqueryrc.json @@ -156,6 +156,7 @@ "local.definition.namespace": "modules or namespaces", "local.definition.import": "imported names", "local.definition.associated": "the associated type of a variable", + "local.definition.target": "build targets", "local.scope": "scope block", "local.reference": "identifier reference" } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f376ed802..90e22b308 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -494,6 +494,7 @@ are only provided for limited backwards compatibility. @local.definition.namespace ; modules or namespaces @local.definition.import ; imported names @local.definition.associated ; the associated type of a variable +@local.definition.target ; a build target (which may not be an identifier) @local.scope ; scope block @local.reference ; identifier reference diff --git a/runtime/queries/starlark/locals.scm b/runtime/queries/starlark/locals.scm index 82ec0b5d2..aa50ce3df 100644 --- a/runtime/queries/starlark/locals.scm +++ b/runtime/queries/starlark/locals.scm @@ -94,3 +94,14 @@ arguments: (argument_list (string) @local.definition.import)) (#eq? @_fn "load")) + +; Build target definitions +((module + (expression_statement + (call + arguments: (argument_list + (keyword_argument + name: (identifier) @_name + value: (string + (string_content) @local.definition.target)))))) + (#eq? @_name "name"))