From b181217db41b20db49339f203d47abce1e9f36cf Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 17 Sep 2021 15:36:16 -0700 Subject: [PATCH] abstract out max restart count --- CHANGELOG.md | 2 ++ package.json | 5 +++++ src/ConfigurationService.ts | 3 +++ src/LanguageServer.ts | 9 +++++++-- src/commands.ts | 27 +++++++++++++++++++-------- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29bbec0..3f3ff1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New "Report Issue" command (#93) - New "Show Output" command - Extend OutputChannel to be able to buffer output internally for error reporting (up to 1000 lines) +- Add button to report server crashes +- Abstract out Max Restart Count into a setting `psalm.maxRestartCount` ## [2.2.3] - 2021-09-17 diff --git a/package.json b/package.json index 8a26277..ee8190d 100644 --- a/package.json +++ b/package.json @@ -174,6 +174,11 @@ "type": "boolean", "default": true, "description": "This will hide the Psalm status from the status bar when it is started and running. This is useful to clear up a cluttered status bar." + }, + "psalm.maxRestartCount": { + "type": "number", + "default": 5, + "description": "The number of times the Language Server is allowed to crash and restart before it will no longer try to restart (Modifying requires VSCode reload)" } } }, diff --git a/src/ConfigurationService.ts b/src/ConfigurationService.ts index 636ccef..8ba61ed 100644 --- a/src/ConfigurationService.ts +++ b/src/ConfigurationService.ts @@ -30,6 +30,9 @@ export class ConfigurationService { workspaceConfiguration.get('psalmScriptPath') || join('vendor', 'vimeo', 'psalm', 'psalm-language-server'); + this.config.maxRestartCount = + workspaceConfiguration.get('maxRestartCount') || 5; + this.config.unusedVariableDetection = workspaceConfiguration.get('unusedVariableDetection') || false; diff --git a/src/LanguageServer.ts b/src/LanguageServer.ts index d901bf1..9b3479a 100644 --- a/src/LanguageServer.ts +++ b/src/LanguageServer.ts @@ -75,7 +75,9 @@ export class LanguageServer { ], }, progressOnInitialization: true, - errorHandler: this.createDefaultErrorHandler(5), + errorHandler: this.createDefaultErrorHandler( + this.configurationService.get('maxRestartCount') - 1 + ), }, this.debug ); @@ -93,7 +95,10 @@ export class LanguageServer { if (maxRestartCount !== undefined && maxRestartCount < 0) { throw new Error(`Invalid maxRestartCount: ${maxRestartCount}`); } - return new LanguageServerErrorHandler('Thing', maxRestartCount ?? 4); + return new LanguageServerErrorHandler( + 'Psalm Language Server', + maxRestartCount ?? 4 + ); } private onTelemetry(params: any) { diff --git a/src/commands.ts b/src/commands.ts index 1478fb7..8b077f2 100755 --- a/src/commands.ts +++ b/src/commands.ts @@ -13,11 +13,16 @@ interface Command { execute(): void; } -async function restartSever(client: LanguageServer) { +async function restartSever( + client: LanguageServer, + configurationService: ConfigurationService +) { const languageServerVersion = await client.getPsalmLanguageServerVersion(); if (languageServerVersion === null) { const reload = await vscode.window.showWarningMessage( - 'This version of Psalm has a bug in that the only way to force the Language Server to re-analyze the workspace is to forcefully crash it. VSCode limitations only allow us to do this 5 times per session. Consider upgrading to at least 4.9.0 of Psalm', + `This version of Psalm has a bug in that the only way to force the Language Server to re-analyze the workspace is to forcefully crash it. VSCode limitations only allow us to do this ${configurationService.get( + 'maxRestartCount' + )} times per session. Consider upgrading to at least 4.9.0 of Psalm`, 'Ok', 'Cancel' ); @@ -30,20 +35,26 @@ async function restartSever(client: LanguageServer) { } } -function analyzeWorkSpace(client: LanguageServer): Command { +function analyzeWorkSpace( + client: LanguageServer, + configurationService: ConfigurationService +): Command { return { id: 'psalm.analyzeWorkSpace', async execute() { - return await restartSever(client); + return await restartSever(client, configurationService); }, }; } -function restartPsalmServer(client: LanguageServer): Command { +function restartPsalmServer( + client: LanguageServer, + configurationService: ConfigurationService +): Command { return { id: 'psalm.restartPsalmServer', async execute() { - return await restartSever(client); + return await restartSever(client, configurationService); }, }; } @@ -114,8 +125,8 @@ export function registerCommands( loggingService: LoggingService ): vscode.Disposable[] { const commands: Command[] = [ - restartPsalmServer(client), - analyzeWorkSpace(client), + restartPsalmServer(client, configurationService), + analyzeWorkSpace(client, configurationService), reportIssue(client, configurationService, loggingService), showOutput(loggingService), ];