Skip to content

Commit d8aee7b

Browse files
witness-meVlad Nikolaenko
andauthored
fix(stepfunctions): Bug fixes - handling unsupported messages, fix undo sync bug, code cleanup (aws#6667)
## Problem 1. In case we introduce new feature dependant on the Toolkit change in the future, users may face issues if they don't update their toolkit right away (as their toolkit version won't have the new functionality in place) 2. There was a regression from my [previous PR](aws@9c40f4c), in `package.json` - most possibly due to incorrect merge conflict resolution (since the original file has been moved to another folder). The regression is that undo command override is not working, causing uncorrect undo command behaviour when triggered from webview 3. There is some redundant code which is not useful and causes incorrect behaviour, showing in the webview view screen ## Solution 1. To ensure compatibility, we are adding an unsupported message handler in advance. In case of unsupported message it will send an appropriate response back to the webview, so we will be able to use it to handle the error gracefully on the webview side 2. Adding back the undo command override (only when WFS editor is active). More context on why it's needed on [previous PR](aws#6024), which was approved and merged previously. Verified that the command only applies to WFS editor and with this undo behaviour is fixed 3. Removing redundant code (verified the integration still works fine) --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license. Co-authored-by: Vlad Nikolaenko <[email protected]>
1 parent c8292a3 commit d8aee7b

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)