Skip to content

Commit

Permalink
fix(vscode): Initialize vscode project correctly when project is crea…
Browse files Browse the repository at this point in the history
…ted outside of vscode (#4267)

Update project initialization
  • Loading branch information
ccastrotrejo committed Feb 28, 2024
1 parent 48c61bf commit 2a3ee91
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addInitVSCodeSteps } from '../../initProjectForVSCode/InitVSCodeLanguageStep';
import { WorkflowCodeProjectCreateStep } from './WorkflowCodeProjectCreateStep';
import { InvokeFunctionProjectSetup } from './createFunction/InvokeFunctionProjectSetup';
import { CodeProjectWorkflowStateTypeStep } from './createLogicApp/CodeProjectWorkflowStateTypeStep';
import { addInitVSCodeSteps } from './createLogicApp/initLogicAppCodeProjectVScode/InitVSCode';
import { DesignerConfig } from './createLogicApp/workflowDesigner/DesignerConfig';
import type { AzureWizardExecuteStep, IWizardOptions } from '@microsoft/vscode-azext-utils';
import { AzureWizardPromptStep, nonNullProp } from '@microsoft/vscode-azext-utils';
Expand Down Expand Up @@ -87,7 +87,7 @@ export class NewCodeProjectTypeStep extends AzureWizardPromptStep<IProjectWizard
executeSteps.push(new WorkflowCodeProjectCreateStep(workflowProjectPath));

// Add any necessary steps to initialize the project for Visual Studio Code.
await addInitVSCodeSteps(context, executeSteps);
await addInitVSCodeSteps(context, executeSteps, true);

// Create the sub-wizard options object
const wizardOptions: IWizardOptions<IProjectWizardContext> = { promptSteps, executeSteps };
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function createNewCodeProjectInternal(context: IActionContext, opti
addLocalFuncTelemetry(context);
showPreviewWarning(extensionCommand.createNewCodeProject); //Show warning if command is set to preview

const language: ProjectLanguage | undefined = (options.language as ProjectLanguage) || getGlobalSetting(projectLanguageSetting);
const language: ProjectLanguage | string = (options.language as ProjectLanguage) || getGlobalSetting(projectLanguageSetting);
const version: string = options.version || getGlobalSetting(funcVersionSetting) || (await tryGetLocalFuncVersion()) || latestGAVersion;
const projectTemplateKey: string | undefined = getGlobalSetting(projectTemplateKeySetting);
const wizardContext: Partial<IFunctionWizardContext> & IActionContext = Object.assign(context, options, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class NewProjectTypeStep extends AzureWizardPromptStep<IProjectWizardCont
break;
}

await addInitVSCodeSteps(context, executeSteps);
await addInitVSCodeSteps(context, executeSteps, false);

const wizardOptions: IWizardOptions<IProjectWizardContext> = { promptSteps, executeSteps };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from '../../../localize';
import { WorkflowInitCodeProject } from '../createNewCodeProject/createCodeProjectSteps/createLogicApp/initLogicAppCodeProjectVScode/WorkflowCode';
import { DotnetInitVSCodeStep } from './DotnetInitVSCodeStep';
import { WorkflowInitVSCodeStep } from './WorkflowInitVSCodeStep';
import { isEmptyString } from '@microsoft/utils-logic-apps';
import { AzureWizardPromptStep } from '@microsoft/vscode-azext-utils';
import type { AzureWizardExecuteStep, IWizardOptions } from '@microsoft/vscode-azext-utils';
import type { IProjectWizardContext } from '@microsoft/vscode-extension';
import { ProjectLanguage } from '@microsoft/vscode-extension';
import { ProjectLanguage, WorkflowProjectType } from '@microsoft/vscode-extension';
import type { QuickPickItem, QuickPickOptions } from 'vscode';

export class InitVSCodeLanguageStep extends AzureWizardPromptStep<IProjectWizardContext> {
Expand All @@ -22,26 +24,29 @@ export class InitVSCodeLanguageStep extends AzureWizardPromptStep<IProjectWizard
}

public shouldPrompt(context: IProjectWizardContext): boolean {
return context.language === undefined;
return isEmptyString(context.language);
}

public async getSubWizard(context: IProjectWizardContext): Promise<IWizardOptions<IProjectWizardContext>> {
const executeSteps: AzureWizardExecuteStep<IProjectWizardContext>[] = [];
const promptSteps: AzureWizardPromptStep<IProjectWizardContext>[] = [];
await addInitVSCodeSteps(context, executeSteps);
await addInitVSCodeSteps(context, executeSteps, false);
return { promptSteps, executeSteps };
}
}

export async function addInitVSCodeSteps(
context: IProjectWizardContext,
executeSteps: AzureWizardExecuteStep<IProjectWizardContext>[]
executeSteps: AzureWizardExecuteStep<IProjectWizardContext>[],
isCustomCode: boolean
): Promise<void> {
switch (context.language) {
case ProjectLanguage.JavaScript:
executeSteps.push(new WorkflowInitVSCodeStep());
context.workflowProjectType = WorkflowProjectType.Bundle;
executeSteps.push(isCustomCode ? new WorkflowInitCodeProject() : new WorkflowInitVSCodeStep());
break;
case ProjectLanguage.CSharp:
context.workflowProjectType = WorkflowProjectType.Nuget;
executeSteps.push(new DotnetInitVSCodeStep());
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { tryParseFuncVersion } from '../funcCoreTools/funcVersion';
import { tryGetLogicAppProjectRoot } from '../verifyIsProject';
import { getWorkspaceSetting, updateGlobalSetting } from './settings';
import { verifyTargetFramework } from './verifyTargetFramework';
import { isEmptyString } from '@microsoft/utils-logic-apps';
import type { IActionContext } from '@microsoft/vscode-azext-utils';
import { callWithTelemetryAndErrorHandling, DialogResponses } from '@microsoft/vscode-azext-utils';
import type { FuncVersion } from '@microsoft/vscode-extension';
Expand All @@ -34,10 +35,10 @@ export async function verifyVSCodeConfigOnActivate(
ext.logicAppWorkspace = projectPath;
context.telemetry.suppressIfSuccessful = false;

const language: ProjectLanguage | undefined = getWorkspaceSetting(projectLanguageSetting, projectPath);
const language: ProjectLanguage | string = getWorkspaceSetting(projectLanguageSetting, projectPath);
const version: FuncVersion | undefined = tryParseFuncVersion(getWorkspaceSetting(funcVersionSetting, projectPath));

if (language !== undefined && version !== undefined) {
if (isEmptyString(language) && version !== undefined) {
callWithTelemetryAndErrorHandling('initializeTemplates', async (templatesContext: IActionContext) => {
templatesContext.telemetry.properties.isActivationEvent = 'true';
templatesContext.errorHandling.suppressDisplay = true;
Expand All @@ -63,7 +64,7 @@ async function promptToInitializeProject(workspacePath: string, context: IAction
if (getWorkspaceSetting<boolean>(showProjectWarningSetting)) {
context.telemetry.properties.verifyConfigPrompt = 'initProject';

const learnMoreLink = 'https://aka.ms/azFuncProject';
const learnMoreLink = 'https://aka.ms/lalearn';
const message: string = localize(
'uninitializedWarning',
'Detected an Azure Logic App Project in folder "{0}" that may have been created outside of VS Code. Initialize for optimal use with VS Code?',
Expand Down
9 changes: 0 additions & 9 deletions apps/vs-code-designer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ export async function activate(context: vscode.ExtensionContext) {
...supportedSchemaFileExts,
]);

// temporary fix to uninstall the old DM extension if it exists
const legacyExtension = vscode.extensions.getExtension('ms-azuretools.data-mapper-vscode-extension');
if (legacyExtension !== undefined) {
vscode.commands.executeCommand('workbench.extensions.uninstallExtension', legacyExtension.id);
vscode.window.showWarningMessage(
'The Azure Logic Apps (Standard) extension now includes the Data Mapper capabilities. To avoid conflicts, the standalone Data Mapper extension has been removed. Please restart Visual Studio Code to complete this update.'
);
}

ext.context = context;

ext.outputChannel = createAzExtOutputChannel('Azure Logic Apps (Standard)', ext.prefix);
Expand Down

0 comments on commit 2a3ee91

Please sign in to comment.