Skip to content

Commit ce15e73

Browse files
committed
Auto merge of #16773 - Veykril:text-explorer, r=Veykril
fix: Add config and capability for test explorer
2 parents e5889c9 + 1c6d1b4 commit ce15e73

File tree

7 files changed

+41
-12
lines changed

7 files changed

+41
-12
lines changed

crates/rust-analyzer/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,10 @@ impl Config {
11461146
self.experimental("colorDiagnosticOutput")
11471147
}
11481148

1149+
pub fn test_explorer(&self) -> bool {
1150+
self.experimental("testExplorer")
1151+
}
1152+
11491153
pub fn publish_diagnostics(&self) -> bool {
11501154
self.data.diagnostics_enable
11511155
}

crates/rust-analyzer/src/main_loop.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,11 @@ impl GlobalState {
386386
}
387387
}
388388

389-
let update_diagnostics = (!was_quiescent || state_changed || memdocs_added_or_removed)
390-
&& self.config.publish_diagnostics();
391-
if update_diagnostics {
389+
let things_changed = !was_quiescent || state_changed || memdocs_added_or_removed;
390+
if things_changed && self.config.publish_diagnostics() {
392391
self.update_diagnostics();
392+
}
393+
if things_changed && self.config.test_explorer() {
393394
self.update_tests();
394395
}
395396
}

docs/dev/lsp-extensions.md

+5
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ rust-analyzer supports only one `kind`, `"cargo"`. The `args` for `"cargo"` look
387387

388388
## Test explorer
389389

390+
**Experimental Client Capability:** `{ "testExplorer": boolean }`
391+
392+
If this capability is set, the `experimental/discoveredTests` notification will be sent from the
393+
server to the client.
394+
390395
**Method:** `experimental/discoverTest`
391396

392397
**Request:** `DiscoverTestParams`

editors/code/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,11 @@
510510
"default": true,
511511
"type": "boolean"
512512
},
513+
"rust-analyzer.testExplorer": {
514+
"markdownDescription": "Whether to show the test explorer.",
515+
"default": false,
516+
"type": "boolean"
517+
},
513518
"$generated-start": {},
514519
"rust-analyzer.assist.emitMustUse": {
515520
"markdownDescription": "Whether to insert #[must_use] when generating `as_` methods\nfor enum variants.",

editors/code/src/client.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,18 @@ export async function createClient(
372372
);
373373

374374
// To turn on all proposed features use: client.registerProposedFeatures();
375-
client.registerFeature(new ExperimentalFeatures());
375+
client.registerFeature(new ExperimentalFeatures(config));
376376
client.registerFeature(new OverrideFeatures());
377377

378378
return client;
379379
}
380380

381381
class ExperimentalFeatures implements lc.StaticFeature {
382+
private readonly testExplorer: boolean;
383+
384+
constructor(config: Config) {
385+
this.testExplorer = config.testExplorer || false;
386+
}
382387
getState(): lc.FeatureState {
383388
return { kind: "static" };
384389
}
@@ -391,6 +396,7 @@ class ExperimentalFeatures implements lc.StaticFeature {
391396
colorDiagnosticOutput: true,
392397
openServerLogs: true,
393398
localDocs: true,
399+
testExplorer: this.testExplorer,
394400
commands: {
395401
commands: [
396402
"rust-analyzer.runSingle",

editors/code/src/config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ export class Config {
266266
return this.get<string | undefined>("cargoRunner");
267267
}
268268

269+
get testExplorer() {
270+
return this.get<boolean | undefined>("testExplorer");
271+
}
272+
269273
get runnablesExtraEnv() {
270274
const item = this.get<any>("runnables.extraEnv") ?? this.get<any>("runnableEnv");
271275
if (!item) return item;

editors/code/src/ctx.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
7575
private _client: lc.LanguageClient | undefined;
7676
private _serverPath: string | undefined;
7777
private traceOutputChannel: vscode.OutputChannel | undefined;
78-
private testController: vscode.TestController;
78+
private testController: vscode.TestController | undefined;
7979
private outputChannel: vscode.OutputChannel | undefined;
8080
private clientSubscriptions: Disposable[];
8181
private state: PersistentState;
@@ -104,18 +104,20 @@ export class Ctx implements RustAnalyzerExtensionApi {
104104
workspace: Workspace,
105105
) {
106106
extCtx.subscriptions.push(this);
107+
this.config = new Config(extCtx);
107108
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
108-
this.testController = vscode.tests.createTestController(
109-
"rustAnalyzerTestController",
110-
"Rust Analyzer test controller",
111-
);
109+
if (this.config.testExplorer) {
110+
this.testController = vscode.tests.createTestController(
111+
"rustAnalyzerTestController",
112+
"Rust Analyzer test controller",
113+
);
114+
}
112115
this.workspace = workspace;
113116
this.clientSubscriptions = [];
114117
this.commandDisposables = [];
115118
this.commandFactories = commandFactories;
116119
this.unlinkedFiles = [];
117120
this.state = new PersistentState(extCtx.globalState);
118-
this.config = new Config(extCtx);
119121

120122
this.updateCommands("disable");
121123
this.setServerStatus({
@@ -126,7 +128,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
126128
dispose() {
127129
this.config.dispose();
128130
this.statusBar.dispose();
129-
this.testController.dispose();
131+
this.testController?.dispose();
130132
void this.disposeClient();
131133
this.commandDisposables.forEach((disposable) => disposable.dispose());
132134
}
@@ -271,7 +273,9 @@ export class Ctx implements RustAnalyzerExtensionApi {
271273
await client.start();
272274
this.updateCommands();
273275

274-
prepareTestExplorer(this, this.testController, client);
276+
if (this.testController) {
277+
prepareTestExplorer(this, this.testController, client);
278+
}
275279
if (this.config.showDependenciesExplorer) {
276280
this.prepareTreeDependenciesView(client);
277281
}

0 commit comments

Comments
 (0)