Skip to content

Commit 52a0e58

Browse files
author
Vlad Nikolaenko
committed
fix(stepfunctions): Bug fixes - handling unsupported messages, fix undo sync bug, code cleanup
1 parent 4e674d6 commit 52a0e58

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
FileChangeEventTrigger,
1515
SyncFileRequestMessage,
1616
ApiCallRequestMessage,
17+
UnsupportedMessage,
1718
} from './types'
1819
import { submitFeedback } from '../../feedback/vue/submitFeedback'
1920
import { placeholder } from '../../shared/vscode/commands2'
@@ -56,13 +57,21 @@ export async function handleMessage(message: Message, context: WebviewContext) {
5657
case Command.API_CALL:
5758
apiCallMessageHandler(message as ApiCallRequestMessage, context)
5859
break
60+
default:
61+
void handleUnsupportedMessage(context, message)
62+
break
5963
}
6064
} else if (messageType === MessageType.BROADCAST) {
6165
switch (command) {
6266
case Command.LOAD_STAGE:
6367
void loadStageMessageHandler(context)
6468
break
69+
default:
70+
void handleUnsupportedMessage(context, message)
71+
break
6572
}
73+
} else {
74+
void handleUnsupportedMessage(context, message)
6675
}
6776
}
6877

@@ -206,3 +215,18 @@ function apiCallMessageHandler(request: ApiCallRequestMessage, context: WebviewC
206215
const apiHandler = new WorkflowStudioApiHandler(globals.awsContext.getCredentialDefaultRegion(), context)
207216
apiHandler.performApiCall(request).catch((error) => logger.error('%s API call failed: %O', request.apiName, error))
208217
}
218+
219+
/**
220+
* Handles unsupported or unrecognized messages by sending a response to the webview. Ensures compatibility with future
221+
* commands and message types, preventing issues if the user has an outdated extension version.
222+
* @param context The context object containing information about the webview environment
223+
* @param command The command received from the webview
224+
* @param messageType The type of the message received
225+
*/
226+
async function handleUnsupportedMessage(context: WebviewContext, originalMessage: Message) {
227+
await context.panel.webview.postMessage({
228+
messageType: MessageType.RESPONSE,
229+
command: Command.UNSUPPORTED_COMMAND,
230+
originalMessage,
231+
} as UnsupportedMessage)
232+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export enum Command {
4141
OPEN_FEEDBACK = 'OPEN_FEEDBACK',
4242
CLOSE_WFS = 'CLOSE_WFS',
4343
API_CALL = 'API_CALL',
44+
UNSUPPORTED_COMMAND = 'UNSUPPORTED_COMMAND',
4445
}
4546

4647
export type FileWatchInfo = {
@@ -61,6 +62,10 @@ export interface FileChangedMessage extends Message {
6162
trigger: FileChangeEventTrigger
6263
}
6364

65+
export interface UnsupportedMessage extends Message {
66+
originalMessage: Message
67+
}
68+
6469
export interface InitResponseMessage extends Omit<FileChangedMessage, 'trigger'> {
6570
isSuccess: boolean
6671
failureReason?: string

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
import * as vscode from 'vscode'
77
import { getLogger } from '../../shared/logger/logger'
88
import request from '../../shared/request'
9-
import fs from '../../shared/fs/fs'
109
import { getClientId } from '../../shared/telemetry/util'
1110
import { telemetry } from '../../shared/telemetry/telemetry'
1211
import globals from '../../shared/extensionGlobals'
13-
import { getRandomString, getStringHash } from '../../shared/utilities/textUtilities'
12+
import { getStringHash } from '../../shared/utilities/textUtilities'
1413
import { ToolkitError } from '../../shared/errors'
1514
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
1615
import { WorkflowStudioEditor } from './workflowStudioEditor'
@@ -80,7 +79,7 @@ export class WorkflowStudioEditorProvider implements vscode.CustomTextEditorProv
8079
* @private
8180
*/
8281
private getWebviewContent = async () => {
83-
let htmlFileSplit = this.webviewHtml.split('<head>')
82+
const htmlFileSplit = this.webviewHtml.split('<head>')
8483

8584
// Set asset source to CDN
8685
const source = isLocalDev ? localhost : cdn
@@ -93,20 +92,8 @@ export class WorkflowStudioEditorProvider implements vscode.CustomTextEditorProv
9392
const isDarkMode = theme === vscode.ColorThemeKind.Dark || theme === vscode.ColorThemeKind.HighContrast
9493
const tabSizeTag = `<meta name='tab-size' content='${getTabSizeSetting()}'>`
9594
const darkModeTag = `<meta name='dark-mode' content='${isDarkMode}'>`
96-
let html = `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${htmlFileSplit[1]}`
9795

98-
const nonce = getRandomString()
99-
const localDevURL = isLocalDev ? localhost : ''
100-
htmlFileSplit = html.split("script-src 'self'")
101-
102-
html = `${htmlFileSplit[0]} script-src 'self' 'nonce-${nonce}' ${localDevURL} ${htmlFileSplit[1]}`
103-
htmlFileSplit = html.split('<body>')
104-
105-
const script = await fs.readFileText(
106-
vscode.Uri.joinPath(globals.context.extensionUri, 'resources', 'js', 'vsCodeExtensionInterface.js')
107-
)
108-
109-
return `${htmlFileSplit[0]} <body> <script nonce='${nonce}'>${script}</script> ${htmlFileSplit[1]}`
96+
return `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${htmlFileSplit[1]}`
11097
}
11198

11299
/**

packages/toolkit/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4151,6 +4151,12 @@
41514151
"mac": "cmd+shift+v",
41524152
"when": "editorTextFocus && editorLangId == asl || editorTextFocus && editorLangId == asl-yaml"
41534153
},
4154+
{
4155+
"command": "noop",
4156+
"key": "ctrl+z",
4157+
"mac": "cmd+z",
4158+
"when": "aws.stepFunctions.isWorkflowStudioFocused"
4159+
},
41544160
{
41554161
"command": "aws.samcli.sync",
41564162
"key": "ctrl+shift+s",

0 commit comments

Comments
 (0)