Skip to content

fix(langserver): Support go-to-definition for plugin-defined rules#3484

Closed
njskalski wants to merge 2 commits intothought-machine:masterfrom
njskalski:lsp-definition-fix
Closed

fix(langserver): Support go-to-definition for plugin-defined rules#3484
njskalski wants to merge 2 commits intothought-machine:masterfrom
njskalski:lsp-definition-fix

Conversation

@njskalski
Copy link
Contributor

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

Andrzej J Skalski added 2 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.
@njskalski njskalski closed this Feb 5, 2026
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