Skip to content

Commit 6572351

Browse files
authored
Update language-client to 8.1.0 (#2377)
Signed-off-by: Shi Chen <chenshi@microsoft.com>
1 parent 6fd9f60 commit 6572351

11 files changed

+547
-516
lines changed

package-lock.json

Lines changed: 44 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@
13971397
"@types/glob": "5.0.30",
13981398
"@types/lodash.findindex": "^4.6.6",
13991399
"@types/mocha": "^5.2.5",
1400-
"@types/node": "^8.10.51",
1400+
"@types/node": "^16.11.7",
14011401
"@types/semver": "^7.3.8",
14021402
"@types/sinon": "^10.0.12",
14031403
"@types/vscode": "^1.74.0",
@@ -1418,7 +1418,7 @@
14181418
"request": "^2.88.2",
14191419
"sinon": "^14.0.0",
14201420
"ts-loader": "^9.2.6",
1421-
"typescript": "^4.2.4",
1421+
"typescript": "^4.6.4",
14221422
"webpack": "^5.28.0",
14231423
"webpack-cli": "^4.6.0"
14241424
},
@@ -1431,7 +1431,7 @@
14311431
"htmlparser2": "6.0.1",
14321432
"jdk-utils": "^0.4.4",
14331433
"semver": "^7.3.5",
1434-
"vscode-languageclient": "7.1.0-next.5",
1434+
"vscode-languageclient": "8.1.0",
14351435
"winreg-utf8": "^0.1.1",
14361436
"winston": "^3.2.1",
14371437
"winston-daily-rotate-file": "^3.10.0"

src/clientErrorHandler.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { window, commands } from "vscode";
2-
import { ErrorHandler, Message, ErrorAction, CloseAction } from "vscode-languageclient";
2+
import { ErrorHandler, Message, ErrorAction, CloseAction, ErrorHandlerResult, CloseHandlerResult } from "vscode-languageclient";
33
import { Commands } from "./commands";
44
import { logger } from "./log";
55

@@ -10,21 +10,27 @@ export class ClientErrorHandler implements ErrorHandler {
1010
this.restarts = [];
1111
}
1212

13-
public error(_error: Error, _message: Message, count: number): ErrorAction {
13+
public error(_error: Error, _message: Message, count: number): ErrorHandlerResult {
1414
if (count && count <= 3) {
1515
logger.error(`${this.name} server encountered error: ${_message}, ${_error && _error.toString()}`);
16-
return ErrorAction.Continue;
16+
return {
17+
action: ErrorAction.Continue
18+
};
1719
}
1820

1921
logger.error(`${this.name} server encountered error and will shut down: ${_message}, ${_error && _error.toString()}`);
20-
return ErrorAction.Shutdown;
22+
return {
23+
action: ErrorAction.Shutdown
24+
};
2125
}
2226

23-
public closed(): CloseAction {
27+
public closed(): CloseHandlerResult {
2428
this.restarts.push(Date.now());
2529
if (this.restarts.length < 5) {
2630
logger.error(`The ${this.name} server crashed and will restart.`);
27-
return CloseAction.Restart;
31+
return {
32+
action: CloseAction.Restart
33+
};
2834
} else {
2935
const diff = this.restarts[this.restarts.length - 1] - this.restarts[0];
3036
if (diff <= 3 * 60 * 1000) {
@@ -36,12 +42,16 @@ export class ClientErrorHandler implements ErrorHandler {
3642
commands.executeCommand(Commands.OPEN_LOGS);
3743
}
3844
});
39-
return CloseAction.DoNotRestart;
45+
return {
46+
action: CloseAction.DoNotRestart
47+
};
4048
}
4149

4250
logger.error(`The ${this.name} server crashed and will restart.`);
4351
this.restarts.shift();
44-
return CloseAction.Restart;
52+
return {
53+
action: CloseAction.Restart
54+
};
4555
}
4656
}
4757
}

src/extension.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as fse from 'fs-extra';
66
import * as os from 'os';
77
import * as path from 'path';
88
import { CodeActionContext, CodeActionTriggerKind, commands, ConfigurationTarget, Diagnostic, env, EventEmitter, ExtensionContext, extensions, IndentAction, InputBoxOptions, languages, RelativePattern, TextDocument, UIKind, Uri, ViewColumn, window, workspace, WorkspaceConfiguration } from 'vscode';
9-
import { CancellationToken, CodeActionParams, CodeActionRequest, Command, DidChangeConfigurationNotification, ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn } from 'vscode-languageclient';
9+
import { CancellationToken, CodeActionParams, CodeActionRequest, Command, DidChangeConfigurationNotification, ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn, State } from 'vscode-languageclient';
1010
import { LanguageClient } from 'vscode-languageclient/node';
1111
import { apiManager } from './apiManager';
1212
import { ClientErrorHandler } from './clientErrorHandler';
@@ -167,16 +167,15 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
167167
resolveAdditionalTextEditsSupport: true,
168168
advancedIntroduceParameterRefactoringSupport: true,
169169
actionableRuntimeNotificationSupport: true,
170-
shouldLanguageServerExitOnShutdown: true,
171170
onCompletionItemSelectedCommand: "editor.action.triggerParameterHints",
172171
extractInterfaceSupport: true,
173172
},
174173
triggerFiles,
175174
},
176175
middleware: {
177176
workspace: {
178-
didChangeConfiguration: () => {
179-
standardClient.getClient().sendNotification(DidChangeConfigurationNotification.type, {
177+
didChangeConfiguration: async () => {
178+
await standardClient.getClient().sendNotification(DidChangeConfigurationNotification.type, {
180179
settings: {
181180
java: getJavaConfig(requirements.java_home),
182181
}
@@ -185,12 +184,12 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
185184
},
186185
// https://github.com/redhat-developer/vscode-java/issues/2130
187186
// include all diagnostics for the current line in the CodeActionContext params for the performance reason
188-
provideCodeActions: (document, range, context, token, next) => {
187+
provideCodeActions: async (document, range, context, token, next) => {
189188
const client: LanguageClient = standardClient.getClient();
190189
const params: CodeActionParams = {
191190
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),
192191
range: client.code2ProtocolConverter.asRange(range),
193-
context: client.code2ProtocolConverter.asCodeActionContext(context)
192+
context: await client.code2ProtocolConverter.asCodeActionContext(context)
194193
};
195194
const showAt = getJavaConfiguration().get<string>("quickfix.showAt");
196195
if (showAt === 'line' && range.start.line === range.end.line && range.start.character === range.end.character) {
@@ -209,12 +208,12 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
209208
const codeActionContext: CodeActionContext = {
210209
diagnostics: allDiagnostics,
211210
only: context.only,
212-
triggerKind: CodeActionTriggerKind.Invoke,
211+
triggerKind: context.triggerKind,
213212
};
214-
params.context = client.code2ProtocolConverter.asCodeActionContext(codeActionContext);
213+
params.context = await client.code2ProtocolConverter.asCodeActionContext(codeActionContext);
215214
}
216215
}
217-
return client.sendRequest(CodeActionRequest.type, params, token).then((values) => {
216+
return client.sendRequest(CodeActionRequest.type, params, token).then(async (values) => {
218217
if (values === null) {
219218
return undefined;
220219
}
@@ -224,7 +223,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
224223
result.push(client.protocol2CodeConverter.asCommand(item));
225224
}
226225
else {
227-
result.push(client.protocol2CodeConverter.asCodeAction(item));
226+
result.push(await client.protocol2CodeConverter.asCodeAction(item));
228227
}
229228
}
230229
return result;
@@ -249,13 +248,16 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
249248
// no need to pass `resolve` into any code past this point,
250249
// since `resolve` is a no-op from now on
251250

251+
const serverOptions = prepareExecutable(requirements, syntaxServerWorkspacePath, getJavaConfig(requirements.java_home), context, true);
252252
if (requireSyntaxServer) {
253253
if (process.env['SYNTAXLS_CLIENT_PORT']) {
254254
syntaxClient.initialize(requirements, clientOptions);
255255
} else {
256-
syntaxClient.initialize(requirements, clientOptions, prepareExecutable(requirements, syntaxServerWorkspacePath, getJavaConfig(requirements.java_home), context, true));
256+
syntaxClient.initialize(requirements, clientOptions, serverOptions);
257257
}
258-
syntaxClient.start();
258+
syntaxClient.start().then(() => {
259+
syntaxClient.registerSyntaxClientActions(serverOptions);
260+
});
259261
serverStatusBarProvider.showLightWeightStatus();
260262
}
261263

@@ -430,7 +432,9 @@ async function startStandardServer(context: ExtensionContext, requirements: requ
430432
apiManager.fireDidServerModeChange(ServerMode.hybrid);
431433
}
432434
await standardClient.initialize(context, requirements, clientOptions, workspacePath, jdtEventEmitter);
433-
standardClient.start();
435+
standardClient.start().then(async () => {
436+
standardClient.registerLanguageClientActions(context, await fse.pathExists(path.join(workspacePath, ".metadata", ".plugins")), jdtEventEmitter);
437+
});
434438
serverStatusBarProvider.showStandardStatus();
435439
}
436440

@@ -532,7 +536,9 @@ export async function getActiveLanguageClient(): Promise<LanguageClient | undefi
532536
return undefined;
533537
}
534538

535-
await languageClient.onReady();
539+
if (languageClient.needsStart()) {
540+
await languageClient.start();
541+
}
536542

537543
return languageClient;
538544
}

src/fileEventHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function getWillRenameHandler(client: LanguageClient) {
165165
const edit = await client.sendRequest(WillRenameFiles.type, {
166166
files: javaRenameEvents
167167
});
168-
resolve(client.protocol2CodeConverter.asWorkspaceEdit(edit));
168+
resolve(await client.protocol2CodeConverter.asWorkspaceEdit(edit));
169169
} catch (ex) {
170170
reject(ex);
171171
}

src/pasteEventHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class PasteEditProvider implements DocumentPasteEditProvider {
9494
if (pasteResponse) {
9595
return {
9696
insertText: pasteResponse.insertText,
97-
additionalEdit: pasteResponse.additionalEdit ? this.languageClient.protocol2CodeConverter.asWorkspaceEdit(pasteResponse.additionalEdit) : undefined
97+
additionalEdit: pasteResponse.additionalEdit ? await this.languageClient.protocol2CodeConverter.asWorkspaceEdit(pasteResponse.additionalEdit) : undefined
9898
} as VDocumentPasteEdit;
9999
}
100100
} catch (e) {

src/refactorAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ async function applyRefactorEdit(languageClient: LanguageClient, refactorEdit: R
226226
}
227227

228228
if (refactorEdit.edit) {
229-
const edit = languageClient.protocol2CodeConverter.asWorkspaceEdit(refactorEdit.edit);
229+
const edit = await languageClient.protocol2CodeConverter.asWorkspaceEdit(refactorEdit.edit);
230230
if (edit) {
231231
await workspace.applyEdit(edit);
232232
}

src/sourceAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ function registerGenerateDelegateMethodsCommand(languageClient: LanguageClient,
385385
}
386386

387387
async function revealWorkspaceEdit(workspaceEdit: WorkspaceEdit, languageClient: LanguageClient): Promise<void> {
388-
const codeWorkspaceEdit = languageClient.protocol2CodeConverter.asWorkspaceEdit(workspaceEdit);
388+
const codeWorkspaceEdit = await languageClient.protocol2CodeConverter.asWorkspaceEdit(workspaceEdit);
389389
if (!codeWorkspaceEdit) {
390390
return;
391391
}

0 commit comments

Comments
 (0)