Separate persistent mutable state from config

That way, we clearly see which things are not change, and we also
clearly see which things are persistent.
This commit is contained in:
Aleksey Kladov 2020-03-16 19:23:38 +01:00
parent 2e9b6320e6
commit ae662617a2
7 changed files with 80 additions and 65 deletions

View file

@ -4,19 +4,21 @@ import * as lc from 'vscode-languageclient';
import { Config } from './config';
import { createClient } from './client';
import { isRustEditor, RustEditor } from './util';
import { PersistentState } from './persistent_state';
export class Ctx {
private constructor(
readonly config: Config,
readonly state: PersistentState,
private readonly extCtx: vscode.ExtensionContext,
readonly client: lc.LanguageClient
) {
}
static async create(config: Config, extCtx: vscode.ExtensionContext, serverPath: string): Promise<Ctx> {
static async create(config: Config, state: PersistentState, extCtx: vscode.ExtensionContext, serverPath: string): Promise<Ctx> {
const client = await createClient(config, serverPath);
const res = new Ctx(config, extCtx, client);
const res = new Ctx(config, state, extCtx, client);
res.pushCleanup(client.start());
await client.onReady();
return res;