bash-language-server icon indicating copy to clipboard operation
bash-language-server copied to clipboard

feat: support leading dynamic section when sourcing

Open aarondill opened this issue 2 years ago • 5 comments

This does the same thing that ShellCheck does (here).

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

fixes #926, fixes #659

aarondill avatar Jan 21 '24 11:01 aarondill

this can now handle all the below cases:
. "$dir/file"
. "$dir/other/file"
. "$dir"/file
. $dir/file
. $dir"/file"
. "$dir"/"file"
. "${dir:-.}"/"file"
. ${dir}/"fi"l'e'
source "$dir/file"
It intentionally fails on these:
. "$dir/$file"
. "$dir/other/$file"
. "$(cmd)/file"
. $(cmd)/file
Tests are coming soon! (once i figure out this testing framework)

aarondill avatar Jan 21 '24 14:01 aarondill

It intentionally fails on these:

is there a way to make it work? seems that's the much more usage case.

Shane-XB-Qian avatar Feb 06 '24 10:02 Shane-XB-Qian

It intentionally fails on these:

is there a way to make it work? seems that's the much more usage case.

potentially, but these cases are process substitution and dynamic file sourcing. if you really want to use process substitution, assign it to a variable, then use that - this way it will work with shellcheck too. as to dynamic file sourcing, at the point this is evaluated, there's no way to get the "static" value of a variable, so there's no meaningful way to support that.

the current implementation matches shellcheck's behavior

aarondill avatar Feb 06 '24 14:02 aarondill

there's no way

:thinking: ok, anyway, this looks was an good improvement.

Shane-XB-Qian avatar Feb 06 '24 15:02 Shane-XB-Qian

This would be great! All of our sources are of the form . "$ScriptDir/something.sh" or . "$ScriptDir/dir/something.sh".

isc-aray avatar Jun 03 '24 14:06 isc-aray