Skip to content

Commit

Permalink
abstract out max restart count
Browse files Browse the repository at this point in the history
  • Loading branch information
tm1000 committed Sep 17, 2021
1 parent 49fe8b3 commit b181217
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions src/ConfigurationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class ConfigurationService {
workspaceConfiguration.get<string>('psalmScriptPath') ||
join('vendor', 'vimeo', 'psalm', 'psalm-language-server');

this.config.maxRestartCount =
workspaceConfiguration.get<number>('maxRestartCount') || 5;

this.config.unusedVariableDetection =
workspaceConfiguration.get<boolean>('unusedVariableDetection') ||
false;
Expand Down
9 changes: 7 additions & 2 deletions src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class LanguageServer {
],
},
progressOnInitialization: true,
errorHandler: this.createDefaultErrorHandler(5),
errorHandler: this.createDefaultErrorHandler(
this.configurationService.get<number>('maxRestartCount') - 1
),
},
this.debug
);
Expand All @@ -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) {
Expand Down
27 changes: 19 additions & 8 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>(
'maxRestartCount'
)} times per session. Consider upgrading to at least 4.9.0 of Psalm`,
'Ok',
'Cancel'
);
Expand All @@ -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);
},
};
}
Expand Down Expand Up @@ -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),
];
Expand Down

0 comments on commit b181217

Please sign in to comment.