Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"AWS.stepFunctions.workflowStudio.actions.progressMessage": "Opening asl file in Workflow Studio",
"AWS.stepFunctions.workflowStudio.actions.saveSuccessMessage": "{0} has been saved",
"AWS.stepFunctions.workflowStudio.actions.invalidJson": "The Workflow Studio editor was not opened because the JSON in the file is invalid. To access Workflow Studio, please fix the JSON and manually reopen the integration.",
"AWS.stepFunctions.workflowStudio.enable.desc": "Open Amazon States Language files in Workflow Studio by default.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use workbench.editorAssociations. We already do something similar for threat composer:

"configurationDefaults": {
"workbench.editorAssociations": {
"{git,gitlens,conflictResolution,vscode-local-history}:/**/*.tc.json": "default"
}

Do not add new, custom ways of setting file associations.

"AWS.configuration.description.awssam.debug.api": "API Gateway configuration",
"AWS.configuration.description.awssam.debug.api.clientCertId": "The API Gateway client certificate ID",
"AWS.configuration.description.awssam.debug.api.headers": "Additional HTTP headers",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/shared/settings-toolkit.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const toolkitSettings = {
"aws.samcli.legacyDeploy": {},
"aws.telemetry": {},
"aws.stepfunctions.asl.format.enable": {},
"aws.stepfunctions.workflowStudio.enable": {},
"aws.stepfunctions.asl.maxItemsComputed": {},
"aws.ssmDocument.ssm.maxItemsComputed": {},
"aws.cwl.limit": {},
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/stepFunctions/workflowStudio/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export async function activate(): Promise<void> {
// Open the file with Workflow Studio editor in a new tab, or focus on the tab with WFS if it is already open
globals.context.subscriptions.push(
Commands.register('aws.stepfunctions.openWithWorkflowStudio', async (uri: vscode.Uri) => {
await vscode.commands.executeCommand('vscode.openWith', uri, WorkflowStudioEditorProvider.viewType)
await vscode.commands.executeCommand(
'vscode.openWith',
uri.with({ query: 'manual=true' }),
WorkflowStudioEditorProvider.viewType
)
})
)

Expand All @@ -26,7 +30,11 @@ export async function activate(): Promise<void> {
globals.context.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)
await vscode.commands.executeCommand(
'vscode.openWith',
uri.with({ query: 'manual=true' }),
WorkflowStudioEditorProvider.viewType
)
})
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { telemetry } from '../../shared/telemetry/telemetry'
import globals from '../../shared/extensionGlobals'
import { getRandomString, getStringHash } from '../../shared/utilities/textUtilities'
import { ToolkitError } from '../../shared/errors'
import { getTabSizeSetting } from '../../shared/utilities/editorUtilities'
import { WorkflowStudioEditor } from './workflowStudioEditor'
import { i18n } from '../../shared/i18n-helper'
import { isInvalidJsonFile } from '../utils'
Expand Down Expand Up @@ -86,8 +87,9 @@ export class WorkflowStudioEditorProvider implements vscode.CustomTextEditorProv
const localeTag = `<meta name='locale' content='${locale}'>`
const theme = vscode.window.activeColorTheme.kind
const isDarkMode = theme === vscode.ColorThemeKind.Dark || theme === vscode.ColorThemeKind.HighContrast
const tabSizeTag = `<meta name='tab-size' content='${getTabSizeSetting()}'>`
const darkModeTag = `<meta name='dark-mode' content='${isDarkMode}'>`
let html = `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${htmlFileSplit[1]}`
let html = `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${htmlFileSplit[1]}`

const nonce = getRandomString()
htmlFileSplit = html.split("script-src 'self'")
Expand Down Expand Up @@ -115,6 +117,21 @@ export class WorkflowStudioEditorProvider implements vscode.CustomTextEditorProv
_token: vscode.CancellationToken
): Promise<void> {
await telemetry.stepfunctions_openWorkflowStudio.run(async () => {
// If the user opted out from Workflow Studio and this is not a manual open, launch default editor instead
const autoOpenWFS = vscode.workspace.getConfiguration().get('aws.stepfunctions.workflowStudio.enable', true)
const isManualAction = new URLSearchParams(document.uri.query).get('manual') === 'true'
if (!autoOpenWFS && !isManualAction) {
await vscode.commands.executeCommand('vscode.openWith', document.uri, 'default')
webviewPanel.dispose()
throw ToolkitError.chain(
'User opted out',
'The Workflow Studio editor was not opened because the user has opted out',
{
code: 'userOptOut',
}
)
}

// For invalid JSON, open default editor and show warning message
if (isInvalidJsonFile(document)) {
await vscode.commands.executeCommand('vscode.openWith', document.uri, 'default')
Expand Down
20 changes: 20 additions & 0 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
"default": true,
"description": "%AWS.stepFunctions.asl.format.enable.desc%"
},
"aws.stepfunctions.workflowStudio.enable": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this setting being added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is explained in point 1:

The feature opens specific file types in a custom editor by default and customers don't have a way to optout while still using toolkit

Our team (including the UX) decided that since custom editor is opened by default, we want to provide a way for the user to opt out of it

"type": "boolean",
"default": true,
"description": "%AWS.stepFunctions.workflowStudio.enable.desc%"
},
"aws.stepfunctions.asl.maxItemsComputed": {
"type": "number",
"default": 5000,
Expand Down Expand Up @@ -1412,6 +1417,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": [
Expand Down Expand Up @@ -3838,6 +3848,16 @@
}
}
},
{
"command": "aws.stepfunctions.openWithWorkflowStudio",
"title": "%AWS.command.stepFunctions.openWithWorkflowStudio%",
"category": "%AWS.title%",
"cloud9": {
"cn": {
"category": "%AWS.title.cn%"
}
}
},
{
"command": "aws.createNewThreatComposer",
"title": "%AWS.command.threatComposer.createNew%",
Expand Down
Loading