| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import type {Comparison} from '../../../shared/Comparison'; |
| b69ab31 | | | 9 | import type {Platform} from '../platform'; |
| b69ab31 | | | 10 | import type {OneIndexedLineNumber, RepoRelativePath} from '../types'; |
| b69ab31 | | | 11 | |
| b69ab31 | | | 12 | import {makeBrowserLikePlatformImpl} from './browserPlatformImpl'; |
| b69ab31 | | | 13 | |
| b69ab31 | | | 14 | declare global { |
| b69ab31 | | | 15 | interface Window { |
| b69ab31 | | | 16 | __vsIdeBridge: { |
| b69ab31 | | | 17 | openFileInVisualStudio: (path: string, line?: number, col?: number) => void; |
| b69ab31 | | | 18 | openDiffInVisualStudio: (path: string, comparison: Comparison) => void; |
| b69ab31 | | | 19 | }; |
| b69ab31 | | | 20 | } |
| b69ab31 | | | 21 | } |
| b69ab31 | | | 22 | |
| b69ab31 | | | 23 | const visualStudioPlatform: Platform = { |
| b69ab31 | | | 24 | ...makeBrowserLikePlatformImpl('visualStudio'), |
| b69ab31 | | | 25 | |
| b69ab31 | | | 26 | confirm: (message: string, details?: string) => { |
| b69ab31 | | | 27 | const ok = window.confirm(message + '\n' + (details ?? '')); |
| b69ab31 | | | 28 | return Promise.resolve(ok); |
| b69ab31 | | | 29 | }, |
| b69ab31 | | | 30 | |
| b69ab31 | | | 31 | openFile: async (path: RepoRelativePath, options?: {line?: OneIndexedLineNumber}) => { |
| b69ab31 | | | 32 | if (window.__vsIdeBridge && window.__vsIdeBridge.openFileInVisualStudio) { |
| b69ab31 | | | 33 | const helpers = await import('./platformHelpers'); |
| b69ab31 | | | 34 | const repoRoot = helpers.getRepoRoot(); |
| b69ab31 | | | 35 | if (repoRoot) { |
| b69ab31 | | | 36 | const fullPath = `${repoRoot}/${path}`; |
| b69ab31 | | | 37 | window.__vsIdeBridge.openFileInVisualStudio(fullPath, options?.line); |
| b69ab31 | | | 38 | } |
| b69ab31 | | | 39 | } |
| b69ab31 | | | 40 | }, |
| b69ab31 | | | 41 | openFiles: async (paths: Array<RepoRelativePath>, _options?: {line?: OneIndexedLineNumber}) => { |
| b69ab31 | | | 42 | if (window.__vsIdeBridge && window.__vsIdeBridge.openFileInVisualStudio) { |
| b69ab31 | | | 43 | const helpers = await import('./platformHelpers'); |
| b69ab31 | | | 44 | const repoRoot = helpers.getRepoRoot(); |
| b69ab31 | | | 45 | if (repoRoot) { |
| b69ab31 | | | 46 | for (const path of paths) { |
| b69ab31 | | | 47 | const fullPath = `${repoRoot}/${path}`; |
| b69ab31 | | | 48 | window.__vsIdeBridge.openFileInVisualStudio(fullPath, _options?.line); |
| b69ab31 | | | 49 | } |
| b69ab31 | | | 50 | } |
| b69ab31 | | | 51 | } |
| b69ab31 | | | 52 | }, |
| b69ab31 | | | 53 | openDiff: async (path: RepoRelativePath, comparison: Comparison) => { |
| b69ab31 | | | 54 | if (window.__vsIdeBridge && window.__vsIdeBridge.openDiffInVisualStudio) { |
| b69ab31 | | | 55 | const helpers = await import('./platformHelpers'); |
| b69ab31 | | | 56 | const repoRoot = helpers.getRepoRoot(); |
| b69ab31 | | | 57 | if (repoRoot) { |
| b69ab31 | | | 58 | const fullPath = `${repoRoot}/${path}`; |
| b69ab31 | | | 59 | window.__vsIdeBridge.openDiffInVisualStudio(fullPath, comparison); |
| b69ab31 | | | 60 | } |
| b69ab31 | | | 61 | } |
| b69ab31 | | | 62 | }, |
| b69ab31 | | | 63 | canCustomizeFileOpener: false, |
| b69ab31 | | | 64 | upsellExternalMergeTool: false, |
| b69ab31 | | | 65 | |
| b69ab31 | | | 66 | openExternalLink(_url: string): void { |
| b69ab31 | | | 67 | window.open(_url, '_blank'); |
| b69ab31 | | | 68 | }, |
| b69ab31 | | | 69 | }; |
| b69ab31 | | | 70 | |
| b69ab31 | | | 71 | window.islPlatform = visualStudioPlatform; |
| b69ab31 | | | 72 | |
| b69ab31 | | | 73 | // Load the actual app entry, which must be done after the platform has been set up. |
| b69ab31 | | | 74 | import('../index'); |