|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +declare module 'vscode' { |
| 7 | + |
| 8 | + // https://github.com/microsoft/vscode/issues/109277 |
| 9 | + |
| 10 | + /** |
| 11 | + * Details if an `ExternalUriOpener` can open a uri. |
| 12 | + * |
| 13 | + * The priority is also used to rank multiple openers against each other and determine |
| 14 | + * if an opener should be selected automatically or if the user should be prompted to |
| 15 | + * select an opener. |
| 16 | + * |
| 17 | + * The editor will try to use the best available opener, as sorted by `ExternalUriOpenerPriority`. |
| 18 | + * If there are multiple potential "best" openers for a URI, then the user will be prompted |
| 19 | + * to select an opener. |
| 20 | + */ |
| 21 | + export enum ExternalUriOpenerPriority { |
| 22 | + /** |
| 23 | + * The opener is disabled and will never be shown to users. |
| 24 | + * |
| 25 | + * Note that the opener can still be used if the user specifically |
| 26 | + * configures it in their settings. |
| 27 | + */ |
| 28 | + None = 0, |
| 29 | + |
| 30 | + /** |
| 31 | + * The opener can open the uri but will not cause a prompt on its own |
| 32 | + * since the editor always contributes a built-in `Default` opener. |
| 33 | + */ |
| 34 | + Option = 1, |
| 35 | + |
| 36 | + /** |
| 37 | + * The opener can open the uri. |
| 38 | + * |
| 39 | + * The editor's built-in opener has `Default` priority. This means that any additional `Default` |
| 40 | + * openers will cause the user to be prompted to select from a list of all potential openers. |
| 41 | + */ |
| 42 | + Default = 2, |
| 43 | + |
| 44 | + /** |
| 45 | + * The opener can open the uri and should be automatically selected over any |
| 46 | + * default openers, include the built-in one from the editor. |
| 47 | + * |
| 48 | + * A preferred opener will be automatically selected if no other preferred openers |
| 49 | + * are available. If multiple preferred openers are available, then the user |
| 50 | + * is shown a prompt with all potential openers (not just preferred openers). |
| 51 | + */ |
| 52 | + Preferred = 3, |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Handles opening uris to external resources, such as http(s) links. |
| 57 | + * |
| 58 | + * Extensions can implement an `ExternalUriOpener` to open `http` links to a webserver |
| 59 | + * inside of the editor instead of having the link be opened by the web browser. |
| 60 | + * |
| 61 | + * Currently openers may only be registered for `http` and `https` uris. |
| 62 | + */ |
| 63 | + export interface ExternalUriOpener { |
| 64 | + |
| 65 | + /** |
| 66 | + * Check if the opener can open a uri. |
| 67 | + * |
| 68 | + * @param uri The uri being opened. This is the uri that the user clicked on. It has |
| 69 | + * not yet gone through port forwarding. |
| 70 | + * @param token Cancellation token indicating that the result is no longer needed. |
| 71 | + * |
| 72 | + * @return Priority indicating if the opener can open the external uri. |
| 73 | + */ |
| 74 | + canOpenExternalUri(uri: Uri, token: CancellationToken): ExternalUriOpenerPriority | Thenable<ExternalUriOpenerPriority>; |
| 75 | + |
| 76 | + /** |
| 77 | + * Open a uri. |
| 78 | + * |
| 79 | + * This is invoked when: |
| 80 | + * |
| 81 | + * - The user clicks a link which does not have an assigned opener. In this case, first `canOpenExternalUri` |
| 82 | + * is called and if the user selects this opener, then `openExternalUri` is called. |
| 83 | + * - The user sets the default opener for a link in their settings and then visits a link. |
| 84 | + * |
| 85 | + * @param resolvedUri The uri to open. This uri may have been transformed by port forwarding, so it |
| 86 | + * may not match the original uri passed to `canOpenExternalUri`. Use `ctx.originalUri` to check the |
| 87 | + * original uri. |
| 88 | + * @param ctx Additional information about the uri being opened. |
| 89 | + * @param token Cancellation token indicating that opening has been canceled. |
| 90 | + * |
| 91 | + * @return Thenable indicating that the opening has completed. |
| 92 | + */ |
| 93 | + openExternalUri(resolvedUri: Uri, ctx: OpenExternalUriContext, token: CancellationToken): Thenable<void> | void; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Additional information about the uri being opened. |
| 98 | + */ |
| 99 | + export interface OpenExternalUriContext { |
| 100 | + /** |
| 101 | + * The uri that triggered the open. |
| 102 | + * |
| 103 | + * This is the original uri that the user clicked on or that was passed to `openExternal.` |
| 104 | + * Due to port forwarding, this may not match the `resolvedUri` passed to `openExternalUri`. |
| 105 | + */ |
| 106 | + readonly sourceUri: Uri; |
| 107 | + } |
| 108 | + |
| 109 | + /** |
| 110 | + * Additional metadata about a registered `ExternalUriOpener`. |
| 111 | + */ |
| 112 | + export interface ExternalUriOpenerMetadata { |
| 113 | + |
| 114 | + /** |
| 115 | + * List of uri schemes the opener is triggered for. |
| 116 | + * |
| 117 | + * Currently only `http` and `https` are supported. |
| 118 | + */ |
| 119 | + readonly schemes: readonly string[]; |
| 120 | + |
| 121 | + /** |
| 122 | + * Text displayed to the user that explains what the opener does. |
| 123 | + * |
| 124 | + * For example, 'Open in browser preview' |
| 125 | + */ |
| 126 | + readonly label: string; |
| 127 | + } |
| 128 | + |
| 129 | + namespace window { |
| 130 | + /** |
| 131 | + * Register a new `ExternalUriOpener`. |
| 132 | + * |
| 133 | + * When a uri is about to be opened, an `onOpenExternalUri:SCHEME` activation event is fired. |
| 134 | + * |
| 135 | + * @param id Unique id of the opener, such as `myExtension.browserPreview`. This is used in settings |
| 136 | + * and commands to identify the opener. |
| 137 | + * @param opener Opener to register. |
| 138 | + * @param metadata Additional information about the opener. |
| 139 | + * |
| 140 | + * @returns Disposable that unregisters the opener. |
| 141 | + */ |
| 142 | + export function registerExternalUriOpener(id: string, opener: ExternalUriOpener, metadata: ExternalUriOpenerMetadata): Disposable; |
| 143 | + } |
| 144 | + |
| 145 | + export interface OpenExternalOptions { |
| 146 | + /** |
| 147 | + * Allows using openers contributed by extensions through `registerExternalUriOpener` |
| 148 | + * when opening the resource. |
| 149 | + * |
| 150 | + * If `true`, the editor will check if any contributed openers can handle the |
| 151 | + * uri, and fallback to the default opener behavior. |
| 152 | + * |
| 153 | + * If it is string, this specifies the id of the `ExternalUriOpener` |
| 154 | + * that should be used if it is available. Use `'default'` to force the editor's |
| 155 | + * standard external opener to be used. |
| 156 | + */ |
| 157 | + readonly allowContributedOpeners?: boolean | string; |
| 158 | + } |
| 159 | + |
| 160 | + namespace env { |
| 161 | + export function openExternal(target: Uri, options?: OpenExternalOptions): Thenable<boolean>; |
| 162 | + } |
| 163 | +} |
0 commit comments