Skip to content

feat(langserver): find references and tests#3494

Open
njskalski wants to merge 7 commits intothought-machine:masterfrom
njskalski:lsp-find-references-clear
Open

feat(langserver): find references and tests#3494
njskalski wants to merge 7 commits intothought-machine:masterfrom
njskalski:lsp-find-references-clear

Conversation

@njskalski
Copy link
Contributor

@njskalski njskalski commented Mar 3, 2026

This is a follow up to #3485 , that was broken into this and #3491, and branches from #3491.

answering @jwong-beep:

A couple of questions:

How does the asp parser handle syntactically invalid functions? Does the LSP server panic because of a parse error?
  • added test to make sure handler doesn't crash in that case

    I see some parseIfNeeded and the handler's builtins map is prepopulated on LSP server init. If you add a new build def file or BUILD file, how do function defs and refs get populated in the cache? Do they get populated at all?

  • this part I honestly don't know. I reused a function that was there and it worked. If you can tell me what exact scenario you want me to verify, I am happy to write a test. But other than that - your guess is as good as mine.

Andrzej J Skalski added 7 commits February 27, 2026 15:43
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
@njskalski
Copy link
Contributor Author

@toastwaffle can i ask you to re-review it?

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