diff --git a/package.json b/package.json index effb14c1..bf003f85 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,11 @@ "command": "azure-pipelines.configure-pipeline", "title": "Configure Pipeline", "category": "Azure Pipelines" + }, + { + "command": "azure-pipelines.reset-state", + "title": "Reset 'do not ask again' messages", + "category": "Azure Pipelines" } ], "menus": { diff --git a/src/extension.ts b/src/extension.ts index 71e1def0..b24482c4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -8,7 +8,7 @@ import * as vscode from 'vscode'; import * as languageclient from 'vscode-languageclient/node'; import * as logger from './logger'; -import { getSchemaAssociation, locateSchemaFile, onDidSelectOrganization, SchemaAssociationNotification } from './schema-association-service'; +import { getSchemaAssociation, locateSchemaFile, onDidSelectOrganization, resetDoNotAskState, SchemaAssociationNotification } from './schema-association-service'; import { schemaContributor, CUSTOM_SCHEMA_REQUEST, CUSTOM_CONTENT_REQUEST } from './schema-contributor'; import { telemetryHelper } from './helpers/telemetryHelper'; import { getAzureAccountExtensionApi } from './extensionApis'; @@ -115,6 +115,8 @@ async function activateYmlContributor(context: vscode.ExtensionContext) { context.subscriptions.push(onDidSelectOrganization(async workspaceFolder => { await loadSchema(context, client, workspaceFolder); })); + + context.subscriptions.push(vscode.commands.registerCommand("azure-pipelines.reset-state", async () => await resetDoNotAskState(context))); } // Find the schema and notify the server. diff --git a/src/schema-association-service.ts b/src/schema-association-service.ts index 7f9a3df8..67c5c569 100644 --- a/src/schema-association-service.ts +++ b/src/schema-association-service.ts @@ -28,8 +28,17 @@ export const onDidSelectOrganization = selectOrganizationEvent.event; const seenOrganizations = new Set(); const lastUpdated1ESPTSchema = new Map(); +export const DO_NOT_ASK_SIGN_IN_KEY = "DO_NOT_ASK_SIGN_IN_KEY"; +export const DO_NOT_ASK_SELECT_ORG_KEY = "DO_NOT_ASK_SELECT_ORG_KEY"; + let repoId1espt: string | undefined = undefined; +export async function resetDoNotAskState(context: vscode.ExtensionContext) { + await context.globalState.update(DO_NOT_ASK_SIGN_IN_KEY, undefined); + await context.globalState.update(DO_NOT_ASK_SELECT_ORG_KEY, undefined); + logger.log("State is reset"); +} + export async function locateSchemaFile( context: vscode.ExtensionContext, workspaceFolder: vscode.WorkspaceFolder | undefined): Promise { @@ -105,6 +114,12 @@ async function autoDetectSchema( // can't return until the sessions are also available. // This only returns false if there is no login. if (!(await azureAccountApi.waitForSubscriptions())) { + const doNotAskAgainSignIn = context.globalState.get(DO_NOT_ASK_SIGN_IN_KEY); + if (doNotAskAgainSignIn) { + logger.log(`Not prompting for login - do not ask again was set`, 'SchemaDetection'); + return undefined; + } + logger.log(`Waiting for login`, 'SchemaDetection'); try { @@ -117,7 +132,7 @@ async function autoDetectSchema( // Don't await this message so that we can return the fallback schema instead of blocking. // We'll detect the login in extension.ts and then re-request the schema. - void vscode.window.showInformationMessage(Messages.signInForEnhancedIntelliSense, Messages.signInLabel) + void vscode.window.showInformationMessage(Messages.signInForEnhancedIntelliSense, Messages.signInLabel, Messages.doNotAskAgain) .then(async action => { if (action === Messages.signInLabel) { await vscode.window.withProgress({ @@ -126,6 +141,8 @@ async function autoDetectSchema( }, async () => { await vscode.commands.executeCommand("azure-account.login"); }); + } else if (action === Messages.doNotAskAgain) { + await context.globalState.update(DO_NOT_ASK_SIGN_IN_KEY, true); } }); @@ -190,6 +207,12 @@ async function autoDetectSchema( `Using cached information for ${workspaceFolder.name}: ${organizationName}, ${session?.tenantId}`, 'SchemaDetection'); } else { + const doNotAskAgainSelectOrg = context.globalState.get(DO_NOT_ASK_SELECT_ORG_KEY); + if (doNotAskAgainSelectOrg) { + logger.log(`Not prompting for organization - do not ask again was set`, 'SchemaDetection'); + return; + } + logger.log(`Prompting for organization for ${workspaceFolder.name}`, 'SchemaDetection'); // Otherwise, we need to manually prompt. @@ -199,7 +222,7 @@ async function autoDetectSchema( // We'll detect when they choose the organization in extension.ts and then re-request the schema. void vscode.window.showInformationMessage( format(Messages.selectOrganizationForEnhancedIntelliSense, workspaceFolder.name), - Messages.selectOrganizationLabel) + Messages.selectOrganizationLabel, Messages.doNotAskAgain) .then(async action => { if (action === Messages.selectOrganizationLabel) { // Lazily construct list of organizations so that we can immediately show the quick pick, @@ -237,6 +260,8 @@ async function autoDetectSchema( }); selectOrganizationEvent.fire(workspaceFolder); + } else if (action === Messages.doNotAskAgain) { + await context.globalState.update(DO_NOT_ASK_SELECT_ORG_KEY, true); } }); return undefined;