function resolveSingleVariable()

in src/utils/resolveVariables.ts [35:82]


function resolveSingleVariable(variable: string, folder?: WorkspaceFolder, additionalVariables?: { [key: string]: string }): string {
    /* eslint-disable no-template-curly-in-string */

    // Replace workspace folder variables
    if (folder) {
        switch (variable) {
            case '${workspaceFolder}':
            case '${workspaceRoot}':
                return path.normalize(folder.uri.fsPath);
            case '${relativeFile}':
                return path.relative(path.normalize(folder.uri.fsPath), getActiveFilePath());
            default:
        }
    }

    // Replace additional variables
    const variableNameOnly = variable.replace(/[${}]/ig, '');
    const replacement = additionalVariables?.[variable] ?? additionalVariables?.[variableNameOnly];
    if (replacement !== undefined) {
        return replacement;
    }

    // Replace config variables
    const configMatch = configVariableMatcher.exec(variable);
    if (configMatch && configMatch.length > 1) {
        const configName: string = configMatch[1]; // Index 1 is the "something.something" group of "${config:something.something}"
        const config = workspace.getConfiguration();
        const configValue = config.get(configName);

        // If it's a simple value we'll return it
        if (typeof (configValue) === 'string') {
            return configValue;
        } else if (typeof (configValue) === 'number' || typeof (configValue) === 'boolean') {
            return configValue.toString();
        }
    }

    // Replace other variables
    switch (variable) {
        case '${file}':
            return getActiveFilePath();
        default:
    }

    return variable; // Return as-is, we don't know what to do with it

    /* eslint-enable no-template-curly-in-string */
}