|
3 | 3 | import * as vscode from 'vscode';
|
4 | 4 | import * as path from 'path';
|
5 | 5 | import { Commands } from './commands';
|
| 6 | +import { extensions } from 'vscode'; |
6 | 7 |
|
7 |
| -let existingExtensions: Array<string>; |
8 |
| -export let buildFilePatterns: Array<string>; |
| 8 | +export let existingExtensions: Array<string> = []; |
| 9 | +export let buildFilePatterns: Array<string> = []; |
9 | 10 |
|
10 | 11 | export function collectJavaExtensions(extensions: readonly vscode.Extension<any>[]): string[] {
|
11 | 12 | const result = [];
|
@@ -44,17 +45,40 @@ export function collectBuildFilePattern(extensions: readonly vscode.Extension<an
|
44 | 45 | return result;
|
45 | 46 | }
|
46 | 47 |
|
47 |
| -export function onExtensionChange(extensions: readonly vscode.Extension<any>[]) { |
48 |
| - if (isContributedPartUpdated(existingExtensions, collectJavaExtensions(extensions)) || isContributedPartUpdated(buildFilePatterns, collectBuildFilePattern(extensions))) { |
49 |
| - const msg = `Java Extension Contributions changed, reloading ${vscode.env.appName} is required for the changes to take effect.`; |
50 |
| - const action = 'Reload'; |
51 |
| - const restartId = Commands.RELOAD_WINDOW; |
52 |
| - vscode.window.showWarningMessage(msg, action).then((selection) => { |
53 |
| - if (action === selection) { |
54 |
| - vscode.commands.executeCommand(restartId); |
55 |
| - } |
56 |
| - }); |
| 48 | +export function getBundlesToReload(): string[] { |
| 49 | + const previousContributions: string[] = [...existingExtensions]; |
| 50 | + const currentContributions = collectJavaExtensions(extensions.all); |
| 51 | + if (isContributedPartUpdated(previousContributions, currentContributions)) { |
| 52 | + return currentContributions; |
| 53 | + } |
| 54 | + |
| 55 | + return []; |
| 56 | +} |
| 57 | + |
| 58 | +export async function onExtensionChange(extensions: readonly vscode.Extension<any>[]): Promise<void> { |
| 59 | + if (isContributedPartUpdated(buildFilePatterns, collectBuildFilePattern(extensions))) { |
| 60 | + return promptToReload(); |
57 | 61 | }
|
| 62 | + |
| 63 | + const bundlesToRefresh: string[] = getBundlesToReload(); |
| 64 | + if (bundlesToRefresh.length) { |
| 65 | + const success = await vscode.commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.REFRESH_BUNDLES, bundlesToRefresh); |
| 66 | + if (!success) { |
| 67 | + // if hot refreshing bundle fails, fallback to reload window. |
| 68 | + return promptToReload(); |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +function promptToReload() { |
| 74 | + const msg = `Java Extension Contributions changed, reloading ${vscode.env.appName} is required for the changes to take effect.`; |
| 75 | + const action = 'Reload'; |
| 76 | + const restartId = Commands.RELOAD_WINDOW; |
| 77 | + vscode.window.showWarningMessage(msg, action).then((selection) => { |
| 78 | + if (action === selection) { |
| 79 | + vscode.commands.executeCommand(restartId); |
| 80 | + } |
| 81 | + }); |
58 | 82 | }
|
59 | 83 |
|
60 | 84 | export function isContributedPartUpdated(oldContributedPart: Array<string>, newContributedPart: Array<string>) {
|
|
0 commit comments