Skip to content

Commit b181217

Browse files
committed
abstract out max restart count
1 parent 49fe8b3 commit b181217

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- New "Report Issue" command (#93)
1515
- New "Show Output" command
1616
- Extend OutputChannel to be able to buffer output internally for error reporting (up to 1000 lines)
17+
- Add button to report server crashes
18+
- Abstract out Max Restart Count into a setting `psalm.maxRestartCount`
1719

1820
## [2.2.3] - 2021-09-17
1921

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@
174174
"type": "boolean",
175175
"default": true,
176176
"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."
177+
},
178+
"psalm.maxRestartCount": {
179+
"type": "number",
180+
"default": 5,
181+
"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)"
177182
}
178183
}
179184
},

src/ConfigurationService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export class ConfigurationService {
3030
workspaceConfiguration.get<string>('psalmScriptPath') ||
3131
join('vendor', 'vimeo', 'psalm', 'psalm-language-server');
3232

33+
this.config.maxRestartCount =
34+
workspaceConfiguration.get<number>('maxRestartCount') || 5;
35+
3336
this.config.unusedVariableDetection =
3437
workspaceConfiguration.get<boolean>('unusedVariableDetection') ||
3538
false;

src/LanguageServer.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export class LanguageServer {
7575
],
7676
},
7777
progressOnInitialization: true,
78-
errorHandler: this.createDefaultErrorHandler(5),
78+
errorHandler: this.createDefaultErrorHandler(
79+
this.configurationService.get<number>('maxRestartCount') - 1
80+
),
7981
},
8082
this.debug
8183
);
@@ -93,7 +95,10 @@ export class LanguageServer {
9395
if (maxRestartCount !== undefined && maxRestartCount < 0) {
9496
throw new Error(`Invalid maxRestartCount: ${maxRestartCount}`);
9597
}
96-
return new LanguageServerErrorHandler('Thing', maxRestartCount ?? 4);
98+
return new LanguageServerErrorHandler(
99+
'Psalm Language Server',
100+
maxRestartCount ?? 4
101+
);
97102
}
98103

99104
private onTelemetry(params: any) {

src/commands.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ interface Command {
1313
execute(): void;
1414
}
1515

16-
async function restartSever(client: LanguageServer) {
16+
async function restartSever(
17+
client: LanguageServer,
18+
configurationService: ConfigurationService
19+
) {
1720
const languageServerVersion = await client.getPsalmLanguageServerVersion();
1821
if (languageServerVersion === null) {
1922
const reload = await vscode.window.showWarningMessage(
20-
'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',
23+
`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>(
24+
'maxRestartCount'
25+
)} times per session. Consider upgrading to at least 4.9.0 of Psalm`,
2126
'Ok',
2227
'Cancel'
2328
);
@@ -30,20 +35,26 @@ async function restartSever(client: LanguageServer) {
3035
}
3136
}
3237

33-
function analyzeWorkSpace(client: LanguageServer): Command {
38+
function analyzeWorkSpace(
39+
client: LanguageServer,
40+
configurationService: ConfigurationService
41+
): Command {
3442
return {
3543
id: 'psalm.analyzeWorkSpace',
3644
async execute() {
37-
return await restartSever(client);
45+
return await restartSever(client, configurationService);
3846
},
3947
};
4048
}
4149

42-
function restartPsalmServer(client: LanguageServer): Command {
50+
function restartPsalmServer(
51+
client: LanguageServer,
52+
configurationService: ConfigurationService
53+
): Command {
4354
return {
4455
id: 'psalm.restartPsalmServer',
4556
async execute() {
46-
return await restartSever(client);
57+
return await restartSever(client, configurationService);
4758
},
4859
};
4960
}
@@ -114,8 +125,8 @@ export function registerCommands(
114125
loggingService: LoggingService
115126
): vscode.Disposable[] {
116127
const commands: Command[] = [
117-
restartPsalmServer(client),
118-
analyzeWorkSpace(client),
128+
restartPsalmServer(client, configurationService),
129+
analyzeWorkSpace(client, configurationService),
119130
reportIssue(client, configurationService, loggingService),
120131
showOutput(loggingService),
121132
];

0 commit comments

Comments
 (0)