Skip to content

Sourcing: support basic variable expansions #659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
skovhus opened this issue Jan 5, 2023 · 1 comment · Fixed by #1086
Closed

Sourcing: support basic variable expansions #659

skovhus opened this issue Jan 5, 2023 · 1 comment · Fixed by #1086
Labels
enhancement New feature or request

Comments

@skovhus
Copy link
Collaborator

skovhus commented Jan 5, 2023

#244 introduced sourcing aware symbol resolution where source commands (e.g. . myfile.sh or source ./file.bash) is used for figure out which symbols are available in a given context.

The current implementation is fairly crude and can be extended a bit to resolve basic variable expansions and sourcing statements in functions and loops.

@skovhus skovhus added the enhancement New feature or request label Jan 5, 2023
@skovhus
Copy link
Collaborator Author

skovhus commented Jan 11, 2023

With #673 we now just miss basic variable expansion support.

@skovhus skovhus changed the title Sourcing: support basic variable expansions and non root statements Sourcing: support basic variable expansions Jan 17, 2023
aarondill added a commit to aarondill/bash-language-server that referenced this issue Jan 21, 2024
This does the same thing that ShellCheck does ([here](https://github.com/koalaman/shellcheck/blob/ba86c6363c30a5dbefd0b8b9a7c5f4ab0478dc91/src/ShellCheck/Parser.hs#L2277-L2283)).

`To support the common pattern of . "$CONFIGDIR/mylib.sh", ShellCheck strips one leading, dynamic section before trying to locate the rest.`

fixes bash-lsp#926, fixes bash-lsp#659
aarondill added a commit to aarondill/bash-language-server that referenced this issue Feb 6, 2024
This does the same thing that ShellCheck does ([here](https://github.com/koalaman/shellcheck/blob/ba86c6363c30a5dbefd0b8b9a7c5f4ab0478dc91/src/ShellCheck/Parser.hs#L2277-L2283)).

`To support the common pattern of . "$CONFIGDIR/mylib.sh", ShellCheck strips one leading, dynamic section before trying to locate the rest.`

fixes bash-lsp#926, fixes bash-lsp#659
aarondill added a commit to aarondill/bash-language-server that referenced this issue Apr 13, 2025
This does the same thing that ShellCheck does ([here](https://github.com/koalaman/shellcheck/blob/ba86c6363c30a5dbefd0b8b9a7c5f4ab0478dc91/src/ShellCheck/Parser.hs#L2277-L2283)).

`To support the common pattern of . "$CONFIGDIR/mylib.sh", ShellCheck strips one leading, dynamic section before trying to locate the rest.`

fixes bash-lsp#926, fixes bash-lsp#659

fix: handle leading dynamic source paths when concatenating

This fixes `${var}/path` and `"${var}"/path` as well as countless variations of these patterns

Note: this turned out to be rather complex task, so it's broken out into a seperate function, which allows for early returns

refactor: move resolveStaticString to util/tree-sitter.ts

This seemed the most appropriate place for it.

tests: fix existing snapshot and add test for dynamic source paths

Adds a simple test for dynamic source paths and updates the snapshot to match new tests / behaivor.

Note: all the line numbers in the snapshot increased by 2 because I added two new lines (the test and a blank one)

tests: add new test in fixtures/sourcing.sh

I added this to the bottom of the file to minimize snapshot diffs. they're large enough as it is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant