feat: resolve bats load as a sourcing command - #1392
Merged
Conversation
skovhus
enabled auto-merge
August 19, 2026 07:51
skovhus
approved these changes
Aug 19, 2026
Contributor
Author
|
@skovhus I think you need to enable CI here (there should be a button). If not possible, close and reopen this PR does the trick. |
Bats test files pull in helpers with `load test_helper` rather than `source`. Since `load` was not recognized as sourcing, none of the helper's symbols were reachable from a .bats file: go to definition returned nothing, and the only workaround was to turn on `includeAllWorkspaceSymbols`, which widens completion and definition across the whole workspace. Treat `load` as a sourcing command, but only in .bats files, as `load` is a common enough name for an unrelated command or function elsewhere. Path resolution follows bats: relative to the test file, retrying with a ".bash" suffix when the given path is not a file. `bats_load_library` is deliberately left out, as it resolves against BATS_LIB_PATH, which is not statically known. Fixes bash-lsp#181
auto-merge was automatically disabled
August 19, 2026 08:49
Head branch was pushed to by a user without write access
kolyshkin
force-pushed
the
bats-load-sourcing
branch
from
August 19, 2026 08:49
e505823 to
61b5428
Compare
Contributor
Author
|
rebased on top of merged #1393; CI started! |
Contributor
Author
|
CI is green now but auto-merge is now disabled because of rebase :( PTAL @skovhus |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1392 +/- ##
==========================================
+ Coverage 80.56% 80.65% +0.08%
==========================================
Files 29 29
Lines 1513 1520 +7
Branches 374 376 +2
==========================================
+ Hits 1219 1226 +7
Misses 235 235
Partials 59 59 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #181.
Problem
Bats test files pull in helper files with
load test_helper, notsource. Sinceloadwas not recognized as a sourcing command, none of the helper's symbols were reachable from a.batsfile — go to definition on a helper function returned nothing.The only workaround today is
bashIde.includeAllWorkspaceSymbols, which is a rather blunt instrument: it widens completion and definition across the entire workspace, well beyond what the file actually pulls in.Change
loadis now treated as a sourcing command, but only in.batsfiles —loadis a common enough name for an unrelated command or function elsewhere. Path resolution follows what bats itself does: relative to the directory of the test file, retrying with a.bashsuffix when the given path is not a file.bats_load_libraryis deliberately left out: it resolves againstBATS_LIB_PATH, which is not statically known, so it would only produce unresolvable source commands (and, withenableSourceErrorDiagnostics, spurious diagnostics).Tests
sourcing.test.ts: resolution of the forms above, plus the dynamic/unfinished cases, and a test assertingloadis not treated as sourcing outside.batsfiles.analyzer.test.ts: an end-to-endfindDeclarationLocationstest going from a.batsfixture into its helper — withincludeAllWorkspaceSymbolsoff, which is exactly the case that did not work before.testing/fixtures/bats/. The added.bashfixture bumpsFIXTURE_FILES_MATCHING_GLOBand adds one empty entry to two workspace-wide rename snapshots.Note:
formatter › should format when shfmt is presentfails on my machine both before and after this change — the expected-message regex does not match shfmt 3.13.1's wording. Unrelated to this PR.