77
88import { registerAppServiceExtensionVariables } from '@microsoft/vscode-azext-azureappservice' ;
99import { registerAzureUtilsExtensionVariables , type AzureAccountTreeItemBase } from '@microsoft/vscode-azext-azureutils' ;
10- import { callWithTelemetryAndErrorHandling , createApiProvider , createAzExtOutputChannel , createExperimentationService , registerErrorHandler , registerEvent , registerReportIssueCommand , registerUIExtensionVariables , type IActionContext , type apiUtils } from '@microsoft/vscode-azext-utils' ;
10+ import { callWithTelemetryAndErrorHandling , createApiProvider , createAzExtOutputChannel , createExperimentationService , registerErrorHandler , registerEvent , registerOnActionStartHandler , registerReportIssueCommand , registerUIExtensionVariables , type apiUtils , type IActionContext } from '@microsoft/vscode-azext-utils' ;
1111import { AzExtResourceType , getAzureResourcesExtensionApi } from '@microsoft/vscode-azureresources-api' ;
1212import * as vscode from 'vscode' ;
1313import { FunctionAppResolver } from './FunctionAppResolver' ;
@@ -16,7 +16,14 @@ import { createFunctionFromApi } from './commands/api/createFunctionFromApi';
1616import { downloadAppSettingsFromApi } from './commands/api/downloadAppSettingsFromApi' ;
1717import { revealTreeItem } from './commands/api/revealTreeItem' ;
1818import { uploadAppSettingsFromApi } from './commands/api/uploadAppSettingsFromApi' ;
19+ import { copyFunctionUrl } from './commands/copyFunctionUrl' ;
1920import { runPostFunctionCreateStepsFromCache } from './commands/createFunction/FunctionCreateStepBase' ;
21+ import { createFunctionInternal } from './commands/createFunction/createFunction' ;
22+ import { createFunctionApp , createFunctionAppAdvanced } from './commands/createFunctionApp/createFunctionApp' ;
23+ import { createNewProjectInternal } from './commands/createNewProject/createNewProject' ;
24+ import { deleteFunctionApp } from './commands/deleteFunctionApp' ;
25+ import { deployProductionSlot } from './commands/deploy/deploy' ;
26+ import { initProjectForVSCode } from './commands/initProjectForVSCode/initProjectForVSCode' ;
2027import { startFuncProcessFromApi } from './commands/pickFuncProcess' ;
2128import { registerCommands } from './commands/registerCommands' ;
2229import { func } from './constants' ;
@@ -27,12 +34,13 @@ import { NodeDebugProvider } from './debug/NodeDebugProvider';
2734import { PowerShellDebugProvider } from './debug/PowerShellDebugProvider' ;
2835import { PythonDebugProvider } from './debug/PythonDebugProvider' ;
2936import { handleUri } from './downloadAzureProject/handleUri' ;
30- import { ext } from './extensionVariables' ;
37+ import { ext , TemplateSource } from './extensionVariables' ;
3138import { registerFuncHostTaskEvents } from './funcCoreTools/funcHostTask' ;
3239import { validateFuncCoreToolsInstalled } from './funcCoreTools/validateFuncCoreToolsInstalled' ;
3340import { validateFuncCoreToolsIsLatest } from './funcCoreTools/validateFuncCoreToolsIsLatest' ;
3441import { getResourceGroupsApi } from './getExtensionApi' ;
3542import { CentralTemplateProvider } from './templates/CentralTemplateProvider' ;
43+ import type { TestApi } from './testApi' ;
3644import { ShellContainerClient } from './tree/durableTaskScheduler/ContainerClient' ;
3745import { HttpDurableTaskSchedulerClient } from './tree/durableTaskScheduler/DurableTaskSchedulerClient' ;
3846import { DurableTaskSchedulerDataBranchProvider } from './tree/durableTaskScheduler/DurableTaskSchedulerDataBranchProvider' ;
@@ -137,24 +145,81 @@ export async function activateInternal(context: vscode.ExtensionContext, perfSta
137145 new DurableTaskSchedulerWorkspaceDataBranchProvider ( emulatorClient ) ) ;
138146 } ) ;
139147
140- console . log ( 'Activated Azure Functions extension...' ) ;
141- console . log ( '**********************************************' ) ;
148+ const apis : ( AzureFunctionsExtensionApi | TestApi ) [ ] = [
149+ < AzureFunctionsExtensionApi > {
150+ revealTreeItem,
151+ createFunction : createFunctionFromApi ,
152+ downloadAppSettings : downloadAppSettingsFromApi ,
153+ uploadAppSettings : uploadAppSettingsFromApi ,
154+ listLocalProjects : listLocalProjects ,
155+ listLocalFunctions : listLocalFunctions ,
156+ isFuncCoreToolsInstalled : async ( message : string ) => {
157+ return await callWithTelemetryAndErrorHandling ( 'azureFunctions.api.isFuncCoreToolsInstalled' , async ( context : IActionContext ) => {
158+ return await validateFuncCoreToolsInstalled ( context , message , undefined ) ;
159+ } ) ;
160+ } ,
161+ startFuncProcess : startFuncProcessFromApi ,
162+ apiVersion : '1.10.0'
163+ }
164+ ] ;
165+
166+ // Add test API when running tests
167+ // This allows tests to access and override internal extension state without changing the public API.
168+ if ( process . env . VSCODE_RUNNING_TESTS ) {
169+ // Cache of template providers keyed by source, for use across test runs
170+ const testTemplateProviders = new Map < string , CentralTemplateProvider > ( ) ;
171+
172+ apis . push ( < TestApi > {
173+ apiVersion : '99.0.0' ,
174+ extensionVariables : {
175+ getOutputChannel : ( ) => ext . outputChannel ,
176+ getContext : ( ) => ext . context ,
177+ getRgApi : ( ) => ext . rgApi ,
178+ getIgnoreBundle : ( ) => ext . ignoreBundle
179+ } ,
180+ testing : {
181+ setIgnoreBundle : ( ignoreBundle ) => {
182+ ext . ignoreBundle = ignoreBundle ;
183+ } ,
184+ registerOnActionStartHandler,
185+ } ,
186+ commands : {
187+ createFunctionApp,
188+ createFunctionAppAdvanced,
189+ deleteFunctionApp,
190+ deployProductionSlot,
191+ copyFunctionUrl,
192+ createNewProjectInternal,
193+ createFunctionInternal,
194+ initProjectForVSCode,
195+ registerTemplateSource : ( context , source ) => {
196+ let cached = testTemplateProviders . get ( source ) ;
197+ if ( ! cached ) {
198+ cached = new CentralTemplateProvider ( source as TemplateSource ) ;
199+ testTemplateProviders . set ( source , cached ) ;
200+ }
201+ ext . templateProvider . registerActionVariable ( cached , context ) ;
202+ } ,
203+ getFunctionTemplates : async ( context , projectPath , language , languageModel , version , templateFilter , projectTemplateKey , source ) => {
204+ let provider : CentralTemplateProvider ;
205+ if ( source ) {
206+ let cached = testTemplateProviders . get ( source ) ;
207+ if ( ! cached ) {
208+ cached = new CentralTemplateProvider ( source as TemplateSource ) ;
209+ testTemplateProviders . set ( source , cached ) ;
210+ }
211+ provider = cached ;
212+ ext . templateProvider . registerActionVariable ( provider , context ) ;
213+ } else {
214+ provider = ext . templateProvider . get ( context ) ;
215+ }
216+ return provider . getFunctionTemplates ( context , projectPath , language , languageModel , version , templateFilter , projectTemplateKey ) ;
217+ }
218+ }
219+ } ) ;
220+ }
142221
143- return createApiProvider ( [ < AzureFunctionsExtensionApi > {
144- revealTreeItem,
145- createFunction : createFunctionFromApi ,
146- downloadAppSettings : downloadAppSettingsFromApi ,
147- uploadAppSettings : uploadAppSettingsFromApi ,
148- listLocalProjects : listLocalProjects ,
149- listLocalFunctions : listLocalFunctions ,
150- isFuncCoreToolsInstalled : async ( message : string ) => {
151- return await callWithTelemetryAndErrorHandling ( 'azureFunctions.api.isFuncCoreToolsInstalled' , async ( context : IActionContext ) => {
152- return await validateFuncCoreToolsInstalled ( context , message , undefined ) ;
153- } ) ;
154- } ,
155- startFuncProcess : startFuncProcessFromApi ,
156- apiVersion : '1.10.0'
157- } ] ) ;
222+ return createApiProvider ( apis ) ;
158223}
159224
160225export async function deactivateInternal ( ) : Promise < void > {
0 commit comments