mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-19 02:57:33 +00:00
Push IO and error handling up
This commit is contained in:
parent
6167101302
commit
ee4e41cbea
@ -2,18 +2,14 @@ import * as lc from 'vscode-languageclient';
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
import { Config } from './config';
|
import { Config } from './config';
|
||||||
import { ensureServerBinary } from './installation/server';
|
|
||||||
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
|
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed';
|
||||||
|
|
||||||
export async function createClient(config: Config): Promise<null | lc.LanguageClient> {
|
export async function createClient(config: Config, serverPath: string): Promise<lc.LanguageClient> {
|
||||||
// '.' Is the fallback if no folder is open
|
// '.' Is the fallback if no folder is open
|
||||||
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
|
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
|
||||||
// It might be a good idea to test if the uri points to a file.
|
// It might be a good idea to test if the uri points to a file.
|
||||||
const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
|
const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath ?? '.';
|
||||||
|
|
||||||
const serverPath = await ensureServerBinary(config.serverSource);
|
|
||||||
if (!serverPath) return null;
|
|
||||||
|
|
||||||
const run: lc.Executable = {
|
const run: lc.Executable = {
|
||||||
command: serverPath,
|
command: serverPath,
|
||||||
options: { cwd: workspaceFolderPath },
|
options: { cwd: workspaceFolderPath },
|
||||||
|
@ -23,16 +23,10 @@ export class Ctx {
|
|||||||
this.extCtx = extCtx;
|
this.extCtx = extCtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
async startServer() {
|
async startServer(serverPath: string) {
|
||||||
assert(this.client == null);
|
assert(this.client == null);
|
||||||
|
|
||||||
const client = await createClient(this.config);
|
const client = await createClient(this.config, serverPath);
|
||||||
if (!client) {
|
|
||||||
throw new Error(
|
|
||||||
"Rust Analyzer Language Server is not available. " +
|
|
||||||
"Please, ensure its [proper installation](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#vs-code)."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.pushCleanup(client.start());
|
this.pushCleanup(client.start());
|
||||||
await client.onReady();
|
await client.onReady();
|
||||||
|
@ -5,18 +5,27 @@ import { activateInlayHints } from './inlay_hints';
|
|||||||
import { activateStatusDisplay } from './status_display';
|
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';
|
||||||
|
|
||||||
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);
|
ctx = new Ctx(context);
|
||||||
|
|
||||||
|
const serverPath = await ensureServerBinary(ctx.config.serverSource);
|
||||||
|
if (serverPath == null) {
|
||||||
|
throw new Error(
|
||||||
|
"Rust Analyzer Language Server is not available. " +
|
||||||
|
"Please, ensure its [proper installation](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#vs-code)."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Note: we try to start the server before we activate type hints so that it
|
// Note: we try to start the server before we activate type hints so that it
|
||||||
// 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 {
|
try {
|
||||||
await ctx.startServer();
|
await ctx.startServer(serverPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
vscode.window.showErrorMessage(e.message);
|
vscode.window.showErrorMessage(e.message);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user