Skip to content

Commit b6b5214

Browse files
committed
Auto merge of rust-lang#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.
2 parents 1db66b9 + d607c1b commit b6b5214

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

editors/code/src/main.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from 'vscode';
2+
import * as lc from 'vscode-languageclient/node';
23
import * as os from "os";
34

45
import * as commands from './commands';
@@ -14,16 +15,20 @@ let ctx: Ctx | undefined;
1415

1516
const RUST_PROJECT_CONTEXT_NAME = "inRustProject";
1617

17-
export async function activate(context: vscode.ExtensionContext) {
18+
export interface RustAnalyzerExtensionApi {
19+
client: lc.LanguageClient;
20+
}
21+
22+
export async function activate(context: vscode.ExtensionContext): Promise<RustAnalyzerExtensionApi> {
1823
// VS Code doesn't show a notification when an extension fails to activate
1924
// so we do it ourselves.
20-
await tryActivate(context).catch(err => {
25+
return await tryActivate(context).catch(err => {
2126
void vscode.window.showErrorMessage(`Cannot activate rust-analyzer: ${err.message}`);
2227
throw err;
2328
});
2429
}
2530

26-
async function tryActivate(context: vscode.ExtensionContext) {
31+
async function tryActivate(context: vscode.ExtensionContext): Promise<RustAnalyzerExtensionApi> {
2732
const config = new Config(context);
2833
const state = new PersistentState(context.globalState);
2934
const serverPath = await bootstrap(context, config, state).catch(err => {
@@ -62,6 +67,10 @@ async function tryActivate(context: vscode.ExtensionContext) {
6267
null,
6368
ctx.subscriptions,
6469
);
70+
71+
return {
72+
client: ctx.client
73+
};
6574
}
6675

6776
async function initCommonContext(context: vscode.ExtensionContext, ctx: Ctx) {

0 commit comments

Comments
 (0)