Skip to content

Commit bd03b35

Browse files
Alexander ChenrgrunberJessicaJHee
committed
Added restart Java language server command.
- Show progress for restarting the language server Signed-off-by: AlexXuChen <[email protected]> Co-authored-by: Roland Grunberg <[email protected]> Co-authored-by: Jessica He <[email protected]>
1 parent 210ea42 commit bd03b35

File tree

10 files changed

+47
-6
lines changed

10 files changed

+47
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ The following commands are available:
108108
- `Java: List All Java Source Paths`: lists all the Java source paths recognized by the Java Language Server workspace.
109109
- `Java: Show Build Job Status`: shows the Java Language Server job status in Visual Studio Code terminal.
110110
- `Java: Go to Super Implementation`: goes to the super implementation for the current selected symbol in editor.
111+
- `Java: Restart Java Language Server`: restarts the Java language server.
111112

112113
Supported VS Code settings
113114
==========================

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,11 @@
12501250
"command": "java.clean.sharedIndexes",
12511251
"title": "%java.clean.sharedIndexes%",
12521252
"category": "Java"
1253+
},
1254+
{
1255+
"command": "java.server.restart",
1256+
"title": "%java.server.restart%",
1257+
"category": "Java"
12531258
}
12541259
],
12551260
"keybindings": [
@@ -1381,6 +1386,10 @@
13811386
{
13821387
"command": "java.server.mode.switch",
13831388
"when": "java:serverMode == LightWeight"
1389+
},
1390+
{
1391+
"command": "java.server.restart",
1392+
"when": "javaLSReady"
13841393
}
13851394
],
13861395
"view/title": [

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"java.action.showSubtypeHierarchy": "Show Subtype Hierarchy",
2424
"java.action.changeBaseType": "Base on this Type",
2525
"java.project.createModuleInfo.command": "Create module-info.java",
26-
"java.clean.sharedIndexes": "Clean Shared Indexes"
26+
"java.clean.sharedIndexes": "Clean Shared Indexes",
27+
"java.server.restart": "Restart Java Language Server"
2728
}

src/commands.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ export namespace Commands {
274274
* Command to switch between standard mode and lightweight mode.
275275
*/
276276
export const SWITCH_SERVER_MODE = 'java.server.mode.switch';
277+
/**
278+
* Command to restart the language server.
279+
*/
280+
export const RESTART_LANGUAGE_SERVER = 'java.server.restart';
277281

278282
export const LEARN_MORE_ABOUT_REFACTORING = '_java.learnMoreAboutRefactorings';
279283

src/extension.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as fs from 'fs';
55
import * as fse from 'fs-extra';
66
import * as os from 'os';
77
import * as path from 'path';
8-
import { CodeActionContext, commands, ConfigurationTarget, Diagnostic, env, EventEmitter, ExtensionContext, extensions, IndentAction, InputBoxOptions, languages, RelativePattern, TextDocument, UIKind, Uri, ViewColumn, window, workspace, WorkspaceConfiguration } from 'vscode';
8+
import { CodeActionContext, commands, ConfigurationTarget, Diagnostic, env, EventEmitter, ExtensionContext, extensions, IndentAction, InputBoxOptions, languages, RelativePattern, TextDocument, UIKind, Uri, ViewColumn, window, workspace, WorkspaceConfiguration, ProgressLocation } from 'vscode';
99
import { CancellationToken, CodeActionParams, CodeActionRequest, Command, DidChangeConfigurationNotification, ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn } from 'vscode-languageclient';
1010
import { LanguageClient } from 'vscode-languageclient/node';
1111
import { apiManager } from './apiManager';
@@ -329,6 +329,8 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
329329

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

332+
registerRestartJavaLanguageServerCommand(context);
333+
332334
/**
333335
* Command to switch the server mode. Currently it only supports switch from lightweight to standard.
334336
* @param force force to switch server mode without asking
@@ -965,3 +967,24 @@ function registerOutOfMemoryDetection(storagePath: string) {
965967
showOOMMessage();
966968
});
967969
}
970+
971+
function registerRestartJavaLanguageServerCommand(context: ExtensionContext) {
972+
context.subscriptions.push(commands.registerCommand(Commands.RESTART_LANGUAGE_SERVER, async () => {
973+
switch (getJavaServerMode()) {
974+
case (ServerMode.standard):
975+
// Standard server restart
976+
await standardClient.getClient().restart();
977+
break;
978+
case (ServerMode.lightWeight):
979+
// Syntax server restart
980+
await syntaxClient.getClient().restart();
981+
break;
982+
case (ServerMode.hybrid):
983+
if (syntaxClient.isAlive()) {
984+
await syntaxClient.getClient().restart();
985+
}
986+
await standardClient.getClient().restart();
987+
break;
988+
}
989+
}));
990+
}

src/javaServerStarter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { deleteDirectory, ensureExists, getJavaConfiguration, getTimestamp } fro
1414

1515
// eslint-disable-next-line no-var
1616
declare var v8debug;
17-
const DEBUG = (typeof v8debug === 'object') || startedInDebugMode();
17+
export const DEBUG = (typeof v8debug === 'object') || startedInDebugMode();
1818

1919
/**
2020
* Argument that tells the program where to generate the heap dump that is created when an OutOfMemoryError is raised and `HEAP_DUMP` has been passed

src/standardLanguageClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Commands } from "./commands";
1414
import { ClientStatus } from "./extension.api";
1515
import * as fileEventHandler from './fileEventHandler';
1616
import { gradleCodeActionMetadata, GradleCodeActionProvider } from "./gradle/gradleCodeActionProvider";
17-
import { awaitServerConnection, prepareExecutable } from "./javaServerStarter";
17+
import { awaitServerConnection, prepareExecutable, DEBUG } from "./javaServerStarter";
1818
import { logger } from "./log";
1919
import { checkLombokDependency } from "./lombokSupport";
2020
import { markdownPreviewProvider } from "./markdownPreviewProvider";
@@ -106,7 +106,7 @@ export class StandardLanguageClient {
106106
}
107107

108108
// Create the language client and start the client.
109-
this.languageClient = new TracingLanguageClient('java', extensionName, serverOptions, clientOptions);
109+
this.languageClient = new TracingLanguageClient('java', extensionName, serverOptions, clientOptions, DEBUG);
110110

111111
this.registerCommandsForStandardServer(context, jdtEventEmitter);
112112
fileEventHandler.registerFileEventHandlers(this.languageClient, context);

src/syntaxLanguageClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { RequirementsData } from "./requirements";
1313
import { ServerMode } from "./settings";
1414
import { snippetCompletionProvider } from "./snippetCompletionProvider";
1515
import { getJavaConfig } from "./utils";
16+
import { DEBUG } from "./javaServerStarter";
1617

1718
const extensionName = "Language Support for Java (Syntax Server)";
1819

@@ -55,7 +56,7 @@ export class SyntaxLanguageClient {
5556
}
5657

5758
if (serverOptions) {
58-
this.languageClient = new LanguageClient('java', extensionName, serverOptions, newClientOptions);
59+
this.languageClient = new LanguageClient('java', extensionName, serverOptions, newClientOptions, DEBUG);
5960
}
6061

6162
this.status = ClientStatus.initialized;

test/lightweight-mode-suite/extension.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ suite('Java Language Extension - LightWeight', () => {
2424
Commands.SWITCH_SERVER_MODE,
2525
Commands.OPEN_FILE,
2626
Commands.CLEAN_SHARED_INDEXES,
27+
Commands.RESTART_LANGUAGE_SERVER,
2728
].sort();
2829
const foundJavaCommands = commands.filter((value) => {
2930
return JAVA_COMMANDS.indexOf(value)>=0 || value.startsWith('java.');

test/standard-mode-suite/extension.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ suite('Java Language Extension - Standard', () => {
9696
Commands.RESOLVE_TYPE_HIERARCHY,
9797
Commands.RESOLVE_WORKSPACE_SYMBOL,
9898
Commands.RUNTIME_VALIDATION_OPEN,
99+
Commands.RESTART_LANGUAGE_SERVER,
99100
Commands.SHOW_JAVA_IMPLEMENTATIONS,
100101
Commands.SHOW_JAVA_REFERENCES,
101102
Commands.SHOW_SERVER_TASK_STATUS,

0 commit comments

Comments
 (0)