bash-lsp / bash-language-server

A language server for Bash

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sourcing: "strip one leading, dynamic section before trying to locate the rest"

aarondill opened this issue · comments

What is the problem this feature will solve?

When writing code like this:

here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
. "$here/config.sh"
. "$here/utils.sh"

shellcheck will understand that it should search the script dir for the files, but bash lsp doesn't.

What is the feature you are proposing to solve the problem?

To support the common pattern of . "$CONFIGDIR/mylib.sh", ShellCheck strips one leading, dynamic section before trying to locate the rest. That means that ShellCheck will look for config.sh and utils.sh in the same directory as this script when it is being checked:

So, let's strip one leading, dynamic section before trying to locate the rest 😄

This can work with #811 by only taking effect when the variable is truly dynamic, instead using the value if it's constant (ie set earlier in the script)

What alternatives have you considered?

# shellcheck source=./.utils.d/output.sh - this gets quite frustrating when shellcheck understands the location of the file, but bash-lsp doesn't

See here for shellcheck's documentation about this pattern.