Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user defined variables for all .json configuration files #137660

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { IPathService } from 'vs/workbench/services/path/common/pathService';
export abstract class BaseConfigurationResolverService extends AbstractVariableResolverService {

static readonly INPUT_OR_COMMAND_VARIABLES_PATTERN = /\${((input|command):(.*?))}/g;
static readonly USER_DEFINED_VARIABLES_PATTERN = /\${((params):(.*?))}/g;

constructor(
context: {
Expand Down Expand Up @@ -209,6 +210,11 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
throw new Error(nls.localize('commandVariable.noStringType', "Cannot substitute command variable '{0}' because command did not return a result of type string.", commandId));
}
break;
case 'params':
// user should give their variables inside a params. So we check for a params.
if (configuration.params) {
result = configuration.params?.name ?? '';
}
default:
// Try to resolve it as a contributed variable
if (this._contributedVariables.has(variable)) {
Expand Down Expand Up @@ -242,6 +248,14 @@ export abstract class BaseConfigurationResolverService extends AbstractVariableR
}
}
}
while ((matches = BaseConfigurationResolverService.USER_DEFINED_VARIABLES_PATTERN.exec(object)) !== null) {
if (matches.length === 4) {
const command = matches[1];
if (variables.indexOf(command) < 0) {
variables.push(command);
}
}
}
this._contributedVariables.forEach((value, contributed: string) => {
if ((variables.indexOf(contributed) < 0) && (object.indexOf('${' + contributed + '}') >= 0)) {
variables.push(contributed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,35 @@ suite('Configuration Resolver Service', () => {
});
});
});

test('user defined variables inside params key', () => {
const configuration = {
'params': {
'git_version': '2.30.0',
'node_version': '14.16.1',
'python_version': '3.8',
'port': '5858',
},
'node_version': '${params:node_version}',
'port': '${params:port}',
'virtual_env': 'virtualenv .venv --python=python${params:python_version}'
};

return configurationResolverService!.resolveWithInteractionReplace(workspace, configuration, 'tasks').then(result => {
assert.deepStrictEqual({ ...result }, {
'params': {
'git_version': '2.30.0',
'node_version': '14.16.1',
'python_version': '3.8',
'port': '5858',
},
'node_version': '14.16.1',
'port': '5858',
'virtual_env': 'virtualenv .venv --python=python3.8'
});
});
})

});


Expand Down