Skip to content

feat: resolve bats load as a sourcing command - #1392

Merged
skovhus merged 1 commit into
bash-lsp:mainfrom
kolyshkin:bats-load-sourcing
Aug 19, 2026
Merged

feat: resolve bats load as a sourcing command#1392
skovhus merged 1 commit into
bash-lsp:mainfrom
kolyshkin:bats-load-sourcing

Conversation

@kolyshkin

Copy link
Copy Markdown
Contributor

Fixes #181.

Problem

Bats test files pull in helper files with load test_helper, not source. Since load was not recognized as a sourcing command, none of the helper's symbols were reachable from a .bats file — 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

load is now treated as a sourcing command, but only in .bats filesload is 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 .bash suffix when the given path is not a file.

#!/usr/bin/env bats

load test_helper        # -> ./test_helper.bash
load ./test_helper.bash # -> ./test_helper.bash
load /abs/path/helper   # -> /abs/path/helper.bash

bats_load_library is deliberately left out: it resolves against BATS_LIB_PATH, which is not statically known, so it would only produce unresolvable source commands (and, with enableSourceErrorDiagnostics, spurious diagnostics).

Tests

  • sourcing.test.ts: resolution of the forms above, plus the dynamic/unfinished cases, and a test asserting load is not treated as sourcing outside .bats files.
  • analyzer.test.ts: an end-to-end findDeclarationLocations test going from a .bats fixture into its helper — with includeAllWorkspaceSymbols off, which is exactly the case that did not work before.
  • New fixtures under testing/fixtures/bats/. The added .bash fixture bumps FIXTURE_FILES_MATCHING_GLOB and adds one empty entry to two workspace-wide rename snapshots.

Note: formatter › should format when shfmt is present fails 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.

@skovhus
skovhus enabled auto-merge August 19, 2026 07:51
@kolyshkin

Copy link
Copy Markdown
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

Copy link
Copy Markdown
Contributor Author

rebased on top of merged #1393; CI started!

@kolyshkin

Copy link
Copy Markdown
Contributor Author

CI is green now but auto-merge is now disabled because of rebase :( PTAL @skovhus

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.65%. Comparing base (d14b5d2) to head (61b5428).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@skovhus
skovhus merged commit 12914ea into bash-lsp:main Aug 19, 2026
5 checks passed
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.

Support BATS testing framework with go to definition

2 participants