in src/AzureRMTools.ts [895:970]
private considerQueryingForNewerSchema(editor: vscode.TextEditor, deploymentTemplate: DeploymentTemplateDoc): void {
// Only deal with saved files, because we don't have an accurate
// URI that we can track for unsaved files, and it's a better user experience.
if (editor.document.uri.scheme !== documentSchemes.file) {
return;
}
// Only ask to upgrade once per session per file
const document = editor.document;
const documentPath = document.uri.fsPath;
let queriedToUpdateSchema = this._filesAskedToUpdateSchemaThisSession.has(documentPath);
if (queriedToUpdateSchema) {
return;
}
this._filesAskedToUpdateSchemaThisSession.add(documentPath);
const schemaValue: Json.StringValue | undefined = deploymentTemplate.schemaValue;
// tslint:disable-next-line: strict-boolean-expressions
const schemaUri: string | undefined = deploymentTemplate.schemaUri || undefined;
const preferredSchemaUri: string | undefined = schemaUri && getPreferredSchema(schemaUri);
const checkForLatestSchema = !!ext.configuration.get<boolean>(configKeys.checkForLatestSchema);
if (preferredSchemaUri && schemaValue) {
// Don't wait
callWithTelemetryAndErrorHandling('queryUpdateSchema', async (actionContext: IActionContext): Promise<void> => {
actionContext.telemetry.properties.currentSchema = schemaUri;
actionContext.telemetry.properties.preferredSchema = preferredSchemaUri;
actionContext.telemetry.properties.checkForLatestSchema = String(checkForLatestSchema);
if (!checkForLatestSchema) {
return;
}
// tslint:disable-next-line: strict-boolean-expressions
const dontAskFiles = ext.context.globalState.get<string[]>(globalStateKeys.dontAskAboutSchemaFiles) || [];
if (dontAskFiles.includes(documentPath)) {
actionContext.telemetry.properties.isInDontAskList = 'true';
return;
}
const yes: vscode.MessageItem = { title: "Use latest" };
const notNow: vscode.MessageItem = { title: "Not now" };
const neverForThisFile: vscode.MessageItem = { title: "Never for this file" };
const response = await ext.ui.showWarningMessage(
`Warning: You are using a deprecated schema version that is no longer maintained. Would you like us to update "${path.basename(document.uri.path)}" to use the newest schema?`,
{
learnMoreLink: "https://aka.ms/vscode-azurearmtools-updateschema"
},
yes,
notNow,
neverForThisFile
);
actionContext.telemetry.properties.response = response.title;
switch (response.title) {
case yes.title:
await this.replaceSchema(document.uri, deploymentTemplate, schemaValue.unquotedValue, preferredSchemaUri);
actionContext.telemetry.properties.replacedSchema = "true";
return;
case notNow.title:
return;
case neverForThisFile.title:
dontAskFiles.push(documentPath);
await ext.context.globalState.update(globalStateKeys.dontAskAboutSchemaFiles, dontAskFiles);
break;
default:
assert("queryUseNewerSchema: Unexpected response");
break;
}
}).catch(err => {
assert.fail("callWithTelemetryAndErrorHandling in queryUpdateSchema shouldn't throw");
});
}
}