@@ -14,14 +14,20 @@ import which from "which";
1414 * Replace any references to predefined variables in config string.
1515 * https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables
1616 */
17- export function handleConfigOption ( input : string ) : string {
17+ export function handleConfigOption ( input : string , workspaceFolder : vscode . WorkspaceFolder | "none" | "guess" ) : string {
1818 if ( input . includes ( "${userHome}" ) ) {
1919 input = input . replaceAll ( "${userHome}" , os . homedir ( ) ) ;
2020 }
2121
22- if ( vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 0 ) {
23- input = input . replaceAll ( "${workspaceFolder}" , vscode . workspace . workspaceFolders [ 0 ] . uri . fsPath ) ;
24- input = input . replaceAll ( "${workspaceFolderBasename}" , vscode . workspace . workspaceFolders [ 0 ] . name ) ;
22+ if ( workspaceFolder === "guess" ) {
23+ workspaceFolder = vscode . workspace . workspaceFolders ?. length ? vscode . workspace . workspaceFolders [ 0 ] : "none" ;
24+ }
25+
26+ if ( workspaceFolder !== "none" ) {
27+ input = input . replaceAll ( "${workspaceFolder}" , workspaceFolder . uri . fsPath ) ;
28+ input = input . replaceAll ( "${workspaceFolderBasename}" , workspaceFolder . name ) ;
29+ } else {
30+ // This may end up reporting a confusing error message.
2531 }
2632
2733 const document = vscode . window . activeTextEditor ?. document ;
@@ -68,7 +74,7 @@ export function resolveExePathAndVersion(
6874 assert ( cmd . length ) ;
6975
7076 // allow passing predefined variables
71- cmd = handleConfigOption ( cmd ) ;
77+ cmd = handleConfigOption ( cmd , "guess" ) ;
7278
7379 if ( cmd . startsWith ( "~" ) ) {
7480 cmd = path . join ( os . homedir ( ) , cmd . substring ( 1 ) ) ;
0 commit comments