import * as vscode from "vscode" ; import { AzureAccountCommands , VscodeCommands } from "../common/Commands" ; import { DependentExtensionNotFoundError } from "../common/Error/OperationFailedErrors/DependentExtensionNotFoundError" ; import { ExtensionName , ExtensionNameIdMap } from "./Interfaces/Api" ; export function getExtension ( name ) { const extensionId = ExtensionNameIdMap . get ( name ) ; if ( extensionId ) { const extension = vscode . extensions . getExtension ( extensionId ) ; if ( extension ) { switch ( name ) { case ExtensionName . AzureAccount : case ExtensionName . Toolkit : return extension . exports ? extension . exports : undefined ; default : return extension ; } } } return undefined ; } export async function checkAzureLogin ( ) { const azureAccount = getExtension ( ExtensionName . AzureAccount ) ; if ( ! azureAccount ) { throw new DependentExtensionNotFoundError ( "check Azure Login" , ExtensionName . AzureAccount ) ; } if ( azureAccount . status !== "LoggedIn" ) { await vscode . commands . executeCommand ( AzureAccountCommands . Login ) ; } return true ; } export async function checkExtensionAvailable ( extensionName ) { if ( ! getExtension ( extensionName ) ) { const choice = await vscode . window . showInformationMessage ( `${ extensionName } extension is required for the current project. Do you want to install it from marketplace?` , "Yes" , "No" ) ; if ( choice === "Yes" ) { vscode . commands . executeCommand ( VscodeCommands . VscodeOpen , vscode . Uri . parse ( ( "vscode:extension/" + ExtensionNameIdMap . get ( extensionName ) ) as string ) ) ; } return false ; } return true ; }