Repository: marp-team/marp-vscode (ts)

Issue:
VS Code v1.58 does not open Workspace Trust from a notification of export command
### Version of Marp Tool

Marp for VS Code v1.1.0

### Operating System

macOS

### Environment

- OS version: macOS Big Sur 11.4
- VS Code version: VS Code 1.58.0


### How to reproduce

1. Open Marp Markdown in restricted mode
2. Choose `markdown.marp.export` from the command palette.
3. Click "Manage Worksapce Trust..." in a notification.

![](https://user-images.githubusercontent.com/3993388/124985679-a5a85500-e075-11eb-88f0-94ed7c124002.png)



### Expected behavior

Open "Workspace Trust" panel.

### Actual behavior

Nothing.

### Additional information

### Output in developer console

```
workbench.desktop.main.js:sourcemap:62 [Extension Host] rejected promise not handled within 1 second: Error: command 'workbench.action.manageTrust' not found (at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:30190)
m @ workbench.desktop.main.js:sourcemap:62
workbench.desktop.main.js:sourcemap:62 [Extension Host] stack trace: Error: command 'workbench.action.manageTrust' not found    at g._tryExecuteCommand (vscode-file://vscode-app/Applications/Visual%20Studio%20Code%20-%20Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1678:3360)    at vscode-file://vscode-app/Applications/Visual%20Studio%20Code%20-%20Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1678:3241    at processTicksAndRejections (internal/process/task_queues.js:93:5) (at /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:103:30269)
m @ workbench.desktop.main.js:sourcemap:62
workbench.desktop.main.js:sourcemap:627   ERR command 'workbench.action.manageTrust' not found: Error: command 'workbench.action.manageTrust' not found
    at g._tryExecuteCommand (vscode-file://vscode-app/Applications/Visual%20Studio%20Code%20-%20Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1678:3360)
    at vscode-file://vscode-app/Applications/Visual%20Studio%20Code%20-%20Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1678:3241
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
```

Pull request:
Update the command for opening Workspace Trust
Fix #259.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ec5c485..bb52b1c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
 
 ## [Unreleased]
 
+### Fixed
+
+- VS Code 1.58 does not open Workspace Trust from a notification of export command ([#259](https://github.com/marp-team/marp-vscode/issues/259), [#260](https://github.com/marp-team/marp-vscode/pull/260))
+
 ## v1.1.0 - 2021-07-08
 
 ### Added
diff --git a/src/__mocks__/vscode.ts b/src/__mocks__/vscode.ts
index 46643a9..67e1140 100644
--- a/src/__mocks__/vscode.ts
+++ b/src/__mocks__/vscode.ts
@@ -116,7 +116,9 @@ export const Uri = {
 }
 
 export const commands = {
-  executeCommand: jest.fn(),
+  executeCommand: jest.fn(async () => {
+    // no ops
+  }),
   registerCommand: jest.fn(),
 }
 
diff --git a/src/commands/export.ts b/src/commands/export.ts
index 0326848..881c140 100644
--- a/src/commands/export.ts
+++ b/src/commands/export.ts
@@ -158,7 +158,18 @@ export default async function exportCommand() {
     )
 
     if (acted === ITEM_MANAGE_WORKSPACE_TRUST) {
-      commands.executeCommand('workbench.action.manageTrust')
+      commands.executeCommand('workbench.trust.manage').then(
+        () => {
+          // do nothing
+        },
+        (e) => {
+          console.error(e)
+
+          // Try alternative way (for VS Code 1.57)
+          // TODO: Remove executing alternative command if the extension requires VS Code 1.58+
+          commands.executeCommand('workbench.action.manageTrust')
+        }
+      )
     }
 
     return


Test patch:
diff --git a/src/commands/export.test.ts b/src/commands/export.test.ts
index 40d8f34..4353f93 100644
--- a/src/commands/export.test.ts
+++ b/src/commands/export.test.ts
@@ -50,16 +50,32 @@ describe('Export command', () => {
       expect(window.showErrorMessage).toHaveBeenCalled()
     })
 
-    it('executes "workbench.action.manageTrust" command when reacted on the prompt', async () => {
-      const { showErrorMessage }: any = window
-      showErrorMessage.mockResolvedValue(
-        exportModule.ITEM_MANAGE_WORKSPACE_TRUST
-      )
+    describe('when reacted with "Manage Workspace Trust..."', () => {
+      beforeEach(() => {
+        ;(window.showErrorMessage as any).mockResolvedValue(
+          exportModule.ITEM_MANAGE_WORKSPACE_TRUST
+        )
+      })
 
-      await exportCommand()
-      expect(commands.executeCommand).toHaveBeenCalledWith(
-        'workbench.action.manageTrust'
-      )
+      it('executes "workbench.trust.manage" command when reacted on the prompt', async () => {
+        await exportCommand()
+        expect(commands.executeCommand).toHaveBeenCalledWith(
+          'workbench.trust.manage'
+        )
+      })
+
+      it('fallbacks to "workbench.action.manageTrust" command for VS Code 1.57 if throwed error', async () => {
+        const error = jest.spyOn(console, 'error').mockImplementation()
+        const err = new Error('!')
+
+        ;(commands.executeCommand as any).mockRejectedValueOnce(err)
+
+        await exportCommand()
+        expect(error).toHaveBeenCalledWith(err)
+        expect(commands.executeCommand).toHaveBeenCalledWith(
+          'workbench.action.manageTrust'
+        )
+      })
     })
   })