Skip to content

language_server: fix "go to definition" to handle build_defs in plugins, add "show usages" that handle both build_defs, plugins and reverse dependencies#3485

Open
njskalski wants to merge 3 commits intothought-machine:masterfrom
njskalski:lsp-definition-fix
Open

Conversation

@njskalski
Copy link
Contributor

fix "go to definition" to handle build_defs in plugins
add "show usages" that handle both build_defs, plugins and reverse dependencies

  • some tests

This makes the languageserver work like a charm, enabling good code navigation and all the magical AI tools that rely on LSP.

Andrzej J Skalski added 3 commits February 5, 2026 17:08
Previously, go-to-definition only worked for core builtin functions.
Plugin-defined rules like go_library, go_repo, etc. would return no
results because they were parsed by a different parser instance than
the one used by the language server.

Changes:
- Use parse.InitParser() to initialize the parser on BuildState, then
  get the same parser via parse.GetAspParser() for the language server
- Add periodic loading of function definitions (every 2 seconds) so
  go-to-definition works progressively while the full parse runs
- Add Range() method to cmap types to iterate over parsed ASTs
- Add AllFunctionsByFile() to asp.Parser to retrieve function definitions
- Fix file URIs to use absolute paths
Implements textDocument/references for the BUILD file language server.
Supports two modes:

1. Function references: When cursor is on a function definition
   (e.g., `def go_repo(...)`), finds all BUILD files that call that
   function.

2. Build label references: When cursor is on a build label, uses
   query.FindRevdeps to find all targets that depend on it, then
   locates the exact string literal positions in their BUILD files.
- Add unit tests for textDocument/references functionality
- Fix panic when package name is invalid (check graph before FindRevdeps)
- Support finding references when cursor is on function call, not just definition
- Add require dependency to BUILD for stricter test assertions
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