in src/documents/templates/deploymentTemplateCodeLenses.ts [106:184]
public async resolve(): Promise<boolean> {
let paramsSource: IParameterValuesSource | undefined;
let errorMessage: string | undefined;
try {
paramsSource = await this.parameterValuesSourceProvider.getValuesSource();
} catch (err) {
if (this.parameterValuesSourceProvider.parameterFileUri) {
if (!await pathExistsNoThrow(this.parameterValuesSourceProvider.parameterFileUri)) {
errorMessage = `$(error) Parameter file not found`;
} else {
errorMessage = `$(error) Could not open parameter file: ${parseError(err).message}`;
}
} else {
errorMessage = parseError(err).message;
}
}
let title: string | undefined;
if (paramsSource && !errorMessage) {
const param = paramsSource.getParameterValue(this.parameterDefinition.nameValue.unquotedValue);
const paramValue = param?.value;
const paramReference = param?.reference;
const givenValueAsString = paramValue?.toFullFriendlyString();
const hasDefaultValue = !!this.parameterDefinition.defaultValue;
if (!!paramReference) {
title = 'Value: (KeyVault reference)';
} else if (givenValueAsString !== undefined) {
title = `Value: ${givenValueAsString}`;
} else if (hasDefaultValue) {
title = "Using default value";
} else {
title = "$(warning) No value found - click here to enter a value";
}
}
if (!title) {
title = errorMessage ?? 'Could not find parameter value';
}
if (title.length > this._maxCharactersInValue) {
// tslint:disable-next-line: prefer-template
title = title.slice(0, this._maxCharactersInValue) + "...";
}
let args: IGotoParameterValueArgs;
if (this.parameterValuesSourceProvider.parameterFileUri) {
// We delay resolving the location if navigating to a parameter file because it could change before the user clicks on the code lens
args = {
inParameterFile: {
parameterFileUri: this.parameterValuesSourceProvider.parameterFileUri,
parameterName: this.parameterDefinition.nameValue.unquotedValue
}
};
} else if (paramsSource) {
// If the parameter doesn't have a value to navigate to, then show the
// properties section or top of the file
let span: Span = paramsSource.getParameterValue(this.parameterDefinition.nameValue.unquotedValue)?.value?.span
?? paramsSource?.parameterValuesProperty?.nameValue.span
?? new Span(0, 0);
const range: Range = getVSCodeRangeFromSpan(paramsSource.document, span);
args = {
inTemplateFile: {
documentUri: paramsSource.document.documentUri,
range
}
};
} else {
return false;
}
this.command = {
title: title,
command: "azurerm-vscode-tools.codeLens.gotoParameterValue",
arguments: [args]
};
return true;
}