Auto merge of #12053 - willcrichton:master, r=jonas-schievink
Export lc.LanguageClient from VSCode extension As described in [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Use.20Rust.20Analyzer.20in.20another.20VSCode.20extension), I would like to experiment with using Rust Analyzer's language server inside another VSCode extension, [Flowistry](https://github.com/willcrichton/flowistry). My current use case is to use one of Rust Analyzer's assists (extract function). This PR would enable that experimentation by exporting the `lc.LanguageClient` from the `activate` function, which [allows other extensions to access it](https://code.visualstudio.com/api/references/vscode-api#extensions). This PR does **not** commit RA to any stability guarantees about the language client, similar to how rustc exports an unstable API.
This commit is contained in:
commit
b6b5214c66
@ -1,4 +1,5 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
import * as lc from 'vscode-languageclient/node';
|
||||||
import * as os from "os";
|
import * as os from "os";
|
||||||
|
|
||||||
import * as commands from './commands';
|
import * as commands from './commands';
|
||||||
@ -14,16 +15,20 @@ let ctx: Ctx | undefined;
|
|||||||
|
|
||||||
const RUST_PROJECT_CONTEXT_NAME = "inRustProject";
|
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<RustAnalyzerExtensionApi> {
|
||||||
// VS Code doesn't show a notification when an extension fails to activate
|
// VS Code doesn't show a notification when an extension fails to activate
|
||||||
// so we do it ourselves.
|
// 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}`);
|
void vscode.window.showErrorMessage(`Cannot activate rust-analyzer: ${err.message}`);
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function tryActivate(context: vscode.ExtensionContext) {
|
async function tryActivate(context: vscode.ExtensionContext): Promise<RustAnalyzerExtensionApi> {
|
||||||
const config = new Config(context);
|
const config = new Config(context);
|
||||||
const state = new PersistentState(context.globalState);
|
const state = new PersistentState(context.globalState);
|
||||||
const serverPath = await bootstrap(context, config, state).catch(err => {
|
const serverPath = await bootstrap(context, config, state).catch(err => {
|
||||||
@ -62,6 +67,10 @@ async function tryActivate(context: vscode.ExtensionContext) {
|
|||||||
null,
|
null,
|
||||||
ctx.subscriptions,
|
ctx.subscriptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
client: ctx.client
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {
|
async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {
|
||||||
|
Loading…
Reference in New Issue
Block a user