-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathplugin.ts
More file actions
55 lines (50 loc) · 1.68 KB
/
plugin.ts
File metadata and controls
55 lines (50 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
import * as vscode from 'vscode';
import * as path from 'path';
import { Commands } from './commands';
let existingExtensions: Array<string>;
export function collectJavaExtensions(extensions: vscode.Extension<any>[]): string[] {
const result = [];
if (extensions && extensions.length) {
for (const extension of extensions) {
const contributesSection = extension.packageJSON['contributes'];
if (contributesSection) {
const javaExtensions = contributesSection['javaExtensions'];
if (Array.isArray(javaExtensions) && javaExtensions.length) {
for (const javaExtensionPath of javaExtensions) {
result.push(path.resolve(extension.extensionPath, javaExtensionPath));
}
}
}
}
}
// Make a copy of extensions:
existingExtensions = result.slice();
return result;
}
export function onExtensionChange(extensions: vscode.Extension<any>[]) {
if (!existingExtensions) {
return;
}
const oldExtensions = new Set(existingExtensions.slice());
const newExtensions = collectJavaExtensions(extensions);
let hasChanged = ( oldExtensions.size !== newExtensions.length);
if (!hasChanged) {
for (const newExtension of newExtensions) {
if (!oldExtensions.has(newExtension)) {
hasChanged = true;
break;
}
}
}
if (hasChanged) {
const msg = 'Extensions to the Java Language Server changed, reloading Visual Studio Code is required for the changes to take effect.';
const action = 'Reload';
const restartId = Commands.RELOAD_WINDOW;
vscode.window.showWarningMessage(msg, action).then((selection) => {
if (action === selection) {
vscode.commands.executeCommand(restartId);
}
});
}
}