mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
parent
fcf15cc05a
commit
dcdbbddd16
6 changed files with 51 additions and 23 deletions
|
@ -1,5 +1,6 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as lc from 'vscode-languageclient';
|
||||
import { strict as assert } from "assert";
|
||||
|
||||
import { Config } from './config';
|
||||
import { createClient } from './client';
|
||||
|
@ -16,19 +17,16 @@ export class Ctx {
|
|||
// on the event loop to get a better picture of what we can do here)
|
||||
client: lc.LanguageClient | null = null;
|
||||
private extCtx: vscode.ExtensionContext;
|
||||
private onDidRestartHooks: Array<(client: lc.LanguageClient) => void> = [];
|
||||
private onStartHooks: Array<(client: lc.LanguageClient) => void> = [];
|
||||
|
||||
constructor(extCtx: vscode.ExtensionContext) {
|
||||
this.config = new Config(extCtx);
|
||||
this.extCtx = extCtx;
|
||||
}
|
||||
|
||||
async restartServer() {
|
||||
const old = this.client;
|
||||
if (old) {
|
||||
await old.stop();
|
||||
}
|
||||
this.client = null;
|
||||
async startServer() {
|
||||
assert(this.client == null);
|
||||
|
||||
const client = await createClient(this.config);
|
||||
if (!client) {
|
||||
throw new Error(
|
||||
|
@ -41,7 +39,7 @@ export class Ctx {
|
|||
await client.onReady();
|
||||
|
||||
this.client = client;
|
||||
for (const hook of this.onDidRestartHooks) {
|
||||
for (const hook of this.onStartHooks) {
|
||||
hook(client);
|
||||
}
|
||||
}
|
||||
|
@ -72,8 +70,13 @@ export class Ctx {
|
|||
this.extCtx.subscriptions.push(d);
|
||||
}
|
||||
|
||||
onDidRestart(hook: (client: lc.LanguageClient) => void) {
|
||||
this.onDidRestartHooks.push(hook);
|
||||
onStart(hook: (client: lc.LanguageClient) => void) {
|
||||
const client = this.client;
|
||||
if (client == null) {
|
||||
this.onStartHooks.push(hook);
|
||||
} else {
|
||||
hook(client)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue