Skip to content

Commit bf2d846

Browse files
committed
feat: support leading dynamic section when sourcing
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 #926, fixes #659
1 parent 7fffe66 commit bf2d846

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

server/src/util/sourcing.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,23 @@ function getSourcedPathInfoFromNode({
109109
}
110110

111111
if (argumentNode.type === 'string' || argumentNode.type === 'raw_string') {
112+
const stringContents = argumentNode.text.slice(1, -1)
112113
if (argumentNode.namedChildren.length === 0) {
113114
return {
114-
sourcedPath: argumentNode.text.slice(1, -1),
115+
sourcedPath: stringContents,
116+
}
117+
} else if (argumentNode.namedChildren.length === 1) {
118+
const [variableNode] = argumentNode.namedChildren
119+
if (
120+
variableNode.type == 'simple_expansion' ||
121+
variableNode.type == 'expansion'
122+
) {
123+
const variableText = `${variableNode.text}`
124+
if (stringContents.startsWith(variableText + '/')) {
125+
return {
126+
sourcedPath: '.' + stringContents.slice(variableText.length),
127+
}
128+
}
115129
}
116130
}
117131
}

0 commit comments

Comments
 (0)