Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,15 @@ export namespace Commands {
* The VS Code command to create module-info.java
*/
export const CREATE_MODULE_INFO_COMMAND = "java.project.createModuleInfo.command";

/**
* The JDT.LS command to reload the bundle list (java extension contributions).
*/
export const REFRESH_BUNDLES = "java.reloadBundles";

/**
* The VS Code command to reload the bundle list.
* JDT.LS will call this command before set the server to ready state.
*/
export const REFRESH_BUNDLES_COMMAND = "_java.reloadBundles.command";
}
6 changes: 5 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as fse from 'fs-extra';
import { workspace, extensions, ExtensionContext, window, commands, ViewColumn, Uri, languages, IndentAction, InputBoxOptions, EventEmitter, OutputChannel, TextDocument, RelativePattern, ConfigurationTarget, WorkspaceConfiguration, env, UIKind, CodeActionContext, Diagnostic, CodeActionTriggerKind, version } from 'vscode';
import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn, ErrorHandler, Message, ErrorAction, CloseAction, DidChangeConfigurationNotification, CancellationToken, CodeActionRequest, CodeActionParams, Command } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';
import { collectJavaExtensions, isContributedPartUpdated } from './plugin';
import { collectJavaExtensions, getBundlesToReload, isContributedPartUpdated } from './plugin';
import { HEAP_DUMP_LOCATION, prepareExecutable } from './javaServerStarter';
import * as requirements from './requirements';
import { initialize as initializeRecommendation } from './recommendation';
Expand Down Expand Up @@ -383,6 +383,10 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {

context.subscriptions.push(commands.registerCommand(Commands.GET_WORKSPACE_PATH, () => workspacePath));

context.subscriptions.push(commands.registerCommand(Commands.REFRESH_BUNDLES_COMMAND, () => {
return getBundlesToReload();
}));

context.subscriptions.push(onConfigurationChange(workspacePath, context));

/**
Expand Down
48 changes: 36 additions & 12 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { Commands } from './commands';
import { extensions } from 'vscode';

let existingExtensions: Array<string>;
export let buildFilePatterns: Array<string>;
export let existingExtensions: Array<string> = [];
export let buildFilePatterns: Array<string> = [];

export function collectJavaExtensions(extensions: readonly vscode.Extension<any>[]): string[] {
const result = [];
Expand Down Expand Up @@ -44,17 +45,40 @@ export function collectBuildFilePattern(extensions: readonly vscode.Extension<an
return result;
}

export function onExtensionChange(extensions: readonly vscode.Extension<any>[]) {
if (isContributedPartUpdated(existingExtensions, collectJavaExtensions(extensions)) || isContributedPartUpdated(buildFilePatterns, collectBuildFilePattern(extensions))) {
const msg = `Java Extension Contributions changed, reloading ${vscode.env.appName} 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);
}
});
export function getBundlesToReload(): string[] {
const previousContributions: string[] = [...existingExtensions];
const currentContributions = collectJavaExtensions(extensions.all);
if (isContributedPartUpdated(previousContributions, currentContributions)) {
return currentContributions;
}

return [];
}

export async function onExtensionChange(extensions: readonly vscode.Extension<any>[]): Promise<void> {
if (isContributedPartUpdated(buildFilePatterns, collectBuildFilePattern(extensions))) {
return promptToReload();
}

const bundlesToRefresh: string[] = getBundlesToReload();
if (bundlesToRefresh.length) {
const success = await vscode.commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.REFRESH_BUNDLES, bundlesToRefresh);
if (!success) {
// if hot refreshing bundle fails, fallback to reload window.
return promptToReload();
}
}
}

function promptToReload() {
const msg = `Java Extension Contributions changed, reloading ${vscode.env.appName} 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);
}
});
}

export function isContributedPartUpdated(oldContributedPart: Array<string>, newContributedPart: Array<string>) {
Expand Down
12 changes: 7 additions & 5 deletions src/standardLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ export class StandardLanguageClient {
apiManager.updateServerMode(ServerMode.standard);
apiManager.fireDidServerModeChange(ServerMode.standard);
apiManager.resolveServerReadyPromise();

if (extensions.onDidChange) {// Theia doesn't support this API yet
extensions.onDidChange(async () => {
await onExtensionChange(extensions.all);
});
}

activationProgressNotification.hide();
if (!hasImported) {
showImportFinishNotification(context);
Expand Down Expand Up @@ -539,11 +546,6 @@ export class StandardLanguageClient {
refactorAction.registerCommands(this.languageClient, context);
pasteAction.registerCommands(this.languageClient, context);

if (extensions.onDidChange) {// Theia doesn't support this API yet
extensions.onDidChange(() => {
onExtensionChange(extensions.all);
});
}
excludeProjectSettingsFiles();

context.subscriptions.push(languages.registerCodeActionsProvider({ scheme: 'file', language: 'java' }, new RefactorDocumentProvider(), RefactorDocumentProvider.metadata));
Expand Down