Skip to content

Commit 6e16714

Browse files
committed
chore: remove companion extension hooks
*** vscode: remove companion extension hooks
1 parent 14ddae7 commit 6e16714

File tree

10 files changed

+9
-250
lines changed

10 files changed

+9
-250
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3044,7 +3044,7 @@ fn doc_comment_to_string(doc: &[&str]) -> String {
30443044

30453045
#[cfg(test)]
30463046
mod tests {
3047-
use std::{env::temp_dir, fs};
3047+
use std::fs;
30483048

30493049
use test_utils::{ensure_file_contents, project_root};
30503050

docs/dev/lsp-extensions.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -580,25 +580,6 @@ Reloads project information (that is, re-executes `cargo metadata`).
580580

581581
Rebuilds build scripts and proc-macros, and runs the build scripts to reseed the build data.
582582

583-
## Unindexed Project
584-
585-
**Experimental Client Capability:** `{ "unindexedProject": boolean }`
586-
587-
**Method:** `rust-analyzer/unindexedProject`
588-
589-
**Notification:**
590-
591-
```typescript
592-
interface UnindexedProjectParams {
593-
/// A list of documents that rust-analyzer has determined are not indexed.
594-
textDocuments: lc.TextDocumentIdentifier[]
595-
}
596-
```
597-
598-
This notification is sent from the server to the client. The client is expected
599-
to determine the appropriate owners of `textDocuments` and update `linkedProjects`
600-
if an owner can be determined successfully.
601-
602583
## Server Status
603584

604585
**Experimental Client Capability:** `{ "serverStatusNotification": boolean }`

docs/user/generated_config.adoc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,6 @@ Sets the LRU capacity of the specified queries.
819819
--
820820
Whether to show `can't find Cargo.toml` error message.
821821
--
822-
[[rust-analyzer.notifications.unindexedProject]]rust-analyzer.notifications.unindexedProject (default: `false`)::
823-
+
824-
--
825-
Whether to send an UnindexedProject notification to the client.
826-
--
827822
[[rust-analyzer.numThreads]]rust-analyzer.numThreads (default: `null`)::
828823
+
829824
--

editors/code/package.json

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,6 @@
487487
"default": false,
488488
"type": "boolean"
489489
},
490-
"rust-analyzer.discoverProjectRunner": {
491-
"markdownDescription": "Sets the extension responsible for determining which extension the rust-analyzer extension uses to generate `rust-project.json` files. This should should only be used\n if a build system like Buck or Bazel is also in use.",
492-
"default": null,
493-
"type": [
494-
"null",
495-
"string"
496-
]
497-
},
498490
"rust-analyzer.showUnlinkedFileNotification": {
499491
"markdownDescription": "Whether to show a notification for unlinked files asking the user to add the corresponding Cargo.toml to the linked projects setting.",
500492
"default": true,
@@ -1556,11 +1548,6 @@
15561548
"default": true,
15571549
"type": "boolean"
15581550
},
1559-
"rust-analyzer.notifications.unindexedProject": {
1560-
"markdownDescription": "Whether to send an UnindexedProject notification to the client.",
1561-
"default": false,
1562-
"type": "boolean"
1563-
},
15641551
"rust-analyzer.numThreads": {
15651552
"markdownDescription": "How many worker threads in the main loop. The default `null` means to pick automatically.",
15661553
"default": null,

editors/code/src/client.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,7 @@ export async function createClient(
102102
const resp = await next(params, token);
103103
if (resp && Array.isArray(resp)) {
104104
return resp.map((val) => {
105-
return prepareVSCodeConfig(val, (key, cfg) => {
106-
// we only want to set discovered workspaces on the right key
107-
// and if a workspace has been discovered.
108-
if (
109-
key === "linkedProjects" &&
110-
config.discoveredWorkspaces.length > 0
111-
) {
112-
cfg[key] = config.discoveredWorkspaces;
113-
}
114-
});
105+
return prepareVSCodeConfig(val);
115106
});
116107
} else {
117108
return resp;

editors/code/src/config.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as vscode from "vscode";
55
import type { Env } from "./client";
66
import { log } from "./util";
77
import { expectNotUndefined, unwrapUndefinable } from "./undefinable";
8-
import type { JsonProject } from "./rust_project";
98

109
export type RunnableEnvCfgItem = {
1110
mask?: string;
@@ -41,7 +40,6 @@ export class Config {
4140

4241
constructor(ctx: vscode.ExtensionContext) {
4342
this.globalStorageUri = ctx.globalStorageUri;
44-
this.discoveredWorkspaces = [];
4543
vscode.workspace.onDidChangeConfiguration(
4644
this.onDidChangeConfiguration,
4745
this,
@@ -63,8 +61,6 @@ export class Config {
6361
log.info("Using configuration", Object.fromEntries(cfg));
6462
}
6563

66-
public discoveredWorkspaces: JsonProject[];
67-
6864
private async onDidChangeConfiguration(event: vscode.ConfigurationChangeEvent) {
6965
this.refreshLogging();
7066

@@ -357,18 +353,7 @@ export class Config {
357353
}
358354
}
359355

360-
// the optional `cb?` parameter is meant to be used to add additional
361-
// key/value pairs to the VS Code configuration. This needed for, e.g.,
362-
// including a `rust-project.json` into the `linkedProjects` key as part
363-
// of the configuration/InitializationParams _without_ causing VS Code
364-
// configuration to be written out to workspace-level settings. This is
365-
// undesirable behavior because rust-project.json files can be tens of
366-
// thousands of lines of JSON, most of which is not meant for humans
367-
// to interact with.
368-
export function prepareVSCodeConfig<T>(
369-
resp: T,
370-
cb?: (key: Extract<keyof T, string>, res: { [key: string]: any }) => void,
371-
): T {
356+
export function prepareVSCodeConfig<T>(resp: T): T {
372357
if (Is.string(resp)) {
373358
return substituteVSCodeVariableInString(resp) as T;
374359
} else if (resp && Is.array<any>(resp)) {
@@ -380,9 +365,6 @@ export function prepareVSCodeConfig<T>(
380365
for (const key in resp) {
381366
const val = resp[key];
382367
res[key] = prepareVSCodeConfig(val);
383-
if (cb) {
384-
cb(key, res);
385-
}
386368
}
387369
return res as T;
388370
}

editors/code/src/ctx.ts

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode";
2-
import * as lc from "vscode-languageclient/node";
2+
import type * as lc from "vscode-languageclient/node";
33
import * as ra from "./lsp_ext";
44

55
import { Config, prepareVSCodeConfig } from "./config";
@@ -22,8 +22,6 @@ import {
2222
import { execRevealDependency } from "./commands";
2323
import { PersistentState } from "./persistent_state";
2424
import { bootstrap } from "./bootstrap";
25-
import type { RustAnalyzerExtensionApi } from "./main";
26-
import type { JsonProject } from "./rust_project";
2725
import { prepareTestExplorer } from "./test_explorer";
2826

2927
// We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
@@ -67,9 +65,9 @@ export type CtxInit = Ctx & {
6765
readonly client: lc.LanguageClient;
6866
};
6967

70-
export class Ctx implements RustAnalyzerExtensionApi {
68+
export class Ctx {
7169
readonly statusBar: vscode.StatusBarItem;
72-
config: Config;
70+
readonly config: Config;
7371
readonly workspace: Workspace;
7472

7573
private _client: lc.LanguageClient | undefined;
@@ -197,15 +195,6 @@ export class Ctx implements RustAnalyzerExtensionApi {
197195
};
198196

199197
let rawInitializationOptions = vscode.workspace.getConfiguration("rust-analyzer");
200-
if (this.config.discoverProjectRunner) {
201-
const command = `${this.config.discoverProjectRunner}.discoverWorkspaceCommand`;
202-
log.info(`running command: ${command}`);
203-
const uris = vscode.workspace.textDocuments
204-
.filter(isRustDocument)
205-
.map((document) => document.uri);
206-
const projects: JsonProject[] = await vscode.commands.executeCommand(command, uris);
207-
this.setWorkspaces(projects);
208-
}
209198

210199
if (this.workspace.kind === "Detached Files") {
211200
rawInitializationOptions = {
@@ -214,16 +203,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
214203
};
215204
}
216205

217-
const initializationOptions = prepareVSCodeConfig(
218-
rawInitializationOptions,
219-
(key, obj) => {
220-
// we only want to set discovered workspaces on the right key
221-
// and if a workspace has been discovered.
222-
if (key === "linkedProjects" && this.config.discoveredWorkspaces.length > 0) {
223-
obj["linkedProjects"] = this.config.discoveredWorkspaces;
224-
}
225-
},
226-
);
206+
const initializationOptions = prepareVSCodeConfig(rawInitializationOptions);
227207

228208
this._client = await createClient(
229209
this.traceOutputChannel,
@@ -243,23 +223,6 @@ export class Ctx implements RustAnalyzerExtensionApi {
243223
this.outputChannel!.show();
244224
}),
245225
);
246-
this.pushClientCleanup(
247-
this._client.onNotification(ra.unindexedProject, async (params) => {
248-
if (this.config.discoverProjectRunner) {
249-
const command = `${this.config.discoverProjectRunner}.discoverWorkspaceCommand`;
250-
log.info(`running command: ${command}`);
251-
const uris = params.textDocuments.map((doc) =>
252-
vscode.Uri.parse(doc.uri, true),
253-
);
254-
const projects: JsonProject[] = await vscode.commands.executeCommand(
255-
command,
256-
uris,
257-
);
258-
this.setWorkspaces(projects);
259-
await this.notifyRustAnalyzer();
260-
}
261-
}),
262-
);
263226
}
264227
return this._client;
265228
}
@@ -376,19 +339,6 @@ export class Ctx implements RustAnalyzerExtensionApi {
376339
return this._serverPath;
377340
}
378341

379-
setWorkspaces(workspaces: JsonProject[]) {
380-
this.config.discoveredWorkspaces = workspaces;
381-
}
382-
383-
async notifyRustAnalyzer(): Promise<void> {
384-
// this is a workaround to avoid needing writing the `rust-project.json` into
385-
// a workspace-level VS Code-specific settings folder. We'd like to keep the
386-
// `rust-project.json` entirely in-memory.
387-
await this.client?.sendNotification(lc.DidChangeConfigurationNotification.type, {
388-
settings: "",
389-
});
390-
}
391-
392342
private updateCommands(forceDisable?: "disable") {
393343
this.commandDisposables.forEach((disposable) => disposable.dispose());
394344
this.commandDisposables = [];

editors/code/src/lsp_ext.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,3 @@ export type RecursiveMemoryLayoutNode = {
263263
export type RecursiveMemoryLayout = {
264264
nodes: RecursiveMemoryLayoutNode[];
265265
};
266-
267-
export const unindexedProject = new lc.NotificationType<UnindexedProjectParams>(
268-
"rust-analyzer/unindexedProject",
269-
);
270-
271-
export type UnindexedProjectParams = { textDocuments: lc.TextDocumentIdentifier[] };

editors/code/src/main.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,14 @@ import { type CommandFactory, Ctx, fetchWorkspace } from "./ctx";
66
import * as diagnostics from "./diagnostics";
77
import { activateTaskProvider } from "./tasks";
88
import { setContextValue } from "./util";
9-
import type { JsonProject } from "./rust_project";
109

1110
const RUST_PROJECT_CONTEXT_NAME = "inRustProject";
1211

13-
// This API is not stable and may break in between minor releases.
14-
export interface RustAnalyzerExtensionApi {
15-
readonly client?: lc.LanguageClient;
16-
17-
setWorkspaces(workspaces: JsonProject[]): void;
18-
notifyRustAnalyzer(): Promise<void>;
19-
}
20-
2112
export async function deactivate() {
2213
await setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
2314
}
2415

25-
export async function activate(
26-
context: vscode.ExtensionContext,
27-
): Promise<RustAnalyzerExtensionApi> {
16+
export async function activate(context: vscode.ExtensionContext): Promise<Ctx> {
2817
checkConflictingExtensions();
2918

3019
const ctx = new Ctx(context, createCommands(), fetchWorkspace());
@@ -40,7 +29,7 @@ export async function activate(
4029
return api;
4130
}
4231

43-
async function activateServer(ctx: Ctx): Promise<RustAnalyzerExtensionApi> {
32+
async function activateServer(ctx: Ctx): Promise<Ctx> {
4433
if (ctx.workspace.kind === "Workspace Folder") {
4534
ctx.pushExtCleanup(activateTaskProvider(ctx.config));
4635
}

0 commit comments

Comments
 (0)