Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update language-client to 8.1.0 #2377

Merged
merged 6 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
74 changes: 44 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@
"@types/glob": "5.0.30",
"@types/lodash.findindex": "^4.6.6",
"@types/mocha": "^5.2.5",
"@types/node": "^8.10.51",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since VS Code has switched to node 16 since 1.66 (https://code.visualstudio.com/updates/v1_66#_nodemoduleversion-and-nodejs-api-update), let's update this deps as well. The update will resolve the following error:

node_modules/vscode-jsonrpc/lib/node/main.d.ts(8,37): error TS2307: Cannot find module 'worker_threads' or its corresponding type declarations.

"@types/node": "^16.11.7",
"@types/semver": "^7.3.8",
"@types/sinon": "^10.0.12",
"@types/vscode": "^1.74.0",
Expand All @@ -1418,7 +1418,7 @@
"request": "^2.88.2",
"sinon": "^14.0.0",
"ts-loader": "^9.2.6",
"typescript": "^4.2.4",
"typescript": "^4.6.4",
"webpack": "^5.28.0",
"webpack-cli": "^4.6.0"
},
Expand All @@ -1431,7 +1431,7 @@
"htmlparser2": "6.0.1",
"jdk-utils": "^0.4.4",
"semver": "^7.3.5",
"vscode-languageclient": "7.1.0-next.5",
"vscode-languageclient": "8.1.0",
"winreg-utf8": "^0.1.1",
"winston": "^3.2.1",
"winston-daily-rotate-file": "^3.10.0"
Expand Down
26 changes: 18 additions & 8 deletions src/clientErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { window, commands } from "vscode";
import { ErrorHandler, Message, ErrorAction, CloseAction } from "vscode-languageclient";
import { ErrorHandler, Message, ErrorAction, CloseAction, ErrorHandlerResult, CloseHandlerResult } from "vscode-languageclient";
import { Commands } from "./commands";
import { logger } from "./log";

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

public error(_error: Error, _message: Message, count: number): ErrorAction {
public error(_error: Error, _message: Message, count: number): ErrorHandlerResult {
if (count && count <= 3) {
logger.error(`${this.name} server encountered error: ${_message}, ${_error && _error.toString()}`);
return ErrorAction.Continue;
return {
action: ErrorAction.Continue
};
}

logger.error(`${this.name} server encountered error and will shut down: ${_message}, ${_error && _error.toString()}`);
return ErrorAction.Shutdown;
return {
action: ErrorAction.Shutdown
};
}

public closed(): CloseAction {
public closed(): CloseHandlerResult {
this.restarts.push(Date.now());
if (this.restarts.length < 5) {
logger.error(`The ${this.name} server crashed and will restart.`);
return CloseAction.Restart;
return {
action: CloseAction.Restart
};
} else {
const diff = this.restarts[this.restarts.length - 1] - this.restarts[0];
if (diff <= 3 * 60 * 1000) {
Expand All @@ -36,12 +42,16 @@ export class ClientErrorHandler implements ErrorHandler {
commands.executeCommand(Commands.OPEN_LOGS);
}
});
return CloseAction.DoNotRestart;
return {
action: CloseAction.DoNotRestart
};
}

logger.error(`The ${this.name} server crashed and will restart.`);
this.restarts.shift();
return CloseAction.Restart;
return {
action: CloseAction.Restart
};
}
}
}
36 changes: 22 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fse from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import { CodeActionContext, CodeActionTriggerKind, commands, ConfigurationTarget, Diagnostic, env, EventEmitter, ExtensionContext, extensions, IndentAction, InputBoxOptions, languages, RelativePattern, TextDocument, UIKind, Uri, ViewColumn, window, workspace, WorkspaceConfiguration } from 'vscode';
import { CancellationToken, CodeActionParams, CodeActionRequest, Command, DidChangeConfigurationNotification, ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn } from 'vscode-languageclient';
import { CancellationToken, CodeActionParams, CodeActionRequest, Command, DidChangeConfigurationNotification, ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn, State } from 'vscode-languageclient';
import { LanguageClient } from 'vscode-languageclient/node';
import { apiManager } from './apiManager';
import { ClientErrorHandler } from './clientErrorHandler';
Expand Down Expand Up @@ -167,16 +167,17 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
resolveAdditionalTextEditsSupport: true,
advancedIntroduceParameterRefactoringSupport: true,
actionableRuntimeNotificationSupport: true,
shouldLanguageServerExitOnShutdown: true,
// https://github.com/redhat-developer/vscode-java/pull/2377#issuecomment-1427268344
shouldLanguageServerExitOnShutdown: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was fixed in the language client release that supported 3.17. Original issue is at #1928 (comment) . There's no need to set it to false as that's the default value anyways on the server side. In fact, there's a good argument for getting rid of it entirely since it was really to handle some non-protocol behaviour.

onCompletionItemSelectedCommand: "editor.action.triggerParameterHints",
extractInterfaceSupport: true,
},
triggerFiles,
},
middleware: {
workspace: {
didChangeConfiguration: () => {
standardClient.getClient().sendNotification(DidChangeConfigurationNotification.type, {
didChangeConfiguration: async () => {
await standardClient.getClient().sendNotification(DidChangeConfigurationNotification.type, {
settings: {
java: getJavaConfig(requirements.java_home),
}
Expand All @@ -185,12 +186,12 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
},
// https://github.com/redhat-developer/vscode-java/issues/2130
// include all diagnostics for the current line in the CodeActionContext params for the performance reason
provideCodeActions: (document, range, context, token, next) => {
provideCodeActions: async (document, range, context, token, next) => {
const client: LanguageClient = standardClient.getClient();
const params: CodeActionParams = {
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(document),
range: client.code2ProtocolConverter.asRange(range),
context: client.code2ProtocolConverter.asCodeActionContext(context)
context: await client.code2ProtocolConverter.asCodeActionContext(context)
};
const showAt = getJavaConfiguration().get<string>("quickfix.showAt");
if (showAt === 'line' && range.start.line === range.end.line && range.start.character === range.end.character) {
Expand All @@ -209,12 +210,12 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
const codeActionContext: CodeActionContext = {
diagnostics: allDiagnostics,
only: context.only,
triggerKind: CodeActionTriggerKind.Invoke,
triggerKind: context.triggerKind,
};
params.context = client.code2ProtocolConverter.asCodeActionContext(codeActionContext);
params.context = await client.code2ProtocolConverter.asCodeActionContext(codeActionContext);
}
}
return client.sendRequest(CodeActionRequest.type, params, token).then((values) => {
return client.sendRequest(CodeActionRequest.type, params, token).then(async (values) => {
if (values === null) {
return undefined;
}
Expand All @@ -224,7 +225,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
result.push(client.protocol2CodeConverter.asCommand(item));
}
else {
result.push(client.protocol2CodeConverter.asCodeAction(item));
result.push(await client.protocol2CodeConverter.asCodeAction(item));
}
}
return result;
Expand All @@ -249,13 +250,16 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
// no need to pass `resolve` into any code past this point,
// since `resolve` is a no-op from now on

const serverOptions = prepareExecutable(requirements, syntaxServerWorkspacePath, getJavaConfig(requirements.java_home), context, true);
if (requireSyntaxServer) {
if (process.env['SYNTAXLS_CLIENT_PORT']) {
syntaxClient.initialize(requirements, clientOptions);
} else {
syntaxClient.initialize(requirements, clientOptions, prepareExecutable(requirements, syntaxServerWorkspacePath, getJavaConfig(requirements.java_home), context, true));
syntaxClient.initialize(requirements, clientOptions, serverOptions);
}
syntaxClient.start();
syntaxClient.start().then(() => {
syntaxClient.registerSyntaxClientActions(serverOptions);
});
serverStatusBarProvider.showLightWeightStatus();
}

Expand Down Expand Up @@ -430,7 +434,9 @@ async function startStandardServer(context: ExtensionContext, requirements: requ
apiManager.fireDidServerModeChange(ServerMode.hybrid);
}
await standardClient.initialize(context, requirements, clientOptions, workspacePath, jdtEventEmitter);
standardClient.start();
standardClient.start().then(async () => {
standardClient.registerLanguageClientActions(context, await fse.pathExists(path.join(workspacePath, ".metadata", ".plugins")), jdtEventEmitter);
});
serverStatusBarProvider.showStandardStatus();
}

Expand Down Expand Up @@ -532,7 +538,9 @@ export async function getActiveLanguageClient(): Promise<LanguageClient | undefi
return undefined;
}

await languageClient.onReady();
if (languageClient.needsStart()) {
await languageClient.start();
}

return languageClient;
}
Expand Down
2 changes: 1 addition & 1 deletion src/fileEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function getWillRenameHandler(client: LanguageClient) {
const edit = await client.sendRequest(WillRenameFiles.type, {
files: javaRenameEvents
});
resolve(client.protocol2CodeConverter.asWorkspaceEdit(edit));
resolve(await client.protocol2CodeConverter.asWorkspaceEdit(edit));
} catch (ex) {
reject(ex);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pasteEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class PasteEditProvider implements DocumentPasteEditProvider {
if (pasteResponse) {
return {
insertText: pasteResponse.insertText,
additionalEdit: pasteResponse.additionalEdit ? this.languageClient.protocol2CodeConverter.asWorkspaceEdit(pasteResponse.additionalEdit) : undefined
additionalEdit: pasteResponse.additionalEdit ? await this.languageClient.protocol2CodeConverter.asWorkspaceEdit(pasteResponse.additionalEdit) : undefined
} as VDocumentPasteEdit;
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/refactorAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ async function applyRefactorEdit(languageClient: LanguageClient, refactorEdit: R
}

if (refactorEdit.edit) {
const edit = languageClient.protocol2CodeConverter.asWorkspaceEdit(refactorEdit.edit);
const edit = await languageClient.protocol2CodeConverter.asWorkspaceEdit(refactorEdit.edit);
if (edit) {
await workspace.applyEdit(edit);
}
Expand Down
2 changes: 1 addition & 1 deletion src/sourceAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function registerGenerateDelegateMethodsCommand(languageClient: LanguageClient,
}

async function revealWorkspaceEdit(workspaceEdit: WorkspaceEdit, languageClient: LanguageClient): Promise<void> {
const codeWorkspaceEdit = languageClient.protocol2CodeConverter.asWorkspaceEdit(workspaceEdit);
const codeWorkspaceEdit = await languageClient.protocol2CodeConverter.asWorkspaceEdit(workspaceEdit);
if (!codeWorkspaceEdit) {
return;
}
Expand Down
Loading