Skip to content

Commit ee96b30

Browse files
Ben MerrittBen Merritt
authored andcommitted
Add "Restart Phan Language Server" command
This is handy when the language server crashes.
1 parent 52189a6 commit ee96b30

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"url": "https://github.com/phan/phan/issues"
4040
},
4141
"activationEvents": [
42+
"onCommand:phan.restartLanguageServer",
4243
"onLanguage:php",
4344
"workspaceContains:**/*.php"
4445
],
@@ -67,6 +68,13 @@
6768
"vscode-languageclient": "^6.1.4"
6869
},
6970
"contributes": {
71+
"commands": [
72+
{
73+
"command": "phan.restartLanguageServer",
74+
"title": "Restart Phan Language Server",
75+
"category": "Phan"
76+
}
77+
],
7078
"configuration": {
7179
"type": "object",
7280
"title": "PHP - Phan Analyzer",

src/extension.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
430430
return new LanguageClient('Phan Language Server', serverOptions, clientOptions);
431431
};
432432

433+
const languageClients = analyzedProjectDirectories.map(createClient);
434+
435+
function restartLanguageClients() {
436+
return Promise.all(languageClients.map((c: LanguageClient) => c.stop().then(() => c.start())));
437+
}
438+
context.subscriptions.push(vscode.commands.registerCommand('phan.restartLanguageServer', restartLanguageClients));
439+
433440
console.log('starting PHP Phan language server');
434-
// Create the language client and start the client.
435-
for (const dirToAnalyze of analyzedProjectDirectories) {
441+
for (const client of languageClients) {
436442
// Push the disposable to the context's subscriptions so that the
437443
// client can be deactivated on extension deactivation
438-
context.subscriptions.push(createClient(dirToAnalyze).start());
444+
context.subscriptions.push(client.start());
439445
}
440446
}

0 commit comments

Comments
 (0)