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