addons/isl/src/platform/visualStudioPlatform.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {Comparison} from '../../../shared/Comparison';
b69ab319import type {Platform} from '../platform';
b69ab3110import type {OneIndexedLineNumber, RepoRelativePath} from '../types';
b69ab3111
b69ab3112import {makeBrowserLikePlatformImpl} from './browserPlatformImpl';
b69ab3113
b69ab3114declare global {
b69ab3115 interface Window {
b69ab3116 __vsIdeBridge: {
b69ab3117 openFileInVisualStudio: (path: string, line?: number, col?: number) => void;
b69ab3118 openDiffInVisualStudio: (path: string, comparison: Comparison) => void;
b69ab3119 };
b69ab3120 }
b69ab3121}
b69ab3122
b69ab3123const visualStudioPlatform: Platform = {
b69ab3124 ...makeBrowserLikePlatformImpl('visualStudio'),
b69ab3125
b69ab3126 confirm: (message: string, details?: string) => {
b69ab3127 const ok = window.confirm(message + '\n' + (details ?? ''));
b69ab3128 return Promise.resolve(ok);
b69ab3129 },
b69ab3130
b69ab3131 openFile: async (path: RepoRelativePath, options?: {line?: OneIndexedLineNumber}) => {
b69ab3132 if (window.__vsIdeBridge && window.__vsIdeBridge.openFileInVisualStudio) {
b69ab3133 const helpers = await import('./platformHelpers');
b69ab3134 const repoRoot = helpers.getRepoRoot();
b69ab3135 if (repoRoot) {
b69ab3136 const fullPath = `${repoRoot}/${path}`;
b69ab3137 window.__vsIdeBridge.openFileInVisualStudio(fullPath, options?.line);
b69ab3138 }
b69ab3139 }
b69ab3140 },
b69ab3141 openFiles: async (paths: Array<RepoRelativePath>, _options?: {line?: OneIndexedLineNumber}) => {
b69ab3142 if (window.__vsIdeBridge && window.__vsIdeBridge.openFileInVisualStudio) {
b69ab3143 const helpers = await import('./platformHelpers');
b69ab3144 const repoRoot = helpers.getRepoRoot();
b69ab3145 if (repoRoot) {
b69ab3146 for (const path of paths) {
b69ab3147 const fullPath = `${repoRoot}/${path}`;
b69ab3148 window.__vsIdeBridge.openFileInVisualStudio(fullPath, _options?.line);
b69ab3149 }
b69ab3150 }
b69ab3151 }
b69ab3152 },
b69ab3153 openDiff: async (path: RepoRelativePath, comparison: Comparison) => {
b69ab3154 if (window.__vsIdeBridge && window.__vsIdeBridge.openDiffInVisualStudio) {
b69ab3155 const helpers = await import('./platformHelpers');
b69ab3156 const repoRoot = helpers.getRepoRoot();
b69ab3157 if (repoRoot) {
b69ab3158 const fullPath = `${repoRoot}/${path}`;
b69ab3159 window.__vsIdeBridge.openDiffInVisualStudio(fullPath, comparison);
b69ab3160 }
b69ab3161 }
b69ab3162 },
b69ab3163 canCustomizeFileOpener: false,
b69ab3164 upsellExternalMergeTool: false,
b69ab3165
b69ab3166 openExternalLink(_url: string): void {
b69ab3167 window.open(_url, '_blank');
b69ab3168 },
b69ab3169};
b69ab3170
b69ab3171window.islPlatform = visualStudioPlatform;
b69ab3172
b69ab3173// Load the actual app entry, which must be done after the platform has been set up.
b69ab3174import('../index');