import * as path from 'path' ; import * as vscode from 'vscode' ; import { callWithTelemetryAndErrorHandling , DialogResponses , IActionContext } from 'vscode-azureextensionui' ; import { tryGetFunctionProjectRoot } from '../commands/createNewProject/verifyIsProject' ; import { initProjectForVSCode } from '../commands/initProjectForVSCode/initProjectForVSCode' ; import { funcVersionSetting , ProjectLanguage , projectLanguageSetting , TemplateFilter } from '../constants' ; import { ext } from '../extensionVariables' ; import { FuncVersion , tryParseFuncVersion } from '../FuncVersion' ; import { localize } from '../localize' ; import { verifyExtensionsConfig } from '../utils/verifyExtensionBundle' ; import { getWorkspaceSetting , updateGlobalSetting } from './settings' ; import { verifyPythonVenv } from './verifyPythonVenv' ; import { verifyTargetFramework } from './verifyTargetFramework' ; export async function verifyVSCodeConfigOnActivate ( context , folders ) { context . telemetry . suppressIfSuccessful = true ; context . telemetry . properties . isActivationEvent = 'true' ; context . errorHandling . suppressDisplay = true ; if ( folders ) { for ( const folder of folders ) { const workspacePath = folder . uri . fsPath ; const projectPath = await tryGetFunctionProjectRoot ( context , folder , 'prompt' ) ; if ( projectPath ) { context . telemetry . suppressIfSuccessful = false ; const language = getWorkspaceSetting ( projectLanguageSetting , projectPath ) ; const version = tryParseFuncVersion ( getWorkspaceSetting ( funcVersionSetting , projectPath ) ) ; if ( language !== undefined && version !== undefined ) { void callWithTelemetryAndErrorHandling ( 'initializeTemplates' , async ( templatesContext ) => { templatesContext . telemetry . properties . isActivationEvent = 'true' ; templatesContext . errorHandling . suppressDisplay = true ; const templateProvider = ext . templateProvider . get ( templatesContext ) ; await templateProvider . getFunctionTemplates ( templatesContext , projectPath , language , version , TemplateFilter . Verified , undefined ) ; } ) ; let isDotnet = false ; const projectLanguage = getWorkspaceSetting ( projectLanguageSetting , workspacePath ) ; context . telemetry . properties . projectLanguage = projectLanguage ; switch ( projectLanguage ) { case ProjectLanguage . Python : await verifyPythonVenv ( projectPath , context , version ) ; break ; case ProjectLanguage . CSharp : case ProjectLanguage . FSharp : isDotnet = true ; await verifyTargetFramework ( projectLanguage , folder , projectPath , context ) ; break ; default : } if ( ! isDotnet ) { await verifyExtensionsConfig ( context , workspacePath , projectPath ) ; } } else { await promptToInitializeProject ( workspacePath , context ) ; } } } } } async function promptToInitializeProject ( workspacePath , context ) { const settingKey = 'showProjectWarning' ; if ( getWorkspaceSetting < boolean > ( settingKey ) ) { context . telemetry . properties . verifyConfigPrompt = 'initProject' ; const learnMoreLink = 'https://aka.ms/azFuncProject' ; const message = localize ( 'uninitializedWarning' , 'Detected an Azure Functions Project in folder "{0}" that may have been created outside of VS Code. Initialize for optimal use with VS Code?' , path . basename ( workspacePath ) ) ; const result = await context . ui . showWarningMessage ( message , { learnMoreLink } , DialogResponses . yes , DialogResponses . dontWarnAgain ) ; if ( result === DialogResponses . dontWarnAgain ) { context . telemetry . properties . verifyConfigResult = 'dontWarnAgain' ; await updateGlobalSetting ( settingKey , false ) ; } else { context . telemetry . properties . verifyConfigResult = 'update' ; await initProjectForVSCode ( context , workspacePath ) ; } } else { context . telemetry . properties . verifyConfigResult = 'suppressed' ; } }