From c1c79cf3d73eac8c4e5a43cb9893a8f86bc41517 Mon Sep 17 00:00:00 2001 From: Vlad Nikolaenko Date: Tue, 22 Oct 2024 15:27:26 -0700 Subject: [PATCH] feat(stepfunctions): allow closing Workflow Studio and reopening it --- packages/core/package.json | 15 +++++++++++++++ packages/core/package.nls.json | 1 + .../src/shared/telemetry/vscodeTelemetry.json | 10 ++++++++++ packages/core/src/stepFunctions/activation.ts | 11 +++++++++-- .../stepFunctions/workflowStudio/activation.ts | 17 +++++++++++++++++ .../workflowStudio/handleMessage.ts | 17 +++++++++++++++++ .../src/stepFunctions/workflowStudio/types.ts | 1 + .../workflowStudio/workflowStudioEditor.ts | 2 -- 8 files changed, 70 insertions(+), 4 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index b674914d4ca..521044a2abe 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1397,6 +1397,11 @@ "command": "aws.openInApplicationComposer", "when": "isFileSystemResource && !(resourceFilename =~ /^.*\\.tc\\.json$/) && resourceFilename =~ /^.*\\.(json|yml|yaml|template)$/", "group": "z_aws@1" + }, + { + "command": "aws.stepfunctions.openWithWorkflowStudio", + "when": "isFileSystemResource && resourceFilename =~ /^.*\\.asl\\.(json|yml|yaml)$/", + "group": "z_aws@1" } ], "view/item/context": [ @@ -3579,6 +3584,16 @@ "category": "%AWS.title.cn%" } } + }, + { + "command": "aws.stepfunctions.openWithWorkflowStudio", + "title": "%AWS.command.stepFunctions.openWithWorkflowStudio%", + "category": "%AWS.title%", + "cloud9": { + "cn": { + "category": "%AWS.title.cn%" + } + } } ], "jsonValidation": [ diff --git a/packages/core/package.nls.json b/packages/core/package.nls.json index 2b28d7d5c4e..17615b2bbb9 100644 --- a/packages/core/package.nls.json +++ b/packages/core/package.nls.json @@ -185,6 +185,7 @@ "AWS.command.stepFunctions.createStateMachineFromTemplate": "Create a new Step Functions state machine", "AWS.command.stepFunctions.publishStateMachine": "Publish state machine to Step Functions", "AWS.command.stepFunctions.previewStateMachine": "Render state machine graph", + "AWS.command.stepFunctions.openWithWorkflowStudio": "Open with Workflow Studio", "AWS.command.cdk.previewStateMachine": "Render state machine graph from CDK application", "AWS.command.copyLogResource": "Copy Log Stream or Group", "AWS.command.saveCurrentLogDataContent": "Save Log to File", diff --git a/packages/core/src/shared/telemetry/vscodeTelemetry.json b/packages/core/src/shared/telemetry/vscodeTelemetry.json index 5142a126637..acce40a440b 100644 --- a/packages/core/src/shared/telemetry/vscodeTelemetry.json +++ b/packages/core/src/shared/telemetry/vscodeTelemetry.json @@ -516,6 +516,16 @@ } ] }, + { + "name": "stepfunctions_closeWorkflowStudio", + "description": "Called after closing Step Functions Workflow Studio custom editor", + "metadata": [ + { + "type": "id", + "required": true + } + ] + }, { "name": "stepfunctions_saveFile", "description": "Called after the user saves local ASL file (inlcuding autosave) from VSCode editor or Workflow Studio", diff --git a/packages/core/src/stepFunctions/activation.ts b/packages/core/src/stepFunctions/activation.ts index 6aa3e188013..f845d15b4f8 100644 --- a/packages/core/src/stepFunctions/activation.ts +++ b/packages/core/src/stepFunctions/activation.ts @@ -144,6 +144,13 @@ function initializeCodeLens(context: vscode.ExtensionContext) { public async provideCodeLenses(document: vscode.TextDocument): Promise { const topOfDocument = new vscode.Range(0, 0, 0, 0) + const openCustomEditorCommand: vscode.Command = { + command: 'aws.stepfunctions.switchToWorkflowStudio', + title: localize('AWS.command.stepFunctions.openWithWorkflowStudio', 'Open with Workflow Studio'), + arguments: [document.uri], + } + const openCustomEditor = new vscode.CodeLens(topOfDocument, openCustomEditorCommand) + const renderCodeLens = previewStateMachineCommand.build().asCodeLens(topOfDocument, { title: localize('AWS.stepFunctions.render', 'Render graph'), }) @@ -155,9 +162,9 @@ function initializeCodeLens(context: vscode.ExtensionContext) { } const publishCodeLens = new vscode.CodeLens(topOfDocument, publishCommand) - return [publishCodeLens, renderCodeLens] + return [openCustomEditor, publishCodeLens, renderCodeLens] } else { - return [renderCodeLens] + return [openCustomEditor, renderCodeLens] } } } diff --git a/packages/core/src/stepFunctions/workflowStudio/activation.ts b/packages/core/src/stepFunctions/workflowStudio/activation.ts index 44de2cd1d0b..376a5a04df9 100644 --- a/packages/core/src/stepFunctions/workflowStudio/activation.ts +++ b/packages/core/src/stepFunctions/workflowStudio/activation.ts @@ -5,6 +5,7 @@ import * as vscode from 'vscode' import { WorkflowStudioEditorProvider } from './workflowStudioEditorProvider' +import { Commands } from '../../shared/vscode/commands2' /** * Activates the extension and registers all necessary components. @@ -12,4 +13,20 @@ import { WorkflowStudioEditorProvider } from './workflowStudioEditorProvider' */ export async function activate(extensionContext: vscode.ExtensionContext): Promise { extensionContext.subscriptions.push(WorkflowStudioEditorProvider.register(extensionContext)) + + // Open the file with Workflow Studio editor in a new tab, or focus on the tab with WFS if it is already open + extensionContext.subscriptions.push( + Commands.register('aws.stepfunctions.openWithWorkflowStudio', async (uri: vscode.Uri) => { + await vscode.commands.executeCommand('vscode.openWith', uri, WorkflowStudioEditorProvider.viewType) + }) + ) + + // Close the active editor and open the file with Workflow Studio (or close and switch to the existing relevant tab). + // This command is expected to always be called from the active tab in the default editor mode + extensionContext.subscriptions.push( + Commands.register('aws.stepfunctions.switchToWorkflowStudio', async (uri: vscode.Uri) => { + await vscode.commands.executeCommand('workbench.action.closeActiveEditor') + await vscode.commands.executeCommand('vscode.openWith', uri, WorkflowStudioEditorProvider.viewType) + }) + ) } diff --git a/packages/core/src/stepFunctions/workflowStudio/handleMessage.ts b/packages/core/src/stepFunctions/workflowStudio/handleMessage.ts index 1e9194737f7..1daf7470783 100644 --- a/packages/core/src/stepFunctions/workflowStudio/handleMessage.ts +++ b/packages/core/src/stepFunctions/workflowStudio/handleMessage.ts @@ -41,6 +41,9 @@ export async function handleMessage(message: Message, context: WebviewContext) { case Command.AUTO_SAVE_FILE: void autoSaveFileMessageHandler(message as SaveFileRequestMessage, context) break + case Command.CLOSE_WFS: + void closeCustomEditorMessageHandler(context) + break case Command.OPEN_FEEDBACK: void submitFeedback(placeholder, 'Workflow Studio') break @@ -107,6 +110,20 @@ async function loadStageMessageHandler(context: WebviewContext) { }, 100) } +/** + * Handler for closing WFS custom editor. When called, disposes webview panel and opens default VSCode editor + * @param context The context object containing the necessary information for the webview. + */ +export function closeCustomEditorMessageHandler(context: WebviewContext) { + telemetry.stepfunctions_closeWorkflowStudio.run((span) => { + span.record({ + id: context.fileId, + }) + context.panel.dispose() + void vscode.commands.executeCommand('vscode.openWith', context.textDocument.uri, 'default') + }) +} + /** * Handler for saving a file from the webview which updates the workspace and saves the file. * Triggered when the user explicitly applies save action in WFS diff --git a/packages/core/src/stepFunctions/workflowStudio/types.ts b/packages/core/src/stepFunctions/workflowStudio/types.ts index 569dfbc3f36..7d03a027fd3 100644 --- a/packages/core/src/stepFunctions/workflowStudio/types.ts +++ b/packages/core/src/stepFunctions/workflowStudio/types.ts @@ -38,6 +38,7 @@ export enum Command { FILE_CHANGED = 'FILE_CHANGED', LOAD_STAGE = 'LOAD_STAGE', OPEN_FEEDBACK = 'OPEN_FEEDBACK', + CLOSE_WFS = 'CLOSE_WFS', } export type FileWatchInfo = { diff --git a/packages/core/src/stepFunctions/workflowStudio/workflowStudioEditor.ts b/packages/core/src/stepFunctions/workflowStudio/workflowStudioEditor.ts index f5121eb7c73..8637816beae 100644 --- a/packages/core/src/stepFunctions/workflowStudio/workflowStudioEditor.ts +++ b/packages/core/src/stepFunctions/workflowStudio/workflowStudioEditor.ts @@ -6,7 +6,6 @@ import * as path from 'path' import * as vscode from 'vscode' import { telemetry } from '../../shared/telemetry/telemetry' -import { getLogger } from '../../shared/logger' import { i18n } from '../../shared/i18n-helper' import { broadcastFileChange } from './handleMessage' import { FileWatchInfo, WebviewContext } from './types' @@ -113,7 +112,6 @@ export class WorkflowStudioEditor { async (progress, token) => { token.onCancellationRequested(async () => { // Cancel opening in Worflow Studio and open regular code editor instead - getLogger().debug('WorkflowStudio: Canceled opening') contextObject.panel.dispose() await vscode.commands.executeCommand('vscode.openWith', documentUri, 'default') throw new CancellationError('user')