Skip to content

Commit d68616a

Browse files
committed
Make more things private
1 parent 8aaafdd commit d68616a

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
lines changed

editors/code/src/ast_inspector.ts

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ export class AstInspector implements vscode.HoverProvider, vscode.DefinitionProv
5454
this,
5555
ctx.subscriptions
5656
);
57-
58-
ctx.pushExtCleanup(this);
5957
}
6058
dispose() {
6159
this.setRustEditor(undefined);

editors/code/src/commands.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ export function syntaxTree(ctx: Ctx): Cmd {
377377
}
378378
})();
379379

380-
void new AstInspector(ctx);
381-
380+
ctx.pushExtCleanup(new AstInspector(ctx));
382381
ctx.pushExtCleanup(
383382
vscode.workspace.registerTextDocumentContentProvider("rust-analyzer-syntax-tree", tdcp)
384383
);

editors/code/src/ctx.ts

+21-14
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export class Ctx {
2323
readonly config: Config;
2424

2525
private client: lc.LanguageClient | undefined;
26+
private _serverPath: string | undefined;
27+
private traceOutputChannel: vscode.OutputChannel | undefined;
28+
private outputChannel: vscode.OutputChannel | undefined;
29+
private state: PersistentState;
2630

27-
traceOutputChannel: vscode.OutputChannel | undefined;
28-
outputChannel: vscode.OutputChannel | undefined;
2931
workspace: Workspace;
30-
state: PersistentState;
31-
serverPath: string | undefined;
3232

3333
constructor(readonly extCtx: vscode.ExtensionContext, workspace: Workspace) {
3434
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
@@ -70,21 +70,24 @@ export class Ctx {
7070
if (!this.client) {
7171
log.info("Creating language client");
7272

73-
this.serverPath = await bootstrap(this.extCtx, this.config, this.state).catch((err) => {
74-
let message = "bootstrap error. ";
73+
this._serverPath = await bootstrap(this.extCtx, this.config, this.state).catch(
74+
(err) => {
75+
let message = "bootstrap error. ";
7576

76-
message +=
77-
'See the logs in "OUTPUT > Rust Analyzer Client" (should open automatically). ';
78-
message += 'To enable verbose logs use { "rust-analyzer.trace.extension": true }';
77+
message +=
78+
'See the logs in "OUTPUT > Rust Analyzer Client" (should open automatically). ';
79+
message +=
80+
'To enable verbose logs use { "rust-analyzer.trace.extension": true }';
7981

80-
log.error("Bootstrap error", err);
81-
throw new Error(message);
82-
});
82+
log.error("Bootstrap error", err);
83+
throw new Error(message);
84+
}
85+
);
8386
const newEnv = substituteVariablesInEnv(
8487
Object.assign({}, process.env, this.config.serverExtraEnv)
8588
);
8689
const run: lc.Executable = {
87-
command: this.serverPath,
90+
command: this._serverPath,
8891
options: { env: newEnv },
8992
};
9093
const serverOptions = {
@@ -129,7 +132,7 @@ export class Ctx {
129132
async disposeClient() {
130133
log.info("Deactivating language client");
131134
await this.client?.dispose();
132-
this.serverPath = undefined;
135+
this._serverPath = undefined;
133136
this.client = undefined;
134137
}
135138

@@ -161,6 +164,10 @@ export class Ctx {
161164
return this.extCtx.subscriptions;
162165
}
163166

167+
get serverPath(): string | undefined {
168+
return this._serverPath;
169+
}
170+
164171
setServerStatus(status: ServerStatusParams) {
165172
let icon = "";
166173
const statusBar = this.statusBar;

editors/code/src/main.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export interface RustAnalyzerExtensionApi {
1414
readonly client?: lc.LanguageClient;
1515
}
1616

17+
export async function deactivate() {
18+
await setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
19+
}
20+
1721
export async function activate(
1822
context: vscode.ExtensionContext
1923
): Promise<RustAnalyzerExtensionApi> {
@@ -56,12 +60,14 @@ export async function activate(
5660
const ctx = new Ctx(context, workspace);
5761
// VS Code doesn't show a notification when an extension fails to activate
5862
// so we do it ourselves.
59-
return await activateServer(ctx).catch((err) => {
63+
const api = await activateServer(ctx).catch((err) => {
6064
void vscode.window.showErrorMessage(
6165
`Cannot activate rust-analyzer extension: ${err.message}`
6266
);
6367
throw err;
6468
});
69+
await setContextValue(RUST_PROJECT_CONTEXT_NAME, true);
70+
return api;
6571
}
6672

6773
async function activateServer(ctx: Ctx): Promise<RustAnalyzerExtensionApi> {
@@ -112,8 +118,6 @@ async function initCommonContext(ctx: Ctx) {
112118
);
113119
ctx.pushExtCleanup(defaultOnEnter);
114120

115-
await setContextValue(RUST_PROJECT_CONTEXT_NAME, true);
116-
117121
// Commands which invokes manually via command palette, shortcut, etc.
118122
ctx.registerCommand("reload", (_) => async () => {
119123
void vscode.window.showInformationMessage("Reloading rust-analyzer...");

editors/code/src/run.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export async function selectRunnable(
1818
showButtons: boolean = true
1919
): Promise<RunnableQuickPick | undefined> {
2020
const editor = ctx.activeRustEditor;
21-
const client = ctx.client;
22-
if (!editor || !client) return;
21+
if (!editor) return;
2322

23+
const client = await ctx.getClient();
2424
const textDocument: lc.TextDocumentIdentifier = {
2525
uri: editor.document.uri.toString(),
2626
};

0 commit comments

Comments
 (0)