Changes to support other extensions (#3754)

This commit is contained in:
Brandon Waterloo [MSFT] 2024-04-23 11:51:47 -04:00 коммит произвёл GitHub
Родитель 88369c36ce
Коммит ed6f8c4e53
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 63 добавлений и 15 удалений

Просмотреть файл

@ -11,18 +11,26 @@ import { TelemetryId } from '../telemetry/telemetryId';
interface InitCommandOptions {
templateUrl?: string;
useExistingSource?: boolean;
environmentName?: string;
}
export async function init(context: IActionContext, selectedFile?: vscode.Uri, allSelectedFiles?: vscode.Uri, options?: InitCommandOptions): Promise<void> {
/**
* A tuple representing the arguments that must be passed to the `init` command when executed via {@link vscode.commands.executeCommand}
*/
export type InitCommandArguments = [ vscode.Uri | undefined, vscode.Uri[] | undefined, InitCommandOptions | undefined, boolean? ];
export async function init(context: IActionContext, selectedFile?: vscode.Uri, allSelectedFiles?: vscode.Uri[], options?: InitCommandOptions, fromAgent: boolean = false): Promise<void> {
context.telemetry.properties.fromAgent = fromAgent.toString();
let folder: vscode.WorkspaceFolder | undefined = (selectedFile ? vscode.workspace.getWorkspaceFolder(selectedFile) : undefined);
if (!folder) {
folder = await quickPickWorkspaceFolder(context, vscode.l10n.t("To run '{0}' command you must first open a folder or workspace in VS Code", 'init'));
}
let templateUrl: string | undefined = options?.templateUrl;
let useExistingSource: boolean = false;
if (!templateUrl) {
let useExistingSource: boolean = !!options?.useExistingSource;
if (!templateUrl && !useExistingSource) {
const selection = await selectApplicationTemplate(context);
templateUrl = selection.templateUrl;
useExistingSource = selection.useExistingSource;
@ -46,6 +54,7 @@ export async function init(context: IActionContext, selectedFile?: vscode.Uri, a
// Don't wait
void executeAsTask(command.build(), getAzDevTerminalTitle(), {
focus: true,
alwaysRunNew: true,
cwd: workspacePath.fsPath,
env: azureCli.env

Просмотреть файл

@ -13,7 +13,14 @@ const WindowsTerminalCommand = `powershell -ex AllSigned -c "Invoke-RestMethod '
const LinuxTerminalCommand = `curl -fsSL https://aka.ms/install-azd.sh | bash`;
const MacTerminalCommand = LinuxTerminalCommand; // Same as Linux
export async function installCli(context: IActionContext, shouldPrompt: boolean = true): Promise<void> {
/**
* A tuple representing the arguments that must be passed to the `installCli` command when executed via {@link vscode.commands.executeCommand}
*/
export type InstallCliCommandArguments = [ boolean?, boolean? ];
export async function installCli(context: IActionContext, shouldPrompt: boolean = true, fromAgent: boolean = false): Promise<void> {
context.telemetry.properties.fromAgent = fromAgent.toString();
if (shouldPrompt) {
const message = vscode.l10n.t('This will install or update the Azure Developer CLI. Do you want to continue?');
// Don't need to check the result, if the user chooses cancel a UserCancelledError will be thrown

Просмотреть файл

@ -6,7 +6,14 @@ import { createAzureDevCli, onAzdLoginAttempted } from '../utils/azureDevCli';
import { executeAsTask } from '../utils/executeAsTask';
import { getAzDevTerminalTitle } from './cmdUtil';
export async function loginCli(context: IActionContext, shouldPrompt: boolean = true): Promise<void> {
/**
* A tuple representing the arguments that must be passed to the `loginCli` command when executed via {@link vscode.commands.executeCommand}
*/
export type LoginCliCommandArguments = [ boolean? ];
export async function loginCli(context: IActionContext, fromAgent: boolean = false): Promise<void> {
context.telemetry.properties.fromAgent = fromAgent.toString();
const azureCli = await createAzureDevCli(context);
const command = azureCli.commandBuilder.withArgs(['auth', 'login']);

Просмотреть файл

@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Licensed under the MIT License.
import * as vscode from 'vscode';
import { IActionContext } from '@microsoft/vscode-azext-utils';
@ -10,7 +10,14 @@ import { TelemetryId } from '../telemetry/telemetryId';
import { isTreeViewModel, TreeViewModel } from '../utils/isTreeViewModel';
import { AzureDevCliApplication } from '../views/workspace/AzureDevCliApplication';
export async function pipelineConfig(context: IActionContext, selectedItem?: vscode.Uri | TreeViewModel): Promise<void> {
/**
* A tuple representing the arguments that must be passed to the `init` command when executed via {@link vscode.commands.executeCommand}
*/
export type PipelineConfigCommandArguments = [ vscode.Uri | undefined, boolean? ];
export async function pipelineConfig(context: IActionContext, selectedItem?: vscode.Uri | TreeViewModel, fromAgent: boolean = false): Promise<void> {
context.telemetry.properties.fromAgent = fromAgent.toString();
const selectedFile = isTreeViewModel(selectedItem) ? selectedItem.unwrap<AzureDevCliApplication>().context.configurationFile : selectedItem;
const workingFolder = await getWorkingFolder(context, selectedFile);

Просмотреть файл

@ -10,7 +10,14 @@ import { TelemetryId } from '../telemetry/telemetryId';
import { AzureDevCliApplication } from '../views/workspace/AzureDevCliApplication';
import { isTreeViewModel, TreeViewModel } from '../utils/isTreeViewModel';
export async function up(context: IActionContext, selectedItem?: vscode.Uri | TreeViewModel): Promise<void> {
/**
* A tuple representing the arguments that must be passed to the `up` command when executed via {@link vscode.commands.executeCommand}
*/
export type UpCommandArguments = [ vscode.Uri | TreeViewModel | undefined, boolean? ];
export async function up(context: IActionContext, selectedItem?: vscode.Uri | TreeViewModel, fromAgent: boolean = false): Promise<void> {
context.telemetry.properties.fromAgent = fromAgent.toString();
const selectedFile = isTreeViewModel(selectedItem) ? selectedItem.unwrap<AzureDevCliApplication>().context.configurationFile : selectedItem;
const workingFolder = await getWorkingFolder(context, selectedFile);

Просмотреть файл

@ -9,7 +9,7 @@ import { DotEnvTaskProvider } from './tasks/dotEnvTaskProvider';
import { TelemetryId } from './telemetry/telemetryId';
import { scheduleSurveys } from './telemetry/surveyScheduler';
import { ActivityStatisticsService } from './telemetry/activityStatisticsService';
import { scheduleAzdSignInCheck, scheduleAzdVersionCheck, scheduleAzdYamlCheck } from './utils/azureDevCli';
import { LoginStatus, getAzdLoginStatus, scheduleAzdSignInCheck, scheduleAzdVersionCheck, scheduleAzdYamlCheck } from './utils/azureDevCli';
import { activeSurveys } from './telemetry/activeSurveys';
import { scheduleRegisterWorkspaceComponents } from './views/workspace/scheduleRegisterWorkspaceComponents';
import { registerLanguageFeatures } from './language/languageFeatures';
@ -20,12 +20,19 @@ type LoadStats = {
loadEndTime: number | undefined
};
export async function activateInternal(vscodeCtx: vscode.ExtensionContext, loadStats: LoadStats) {
interface AzdExtensionApi {
/**
* @deprecated This is only temporary and should not be relied on.
*/
getAzdLoginStatus(): Promise<LoginStatus | undefined>
}
export async function activateInternal(vscodeCtx: vscode.ExtensionContext, loadStats: LoadStats): Promise<AzdExtensionApi> {
loadStats.loadEndTime = Date.now();
function registerDisposable<T extends vscode.Disposable>(disposable: T): T {
vscodeCtx.subscriptions.push(disposable);
return disposable;
}
@ -34,7 +41,7 @@ export async function activateInternal(vscodeCtx: vscode.ExtensionContext, loadS
ext.ignoreBundle = false;
ext.outputChannel = registerDisposable(createAzExtOutputChannel('Azure Developer', "azure-dev"));
registerUIExtensionVariables(ext);
await callWithTelemetryAndErrorHandling(TelemetryId.Activation, async (activationCtx: IActionContext) => {
activationCtx.errorHandling.rethrow = true;
activationCtx.telemetry.properties.isActivationEvent = 'true';
@ -54,6 +61,10 @@ export async function activateInternal(vscodeCtx: vscode.ExtensionContext, loadS
scheduleAzdSignInCheck();
scheduleAzdYamlCheck();
});
return {
getAzdLoginStatus
};
}
export async function deactivateInternal(): Promise<void> {

Просмотреть файл

@ -20,7 +20,7 @@ const AzdLoginCheckCacheLifetime = 15 * 60 * 1000; // 15 minutes
let azdInstallAttempted: boolean = false;
const azdLoginChecker = new AsyncLazy<LoginStatus | undefined>(getAzdLoginStatus, AzdLoginCheckCacheLifetime);
interface LoginStatus {
export interface LoginStatus {
readonly status: 'success' | 'unauthenticated' | string;
readonly expiresOn?: string;
}
@ -59,7 +59,7 @@ export function scheduleAzdVersionCheck(): void {
const versionResult = await getAzdVersion();
if (versionResult && !semver.gte(versionResult, minimumSupportedVersion)) {
// We won't show a warning if AZD is not installed, but if it is installed and less than 0.8.0, we will warn
// We won't show a warning if AZD is not installed, but if it is installed and less than the minimum, we will warn
const install: vscode.MessageItem = {
title: vscode.l10n.t('Update'),
@ -197,7 +197,7 @@ async function getAzdVersion(): Promise<semver.SemVer | undefined> {
}
}
async function getAzdLoginStatus(): Promise<LoginStatus | undefined> {
export async function getAzdLoginStatus(): Promise<LoginStatus | undefined> {
const cli = createCli();
const command = cli.commandBuilder.withArgs(['auth', 'login', '--check-status', '--output', 'json']).build();
try {