From 2283bbd31335a524f03f03de2763a3bf4f052c73 Mon Sep 17 00:00:00 2001 From: Timur Valiev Date: Tue, 26 May 2020 05:00:30 -0700 Subject: [PATCH] vscode integration helper Summary: VSCode integration helpers to call extensions Reviewed By: passy Differential Revision: D21641284 fbshipit-source-id: dd978520ea541dbd6a96b8398ce28744a0fc97ad --- desktop/app/src/fb-stubs/user.tsx | 4 ++++ desktop/app/src/index.tsx | 1 + desktop/app/src/utils/vscodeUtils.tsx | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 desktop/app/src/utils/vscodeUtils.tsx diff --git a/desktop/app/src/fb-stubs/user.tsx b/desktop/app/src/fb-stubs/user.tsx index 1e4da4f3a..cbf0e855b 100644 --- a/desktop/app/src/fb-stubs/user.tsx +++ b/desktop/app/src/fb-stubs/user.tsx @@ -79,3 +79,7 @@ export async function getFlipperMediaCDN( ): Promise { throw new Error('Feature not implemented'); } + +export async function getPreferredEditorUriScheme(): Promise { + return 'vscode'; +} diff --git a/desktop/app/src/index.tsx b/desktop/app/src/index.tsx index 0ffce3cf7..26c789d86 100644 --- a/desktop/app/src/index.tsx +++ b/desktop/app/src/index.tsx @@ -183,3 +183,4 @@ export {KeyboardActions} from './MenuBar'; export {getFlipperMediaCDN} from './fb-stubs/user'; export {Rect} from './utils/geometry'; export {Logger} from './fb-interfaces/Logger'; +export {callVSCode, getVSCodeUrl} from './utils/vscodeUtils'; diff --git a/desktop/app/src/utils/vscodeUtils.tsx b/desktop/app/src/utils/vscodeUtils.tsx new file mode 100644 index 000000000..d21b3bdef --- /dev/null +++ b/desktop/app/src/utils/vscodeUtils.tsx @@ -0,0 +1,27 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +import {getPreferredEditorUriScheme} from '../fb-stubs/user'; +import {shell} from 'electron'; + +const preferredEditorUriScheme: Promise = getPreferredEditorUriScheme(); + +export function callVSCode(plugin: string, command: string, params?: string) { + getVSCodeUrl(plugin, command, params).then((url) => shell.openExternal(url)); +} + +export async function getVSCodeUrl( + plugin: string, + command: string, + params?: string, +): Promise { + return `${await preferredEditorUriScheme}://${plugin}/${command}${ + params == null ? '' : `?${params}` + }`; +}