From d607c1b558b434d60846ce3052da0058e761a530 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Thu, 21 Apr 2022 13:39:53 -0700 Subject: [PATCH] Export lc.LanguageClient from VSCode extension --- editors/code/src/main.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 0451e4c3d6e..7591865390b 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -1,4 +1,5 @@ import * as vscode from 'vscode'; +import * as lc from 'vscode-languageclient/node'; import * as os from "os"; import * as commands from './commands'; @@ -14,16 +15,20 @@ let ctx: Ctx | undefined; const RUST_PROJECT_CONTEXT_NAME = "inRustProject"; -export async function activate(context: vscode.ExtensionContext) { +export interface RustAnalyzerExtensionApi { + client: lc.LanguageClient; +} + +export async function activate(context: vscode.ExtensionContext): Promise { // VS Code doesn't show a notification when an extension fails to activate // so we do it ourselves. - await tryActivate(context).catch(err => { + return await tryActivate(context).catch(err => { void vscode.window.showErrorMessage(`Cannot activate rust-analyzer: ${err.message}`); throw err; }); } -async function tryActivate(context: vscode.ExtensionContext) { +async function tryActivate(context: vscode.ExtensionContext): Promise { const config = new Config(context); const state = new PersistentState(context.globalState); const serverPath = await bootstrap(context, config, state).catch(err => { @@ -62,6 +67,10 @@ async function tryActivate(context: vscode.ExtensionContext) { null, ctx.subscriptions, ); + + return { + client: ctx.client + }; } async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {