Skip to content

Commit 8e8836d

Browse files
author
Vlad Nikolaenko
committed
feat(stepfunctions): allow closing Workflow Studio and reopening it
1 parent ba27519 commit 8e8836d

File tree

8 files changed

+69
-4
lines changed

8 files changed

+69
-4
lines changed

packages/core/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,11 @@
13971397
"command": "aws.openInApplicationComposer",
13981398
"when": "isFileSystemResource && !(resourceFilename =~ /^.*\\.tc\\.json$/) && resourceFilename =~ /^.*\\.(json|yml|yaml|template)$/",
13991399
"group": "z_aws@1"
1400+
},
1401+
{
1402+
"command": "aws.stepfunctions.openWithWorkflowStudio",
1403+
"when": "isFileSystemResource && resourceFilename =~ /^.*\\.asl\\.(json|yml|yaml)$/",
1404+
"group": "z_aws@1"
14001405
}
14011406
],
14021407
"view/item/context": [
@@ -3579,6 +3584,16 @@
35793584
"category": "%AWS.title.cn%"
35803585
}
35813586
}
3587+
},
3588+
{
3589+
"command": "aws.stepfunctions.openWithWorkflowStudio",
3590+
"title": "%AWS.command.stepFunctions.openWithWorkflowStudio%",
3591+
"category": "%AWS.title%",
3592+
"cloud9": {
3593+
"cn": {
3594+
"category": "%AWS.title.cn%"
3595+
}
3596+
}
35823597
}
35833598
],
35843599
"jsonValidation": [

packages/core/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
"AWS.command.stepFunctions.createStateMachineFromTemplate": "Create a new Step Functions state machine",
186186
"AWS.command.stepFunctions.publishStateMachine": "Publish state machine to Step Functions",
187187
"AWS.command.stepFunctions.previewStateMachine": "Render state machine graph",
188+
"AWS.command.stepFunctions.openWithWorkflowStudio": "Open with Workflow Studio",
188189
"AWS.command.cdk.previewStateMachine": "Render state machine graph from CDK application",
189190
"AWS.command.copyLogResource": "Copy Log Stream or Group",
190191
"AWS.command.saveCurrentLogDataContent": "Save Log to File",

packages/core/src/shared/telemetry/vscodeTelemetry.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,16 @@
516516
}
517517
]
518518
},
519+
{
520+
"name": "stepfunctions_closeWorkflowStudio",
521+
"description": "Called after closing Step Functions Workflow Studio custom editor",
522+
"metadata": [
523+
{
524+
"type": "id",
525+
"required": true
526+
}
527+
]
528+
},
519529
{
520530
"name": "stepfunctions_saveFile",
521531
"description": "Called after the user saves local ASL file (inlcuding autosave) from VSCode editor or Workflow Studio",

packages/core/src/stepFunctions/activation.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ function initializeCodeLens(context: vscode.ExtensionContext) {
144144
public async provideCodeLenses(document: vscode.TextDocument): Promise<vscode.CodeLens[]> {
145145
const topOfDocument = new vscode.Range(0, 0, 0, 0)
146146

147+
const openCustomEditorCommand: vscode.Command = {
148+
command: 'aws.stepfunctions.switchToWorkflowStudio',
149+
title: localize('AWS.command.stepFunctions.openWithWorkflowStudio', 'Open with Workflow Studio'),
150+
arguments: [document.uri],
151+
}
152+
const openCustomEditor = new vscode.CodeLens(topOfDocument, openCustomEditorCommand)
153+
147154
const renderCodeLens = previewStateMachineCommand.build().asCodeLens(topOfDocument, {
148155
title: localize('AWS.stepFunctions.render', 'Render graph'),
149156
})
@@ -155,9 +162,9 @@ function initializeCodeLens(context: vscode.ExtensionContext) {
155162
}
156163
const publishCodeLens = new vscode.CodeLens(topOfDocument, publishCommand)
157164

158-
return [publishCodeLens, renderCodeLens]
165+
return [openCustomEditor, publishCodeLens, renderCodeLens]
159166
} else {
160-
return [renderCodeLens]
167+
return [openCustomEditor, renderCodeLens]
161168
}
162169
}
163170
}

packages/core/src/stepFunctions/workflowStudio/activation.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,20 @@ import { WorkflowStudioEditorProvider } from './workflowStudioEditorProvider'
1212
*/
1313
export async function activate(extensionContext: vscode.ExtensionContext): Promise<void> {
1414
extensionContext.subscriptions.push(WorkflowStudioEditorProvider.register(extensionContext))
15+
16+
// Open the file with Workflow Studio editor in a new tab, or focus on the tab with WFS if it is already open
17+
extensionContext.subscriptions.push(
18+
vscode.commands.registerCommand('aws.stepfunctions.openWithWorkflowStudio', async (uri: vscode.Uri) => {
19+
await vscode.commands.executeCommand('vscode.openWith', uri, WorkflowStudioEditorProvider.viewType)
20+
})
21+
)
22+
23+
// Close the active editor and open the file with Workflow Studio (or close and switch to the existing relevant tab).
24+
// This command is expected to always be called from the active tab in the default editor mode
25+
extensionContext.subscriptions.push(
26+
vscode.commands.registerCommand('aws.stepfunctions.switchToWorkflowStudio', async (uri: vscode.Uri) => {
27+
await vscode.commands.executeCommand('workbench.action.closeActiveEditor')
28+
await vscode.commands.executeCommand('vscode.openWith', uri, WorkflowStudioEditorProvider.viewType)
29+
})
30+
)
1531
}

packages/core/src/stepFunctions/workflowStudio/handleMessage.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export async function handleMessage(message: Message, context: WebviewContext) {
4141
case Command.AUTO_SAVE_FILE:
4242
void autoSaveFileMessageHandler(message as SaveFileRequestMessage, context)
4343
break
44+
case Command.CLOSE_WFS:
45+
void closeCustomEditorMessageHandler(context)
46+
break
4447
case Command.OPEN_FEEDBACK:
4548
void submitFeedback(placeholder, 'Workflow Studio')
4649
break
@@ -107,6 +110,20 @@ async function loadStageMessageHandler(context: WebviewContext) {
107110
}, 100)
108111
}
109112

113+
/**
114+
* Handler for closing WFS custom editor. When called, disposes webview panel and opens default VSCode editor
115+
* @param context The context object containing the necessary information for the webview.
116+
*/
117+
export function closeCustomEditorMessageHandler(context: WebviewContext) {
118+
telemetry.stepfunctions_closeWorkflowStudio.run((span) => {
119+
span.record({
120+
id: context.fileId,
121+
})
122+
context.panel.dispose()
123+
void vscode.commands.executeCommand('vscode.openWith', context.textDocument.uri, 'default')
124+
})
125+
}
126+
110127
/**
111128
* Handler for saving a file from the webview which updates the workspace and saves the file.
112129
* Triggered when the user explicitly applies save action in WFS

packages/core/src/stepFunctions/workflowStudio/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export enum Command {
3838
FILE_CHANGED = 'FILE_CHANGED',
3939
LOAD_STAGE = 'LOAD_STAGE',
4040
OPEN_FEEDBACK = 'OPEN_FEEDBACK',
41+
CLOSE_WFS = 'CLOSE_WFS',
4142
}
4243

4344
export type FileWatchInfo = {

packages/core/src/stepFunctions/workflowStudio/workflowStudioEditor.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import * as path from 'path'
77
import * as vscode from 'vscode'
88
import { telemetry } from '../../shared/telemetry/telemetry'
9-
import { getLogger } from '../../shared/logger'
109
import { i18n } from '../../shared/i18n-helper'
1110
import { broadcastFileChange } from './handleMessage'
1211
import { FileWatchInfo, WebviewContext } from './types'
@@ -113,7 +112,6 @@ export class WorkflowStudioEditor {
113112
async (progress, token) => {
114113
token.onCancellationRequested(async () => {
115114
// Cancel opening in Worflow Studio and open regular code editor instead
116-
getLogger().debug('WorkflowStudio: Canceled opening')
117115
contextObject.panel.dispose()
118116
await vscode.commands.executeCommand('vscode.openWith', documentUri, 'default')
119117
throw new CancellationError('user')

0 commit comments

Comments
 (0)