Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export lc.LanguageClient from VSCode extension #12053

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions editors/code/src/main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<RustAnalyzerExtensionApi> {
// 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<RustAnalyzerExtensionApi> {
const config = new Config(context);
const state = new PersistentState(context.globalState);
const serverPath = await bootstrap(context, config, state).catch(err => {
Expand Down Expand Up @@ -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) {
Expand Down