| 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 {LazyExoticComponent} from 'react'; |
| b69ab31 | | | 9 | import type {Comparison} from 'shared/Comparison'; |
| b69ab31 | | | 10 | import type {Json} from 'shared/typeUtils'; |
| b69ab31 | | | 11 | import type {MessageBus} from './MessageBus'; |
| b69ab31 | | | 12 | import type {ThemeColor} from './theme'; |
| b69ab31 | | | 13 | import type { |
| b69ab31 | | | 14 | AbsolutePath, |
| b69ab31 | | | 15 | Disposable, |
| b69ab31 | | | 16 | OneIndexedLineNumber, |
| b69ab31 | | | 17 | PlatformName, |
| b69ab31 | | | 18 | RepoRelativePath, |
| b69ab31 | | | 19 | ServerToClientMessage, |
| b69ab31 | | | 20 | } from './types'; |
| b69ab31 | | | 21 | |
| b69ab31 | | | 22 | import {browserPlatform} from './BrowserPlatform'; |
| b69ab31 | | | 23 | import type {CodeReviewIssue} from './firstPassCodeReview/types'; |
| b69ab31 | | | 24 | |
| b69ab31 | | | 25 | export type InitialParamKeys = 'token' | string; |
| b69ab31 | | | 26 | |
| b69ab31 | | | 27 | /** |
| b69ab31 | | | 28 | * Platform-specific API for each target: vscode extension, electron standalone, browser, ... |
| b69ab31 | | | 29 | */ |
| b69ab31 | | | 30 | export interface Platform { |
| b69ab31 | | | 31 | platformName: PlatformName; |
| b69ab31 | | | 32 | confirm(message: string, details?: string): Promise<boolean>; |
| b69ab31 | | | 33 | openFile(path: RepoRelativePath, options?: {line?: OneIndexedLineNumber}): void; |
| b69ab31 | | | 34 | openFiles(paths: ReadonlyArray<RepoRelativePath>, options?: {line?: OneIndexedLineNumber}): void; |
| b69ab31 | | | 35 | canCustomizeFileOpener: boolean; |
| b69ab31 | | | 36 | openContainingFolder?(path: RepoRelativePath): void; |
| b69ab31 | | | 37 | openDiff?(path: RepoRelativePath, comparison: Comparison): void; |
| b69ab31 | | | 38 | openExternalLink(url: string): void; |
| b69ab31 | | | 39 | clipboardCopy(text: string, html?: string): void; |
| b69ab31 | | | 40 | chooseFile?(title: string, multi: boolean): Promise<Array<File>>; |
| b69ab31 | | | 41 | /** Whether to ask to configure an external merge tool. Useful for standalone platforms, but not embedded ones like vscode. */ |
| b69ab31 | | | 42 | upsellExternalMergeTool: boolean; |
| b69ab31 | | | 43 | /** |
| b69ab31 | | | 44 | * Get stored data from local persistent cache (usually browser local storage). |
| b69ab31 | | | 45 | * Note: Some platforms may not support this (e.g. browser with localStorage disabled), |
| b69ab31 | | | 46 | * or it may not be persisted indefinitely---usual localStorage caveats apply. |
| b69ab31 | | | 47 | */ |
| b69ab31 | | | 48 | getPersistedState<T extends Json>(key: string): T | null; |
| b69ab31 | | | 49 | /** see getPersistedState */ |
| b69ab31 | | | 50 | setPersistedState<T extends Json>(key: string, value: T | undefined): void; |
| b69ab31 | | | 51 | /** see getPersistedState */ |
| b69ab31 | | | 52 | clearPersistedState(): void; |
| b69ab31 | | | 53 | /** see getPersistedState */ |
| b69ab31 | | | 54 | getAllPersistedState(): Json | undefined; |
| b69ab31 | | | 55 | |
| b69ab31 | | | 56 | handleServerMessage?: (message: ServerToClientMessage) => void; |
| b69ab31 | | | 57 | |
| b69ab31 | | | 58 | openDedicatedComparison?: (comparison: Comparison) => Promise<boolean>; |
| b69ab31 | | | 59 | |
| b69ab31 | | | 60 | /** |
| b69ab31 | | | 61 | * Component representing additional buttons/info in the cwd menu, |
| b69ab31 | | | 62 | * used to show a button or hint about how to add more cwds. |
| b69ab31 | | | 63 | * Note: This should be lazy-loaded via `React.lazy()` so that implementations |
| b69ab31 | | | 64 | * may import any files without worrying about the platform being set up yet or not. |
| b69ab31 | | | 65 | */ |
| b69ab31 | | | 66 | AddMoreCwdsHint?: LazyExoticComponent<() => JSX.Element>; |
| b69ab31 | | | 67 | |
| b69ab31 | | | 68 | /** Platform-specific settings, such as how ISL panels work */ |
| b69ab31 | | | 69 | Settings?: LazyExoticComponent<() => JSX.Element>; |
| b69ab31 | | | 70 | |
| b69ab31 | | | 71 | theme?: { |
| b69ab31 | | | 72 | getTheme(): ThemeColor; |
| b69ab31 | | | 73 | getThemeName?(): string | undefined; |
| b69ab31 | | | 74 | onDidChangeTheme(callback: (theme: ThemeColor) => unknown): Disposable; |
| b69ab31 | | | 75 | resetCSS?: string; |
| b69ab31 | | | 76 | }; |
| b69ab31 | | | 77 | |
| b69ab31 | | | 78 | /** If the platform has a notion of pending edits (typically from an AI), methods for listening and resolving them. */ |
| b69ab31 | | | 79 | suggestedEdits?: { |
| b69ab31 | | | 80 | /** listen for changes to edits so ISL can confirm edits before taking actions. */ |
| b69ab31 | | | 81 | onDidChangeSuggestedEdits(callback: (suggestedEdits: Array<AbsolutePath>) => void): Disposable; |
| b69ab31 | | | 82 | /** Accepts/Rejects edits */ |
| b69ab31 | | | 83 | resolveSuggestedEdits(action: 'accept' | 'reject', files?: Array<AbsolutePath>): void; |
| b69ab31 | | | 84 | }; |
| b69ab31 | | | 85 | |
| b69ab31 | | | 86 | messageBus: MessageBus; |
| b69ab31 | | | 87 | /** In browser-like platforms, some ISL parameters are passed via URL query params */ |
| b69ab31 | | | 88 | initialUrlParams?: Map<InitialParamKeys, string>; |
| b69ab31 | | | 89 | |
| b69ab31 | | | 90 | /** If the platform has a notion of AI code review, methods for listening to them. */ |
| b69ab31 | | | 91 | aiCodeReview?: { |
| b69ab31 | | | 92 | /** listen for new comments so ISL can render them */ |
| b69ab31 | | | 93 | onDidChangeAIReviewComments( |
| b69ab31 | | | 94 | callback: (aiReviewComments: Array<CodeReviewIssue>) => void, |
| b69ab31 | | | 95 | ): Disposable; |
| b69ab31 | | | 96 | }; |
| b69ab31 | | | 97 | } |
| b69ab31 | | | 98 | |
| b69ab31 | | | 99 | declare global { |
| b69ab31 | | | 100 | interface Window { |
| b69ab31 | | | 101 | islPlatform?: Platform; |
| b69ab31 | | | 102 | } |
| b69ab31 | | | 103 | } |
| b69ab31 | | | 104 | |
| b69ab31 | | | 105 | // [!] NOTE: On some platforms (vscode), this file is replaced at bundle time with a platform-specific implementation |
| b69ab31 | | | 106 | // of the Platform interface. |
| b69ab31 | | | 107 | // This file should have no other side effects than exporting the platform. |
| b69ab31 | | | 108 | |
| b69ab31 | | | 109 | // However, non-vscode but non-browser platforms are defined by setting window.islPlatform |
| b69ab31 | | | 110 | // before the main ISL script loads. |
| b69ab31 | | | 111 | |
| b69ab31 | | | 112 | /** The ISL client Platform. This may be BrowserPlatform, VSCodeWebviewPlatform, or another platforms, determined at runtime. */ |
| b69ab31 | | | 113 | const platform = window.islPlatform ?? browserPlatform; |
| b69ab31 | | | 114 | window.islPlatform = platform; |
| b69ab31 | | | 115 | |
| b69ab31 | | | 116 | export default platform; |