mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Make more things private
This commit is contained in:
parent
8aaafddee8
commit
d68616a140
5 changed files with 31 additions and 23 deletions
|
@ -54,8 +54,6 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
|
||||||
this,
|
this,
|
||||||
ctx.subscriptions
|
ctx.subscriptions
|
||||||
);
|
);
|
||||||
|
|
||||||
ctx.pushExtCleanup(this);
|
|
||||||
}
|
}
|
||||||
dispose() {
|
dispose() {
|
||||||
this.setRustEditor(undefined);
|
this.setRustEditor(undefined);
|
||||||
|
|
|
@ -377,8 +377,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
void new AstInspector(ctx);
|
ctx.pushExtCleanup(new AstInspector(ctx));
|
||||||
|
|
||||||
ctx.pushExtCleanup(
|
ctx.pushExtCleanup(
|
||||||
vscode.workspace.registerTextDocumentContentProvider("rust-analyzer-syntax-tree", tdcp)
|
vscode.workspace.registerTextDocumentContentProvider("rust-analyzer-syntax-tree", tdcp)
|
||||||
);
|
);
|
||||||
|
|
|
@ -23,12 +23,12 @@ export class Ctx {
|
||||||
readonly config: Config;
|
readonly config: Config;
|
||||||
|
|
||||||
private client: lc.LanguageClient | undefined;
|
private client: lc.LanguageClient | undefined;
|
||||||
|
private _serverPath: string | undefined;
|
||||||
|
private traceOutputChannel: vscode.OutputChannel | undefined;
|
||||||
|
private outputChannel: vscode.OutputChannel | undefined;
|
||||||
|
private state: PersistentState;
|
||||||
|
|
||||||
traceOutputChannel: vscode.OutputChannel | undefined;
|
|
||||||
outputChannel: vscode.OutputChannel | undefined;
|
|
||||||
workspace: Workspace;
|
workspace: Workspace;
|
||||||
state: PersistentState;
|
|
||||||
serverPath: string | undefined;
|
|
||||||
|
|
||||||
constructor(readonly extCtx: vscode.ExtensionContext, workspace: Workspace) {
|
constructor(readonly extCtx: vscode.ExtensionContext, workspace: Workspace) {
|
||||||
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||||
|
@ -70,21 +70,24 @@ export class Ctx {
|
||||||
if (!this.client) {
|
if (!this.client) {
|
||||||
log.info("Creating language client");
|
log.info("Creating language client");
|
||||||
|
|
||||||
this.serverPath = await bootstrap(this.extCtx, this.config, this.state).catch((err) => {
|
this._serverPath = await bootstrap(this.extCtx, this.config, this.state).catch(
|
||||||
let message = "bootstrap error. ";
|
(err) => {
|
||||||
|
let message = "bootstrap error. ";
|
||||||
|
|
||||||
message +=
|
message +=
|
||||||
'See the logs in "OUTPUT > Rust Analyzer Client" (should open automatically). ';
|
'See the logs in "OUTPUT > Rust Analyzer Client" (should open automatically). ';
|
||||||
message += 'To enable verbose logs use { "rust-analyzer.trace.extension": true }';
|
message +=
|
||||||
|
'To enable verbose logs use { "rust-analyzer.trace.extension": true }';
|
||||||
|
|
||||||
log.error("Bootstrap error", err);
|
log.error("Bootstrap error", err);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
const newEnv = substituteVariablesInEnv(
|
const newEnv = substituteVariablesInEnv(
|
||||||
Object.assign({}, process.env, this.config.serverExtraEnv)
|
Object.assign({}, process.env, this.config.serverExtraEnv)
|
||||||
);
|
);
|
||||||
const run: lc.Executable = {
|
const run: lc.Executable = {
|
||||||
command: this.serverPath,
|
command: this._serverPath,
|
||||||
options: { env: newEnv },
|
options: { env: newEnv },
|
||||||
};
|
};
|
||||||
const serverOptions = {
|
const serverOptions = {
|
||||||
|
@ -129,7 +132,7 @@ export class Ctx {
|
||||||
async disposeClient() {
|
async disposeClient() {
|
||||||
log.info("Deactivating language client");
|
log.info("Deactivating language client");
|
||||||
await this.client?.dispose();
|
await this.client?.dispose();
|
||||||
this.serverPath = undefined;
|
this._serverPath = undefined;
|
||||||
this.client = undefined;
|
this.client = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +164,10 @@ export class Ctx {
|
||||||
return this.extCtx.subscriptions;
|
return this.extCtx.subscriptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get serverPath(): string | undefined {
|
||||||
|
return this._serverPath;
|
||||||
|
}
|
||||||
|
|
||||||
setServerStatus(status: ServerStatusParams) {
|
setServerStatus(status: ServerStatusParams) {
|
||||||
let icon = "";
|
let icon = "";
|
||||||
const statusBar = this.statusBar;
|
const statusBar = this.statusBar;
|
||||||
|
|
|
@ -14,6 +14,10 @@ export interface RustAnalyzerExtensionApi {
|
||||||
readonly client?: lc.LanguageClient;
|
readonly client?: lc.LanguageClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deactivate() {
|
||||||
|
await setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
|
||||||
|
}
|
||||||
|
|
||||||
export async function activate(
|
export async function activate(
|
||||||
context: vscode.ExtensionContext
|
context: vscode.ExtensionContext
|
||||||
): Promise<RustAnalyzerExtensionApi> {
|
): Promise<RustAnalyzerExtensionApi> {
|
||||||
|
@ -56,12 +60,14 @@ export async function activate(
|
||||||
const ctx = new Ctx(context, workspace);
|
const ctx = new Ctx(context, workspace);
|
||||||
// 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.
|
||||||
return await activateServer(ctx).catch((err) => {
|
const api = await activateServer(ctx).catch((err) => {
|
||||||
void vscode.window.showErrorMessage(
|
void vscode.window.showErrorMessage(
|
||||||
`Cannot activate rust-analyzer extension: ${err.message}`
|
`Cannot activate rust-analyzer extension: ${err.message}`
|
||||||
);
|
);
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
await setContextValue(RUST_PROJECT_CONTEXT_NAME, true);
|
||||||
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function activateServer(ctx: Ctx): Promise<RustAnalyzerExtensionApi> {
|
async function activateServer(ctx: Ctx): Promise<RustAnalyzerExtensionApi> {
|
||||||
|
@ -112,8 +118,6 @@ async function initCommonContext(ctx: Ctx) {
|
||||||
);
|
);
|
||||||
ctx.pushExtCleanup(defaultOnEnter);
|
ctx.pushExtCleanup(defaultOnEnter);
|
||||||
|
|
||||||
await setContextValue(RUST_PROJECT_CONTEXT_NAME, true);
|
|
||||||
|
|
||||||
// Commands which invokes manually via command palette, shortcut, etc.
|
// Commands which invokes manually via command palette, shortcut, etc.
|
||||||
ctx.registerCommand("reload", (_) => async () => {
|
ctx.registerCommand("reload", (_) => async () => {
|
||||||
void vscode.window.showInformationMessage("Reloading rust-analyzer...");
|
void vscode.window.showInformationMessage("Reloading rust-analyzer...");
|
||||||
|
|
|
@ -18,9 +18,9 @@ export async function selectRunnable(
|
||||||
showButtons: boolean = true
|
showButtons: boolean = true
|
||||||
): Promise<RunnableQuickPick | undefined> {
|
): Promise<RunnableQuickPick | undefined> {
|
||||||
const editor = ctx.activeRustEditor;
|
const editor = ctx.activeRustEditor;
|
||||||
const client = ctx.client;
|
if (!editor) return;
|
||||||
if (!editor || !client) return;
|
|
||||||
|
|
||||||
|
const client = await ctx.getClient();
|
||||||
const textDocument: lc.TextDocumentIdentifier = {
|
const textDocument: lc.TextDocumentIdentifier = {
|
||||||
uri: editor.document.uri.toString(),
|
uri: editor.document.uri.toString(),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue