|
14 | 14 |
|
15 | 15 | import * as vscode from "vscode";
|
16 | 16 | import { Workbench } from "../utilities/commands";
|
| 17 | +// eslint-disable-next-line @typescript-eslint/no-require-imports |
| 18 | +import debounce = require("lodash.debounce"); |
17 | 19 |
|
18 | 20 | /**
|
19 | 21 | * Prompts the user to reload the extension in cases where we are unable to do
|
20 |
| - * so automatically. |
| 22 | + * so automatically. Only one of these prompts will be shown at a time. |
21 | 23 | *
|
22 | 24 | * @param message the warning message to display to the user
|
23 | 25 | * @param items extra buttons to display
|
24 | 26 | * @returns the selected button or undefined if cancelled
|
25 | 27 | */
|
26 |
| -export async function showReloadExtensionNotification<T extends string>( |
27 |
| - message: string, |
28 |
| - ...items: T[] |
29 |
| -): Promise<"Reload Extensions" | T | undefined> { |
30 |
| - const buttons: ("Reload Extensions" | T)[] = ["Reload Extensions", ...items]; |
31 |
| - const selected = await vscode.window.showWarningMessage(message, ...buttons); |
32 |
| - if (selected === "Reload Extensions") { |
33 |
| - await vscode.commands.executeCommand(Workbench.ACTION_RELOADWINDOW); |
34 |
| - } |
35 |
| - return selected; |
| 28 | +export function showReloadExtensionNotificationInstance<T extends string>() { |
| 29 | + let inFlight: Promise<"Reload Extensions" | T | undefined> | null = null; |
| 30 | + |
| 31 | + return async function ( |
| 32 | + message: string, |
| 33 | + ...items: T[] |
| 34 | + ): Promise<"Reload Extensions" | T | undefined> { |
| 35 | + if (inFlight) { |
| 36 | + return inFlight; |
| 37 | + } |
| 38 | + |
| 39 | + const buttons: ("Reload Extensions" | T)[] = ["Reload Extensions", ...items]; |
| 40 | + inFlight = (async () => { |
| 41 | + try { |
| 42 | + const selected = await vscode.window.showWarningMessage(message, ...buttons); |
| 43 | + if (selected === "Reload Extensions") { |
| 44 | + await vscode.commands.executeCommand(Workbench.ACTION_RELOADWINDOW); |
| 45 | + } |
| 46 | + return selected; |
| 47 | + } finally { |
| 48 | + inFlight = null; |
| 49 | + } |
| 50 | + })(); |
| 51 | + |
| 52 | + return inFlight; |
| 53 | + }; |
36 | 54 | }
|
| 55 | + |
| 56 | +// In case the user closes the dialog immediately we want to debounce showing it again |
| 57 | +// for 10 seconds to prevent another popup perhaps immediately appearing. |
| 58 | +export const showReloadExtensionNotification = debounce( |
| 59 | + showReloadExtensionNotificationInstance(), |
| 60 | + 10_000, |
| 61 | + { leading: true } |
| 62 | +); |
0 commit comments