Skip to content
21 changes: 17 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@
"@microsoft/vscode-azext-azureutils": "^3.5.2",
"@microsoft/vscode-azext-github": "^1.0.7",
"@microsoft/vscode-azext-utils": "^3.5.1",
"@microsoft/vscode-azureresources-api": "^2.6.3",
"@microsoft/vscode-azureresources-api": "file:../vscode-azureresourcegroups/api/microsoft-vscode-azureresources-api-3.0.0.tgz",
"@vscode/codicons": "0.0.38",
"buffer": "^6.0.3",
"dayjs": "^1.11.3",
Expand Down
54 changes: 54 additions & 0 deletions src/commands/api/createContainerAppsApiProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { callWithTelemetryAndErrorHandling, createApiProvider, maskUserInfo, type apiUtils, type IActionContext } from "@microsoft/vscode-azext-utils";
import { AzExtResourceType, prepareAzureResourcesApiRequest, type AzureResourcesApiRequestContext, type AzureResourcesApiRequestError, type AzureResourcesExtensionApi } from "@microsoft/vscode-azureresources-api";
import { ext } from "../../extensionVariables";
import { localize } from "../../utils/localize";
import { deployImageApi } from "./deployImageApi";
import { deployWorkspaceProjectApi } from "./deployWorkspaceProjectApi";
import type * as api from "./vscode-azurecontainerapps.api";

export function createContainerAppsApiProvider(): apiUtils.AzureExtensionApiProvider {
const v2: string = '^2.0.0';

const context: AzureResourcesApiRequestContext = {
azureResourcesApiVersions: [v2],
clientExtensionId: ext.context.extension.id,

onDidReceiveAzureResourcesApis: async (azureResourcesApis: (AzureResourcesExtensionApi | undefined)[]) => {
await callWithTelemetryAndErrorHandling('containerApps.hostApiRequestSucceeded', (actionContext: IActionContext) => {
actionContext.errorHandling.rethrow = true;

const [rgApiV2] = azureResourcesApis;
if (!rgApiV2) {
throw new Error(localize('noMatchingApi', 'Failed to find a matching Azure Resources API for version "{0}".', v2));
}

ext.rgApiV2 = rgApiV2;
ext.rgApiV2.resources.registerAzureResourceBranchDataProvider(AzExtResourceType.ContainerAppsEnvironment, ext.branchDataProvider);
Copy link
Contributor

@bwateratmsft bwateratmsft Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like these two parts should stay in the extension.ts since they are kinda "what do we do on activation". They can be passed in as a callback to this method.

Not stuck on this, but let me know what you think.

Copy link
Contributor Author

@MicroFish91 MicroFish91 Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good idea so people don't have to hunt around to figure out the activation logic.

});
},

onApiRequestError: async (error: AzureResourcesApiRequestError) => {
await callWithTelemetryAndErrorHandling('containerApps.hostApiRequestFailed', (actionContext: IActionContext) => {
actionContext.telemetry.properties.hostApiRequestErrorCode = error.code;
actionContext.telemetry.properties.hostApiRequestError = maskUserInfo(error.message, []);
});
throw error;
},

};

const containerAppsApi: api.AzureContainerAppsExtensionApi = {
apiVersion: '1.0.0',
deployImage: deployImageApi,
deployWorkspaceProject: deployWorkspaceProjectApi,
};

const { clientApi, requestResourcesApis } = prepareAzureResourcesApiRequest(context, containerAppsApi);
requestResourcesApis();
return createApiProvider([clientApi]);
}
17 changes: 0 additions & 17 deletions src/commands/api/getAzureContainerAppsApiProvider.ts

This file was deleted.

4 changes: 3 additions & 1 deletion src/commands/api/vscode-azurecontainerapps.api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

export interface AzureContainerAppsExtensionApi {
import { type AzureExtensionApi } from "@microsoft/vscode-azureresources-api";

export interface AzureContainerAppsExtensionApi extends AzureExtensionApi {
apiVersion: string;
deployImage(options: DeployImageToAcaOptionsContract): Promise<void>;
deployWorkspaceProject(options: DeployWorkspaceProjectOptionsContract): Promise<DeployWorkspaceProjectResults>;
Expand Down
15 changes: 7 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

import { registerAzureUtilsExtensionVariables } from '@microsoft/vscode-azext-azureutils';
import { registerGitHubExtensionVariables } from '@microsoft/vscode-azext-github';
import { TreeElementStateManager, callWithTelemetryAndErrorHandling, createAzExtOutputChannel, createExperimentationService, registerUIExtensionVariables, type IActionContext, type apiUtils } from '@microsoft/vscode-azext-utils';
import { AzExtResourceType, getAzureResourcesExtensionApi } from '@microsoft/vscode-azureresources-api';
import { TreeElementStateManager, callWithTelemetryAndErrorHandling, createApiProvider, createAzExtOutputChannel, createExperimentationService, registerUIExtensionVariables, type IActionContext, type apiUtils } from '@microsoft/vscode-azext-utils';
import * as vscode from 'vscode';
import { getAzureContainerAppsApiProvider } from './commands/api/getAzureContainerAppsApiProvider';
import { createContainerAppsApiProvider } from './commands/api/createContainerAppsApiProvider';
import { registerCommands } from './commands/registerCommands';
import { RevisionDraftFileSystem } from './commands/revisionDraft/RevisionDraftFileSystem';
import { ext } from './extensionVariables';
Expand All @@ -29,7 +28,8 @@ export async function activate(context: vscode.ExtensionContext, perfStats: { lo
registerAzureUtilsExtensionVariables(ext);
registerGitHubExtensionVariables(ext);

await callWithTelemetryAndErrorHandling('containerApps.activate', async (activateContext: IActionContext) => {
return await callWithTelemetryAndErrorHandling('containerApps.activate', async (activateContext: IActionContext) => {
activateContext.errorHandling.rethrow = true;
activateContext.telemetry.properties.isActivationEvent = 'true';
activateContext.telemetry.measurements.mainFileLoad = (perfStats.loadEndTime - perfStats.loadStartTime) / 1000;

Expand All @@ -40,12 +40,11 @@ export async function activate(context: vscode.ExtensionContext, perfStats: { lo
context.subscriptions.push(vscode.workspace.registerFileSystemProvider(RevisionDraftFileSystem.scheme, ext.revisionDraftFileSystem));

ext.state = new TreeElementStateManager();
ext.rgApiV2 = await getAzureResourcesExtensionApi(context, '2.0.0');
ext.branchDataProvider = new ContainerAppsBranchDataProvider();
ext.rgApiV2.resources.registerAzureResourceBranchDataProvider(AzExtResourceType.ContainerAppsEnvironment, ext.branchDataProvider);
});

return getAzureContainerAppsApiProvider();
return createContainerAppsApiProvider();

}) ?? createApiProvider([]);
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
Expand Down
Loading