mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Remove two stage constuction
This commit is contained in:
parent
978bea2b31
commit
89afb1a841
2 changed files with 15 additions and 21 deletions
|
@ -1,6 +1,5 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as lc from 'vscode-languageclient';
|
import * as lc from 'vscode-languageclient';
|
||||||
import { strict as assert } from "assert";
|
|
||||||
|
|
||||||
import { Config } from './config';
|
import { Config } from './config';
|
||||||
import { createClient } from './client';
|
import { createClient } from './client';
|
||||||
|
@ -15,23 +14,21 @@ export class Ctx {
|
||||||
// FIXME: this actually needs syncronization of some kind (check how
|
// FIXME: this actually needs syncronization of some kind (check how
|
||||||
// vscode deals with `deactivate()` call when extension has some work scheduled
|
// vscode deals with `deactivate()` call when extension has some work scheduled
|
||||||
// on the event loop to get a better picture of what we can do here)
|
// on the event loop to get a better picture of what we can do here)
|
||||||
client: lc.LanguageClient | null = null;
|
client: lc.LanguageClient;
|
||||||
private extCtx: vscode.ExtensionContext;
|
private extCtx: vscode.ExtensionContext;
|
||||||
|
|
||||||
constructor(extCtx: vscode.ExtensionContext) {
|
static async create(config: Config, extCtx: vscode.ExtensionContext, serverPath: string): Promise<Ctx> {
|
||||||
this.config = new Config(extCtx);
|
const client = await createClient(config, serverPath);
|
||||||
this.extCtx = extCtx;
|
const res = new Ctx(config, extCtx, client);
|
||||||
|
res.pushCleanup(client.start());
|
||||||
|
await client.onReady();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
async startServer(serverPath: string) {
|
private constructor(config: Config, extCtx: vscode.ExtensionContext, client: lc.LanguageClient) {
|
||||||
assert(this.client == null);
|
this.config = config;
|
||||||
|
this.extCtx = extCtx;
|
||||||
const client = await createClient(this.config, serverPath);
|
this.client = client
|
||||||
|
|
||||||
this.pushCleanup(client.start());
|
|
||||||
await client.onReady();
|
|
||||||
|
|
||||||
this.client = client;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get activeRustEditor(): vscode.TextEditor | undefined {
|
get activeRustEditor(): vscode.TextEditor | undefined {
|
||||||
|
|
|
@ -6,13 +6,14 @@ import { activateStatusDisplay } from './status_display';
|
||||||
import { Ctx } from './ctx';
|
import { Ctx } from './ctx';
|
||||||
import { activateHighlighting } from './highlighting';
|
import { activateHighlighting } from './highlighting';
|
||||||
import { ensureServerBinary } from './installation/server';
|
import { ensureServerBinary } from './installation/server';
|
||||||
|
import { Config } from './config';
|
||||||
|
|
||||||
let ctx: Ctx | undefined;
|
let ctx: Ctx | undefined;
|
||||||
|
|
||||||
export async function activate(context: vscode.ExtensionContext) {
|
export async function activate(context: vscode.ExtensionContext) {
|
||||||
ctx = new Ctx(context);
|
const config = new Config(context)
|
||||||
|
|
||||||
const serverPath = await ensureServerBinary(ctx.config.serverSource);
|
const serverPath = await ensureServerBinary(config.serverSource);
|
||||||
if (serverPath == null) {
|
if (serverPath == null) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Rust Analyzer Language Server is not available. " +
|
"Rust Analyzer Language Server is not available. " +
|
||||||
|
@ -24,11 +25,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
// registers its `onDidChangeDocument` handler before us.
|
// registers its `onDidChangeDocument` handler before us.
|
||||||
//
|
//
|
||||||
// This a horribly, horribly wrong way to deal with this problem.
|
// This a horribly, horribly wrong way to deal with this problem.
|
||||||
try {
|
ctx = await Ctx.create(config, context, serverPath);
|
||||||
await ctx.startServer(serverPath);
|
|
||||||
} catch (e) {
|
|
||||||
vscode.window.showErrorMessage(e.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commands which invokes manually via command palette, shortcut, etc.
|
// Commands which invokes manually via command palette, shortcut, etc.
|
||||||
ctx.registerCommand('reload', (ctx) => {
|
ctx.registerCommand('reload', (ctx) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue