mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
fix: Add config and capability for test explorer
This commit is contained in:
parent
52d8ae791d
commit
1c6d1b4f2a
7 changed files with 41 additions and 12 deletions
|
@ -1146,6 +1146,10 @@ impl Config {
|
||||||
self.experimental("colorDiagnosticOutput")
|
self.experimental("colorDiagnosticOutput")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn test_explorer(&self) -> bool {
|
||||||
|
self.experimental("testExplorer")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn publish_diagnostics(&self) -> bool {
|
pub fn publish_diagnostics(&self) -> bool {
|
||||||
self.data.diagnostics_enable
|
self.data.diagnostics_enable
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,10 +386,11 @@ impl GlobalState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let update_diagnostics = (!was_quiescent || state_changed || memdocs_added_or_removed)
|
let things_changed = !was_quiescent || state_changed || memdocs_added_or_removed;
|
||||||
&& self.config.publish_diagnostics();
|
if things_changed && self.config.publish_diagnostics() {
|
||||||
if update_diagnostics {
|
|
||||||
self.update_diagnostics();
|
self.update_diagnostics();
|
||||||
|
}
|
||||||
|
if things_changed && self.config.test_explorer() {
|
||||||
self.update_tests();
|
self.update_tests();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -387,6 +387,11 @@ rust-analyzer supports only one `kind`, `"cargo"`. The `args` for `"cargo"` look
|
||||||
|
|
||||||
## Test explorer
|
## Test explorer
|
||||||
|
|
||||||
|
**Experimental Client Capability:** `{ "testExplorer": boolean }`
|
||||||
|
|
||||||
|
If this capability is set, the `experimental/discoveredTests` notification will be sent from the
|
||||||
|
server to the client.
|
||||||
|
|
||||||
**Method:** `experimental/discoverTest`
|
**Method:** `experimental/discoverTest`
|
||||||
|
|
||||||
**Request:** `DiscoverTestParams`
|
**Request:** `DiscoverTestParams`
|
||||||
|
|
|
@ -510,6 +510,11 @@
|
||||||
"default": true,
|
"default": true,
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"rust-analyzer.testExplorer": {
|
||||||
|
"markdownDescription": "Whether to show the test explorer.",
|
||||||
|
"default": false,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"$generated-start": {},
|
"$generated-start": {},
|
||||||
"rust-analyzer.assist.emitMustUse": {
|
"rust-analyzer.assist.emitMustUse": {
|
||||||
"markdownDescription": "Whether to insert #[must_use] when generating `as_` methods\nfor enum variants.",
|
"markdownDescription": "Whether to insert #[must_use] when generating `as_` methods\nfor enum variants.",
|
||||||
|
|
|
@ -372,13 +372,18 @@ export async function createClient(
|
||||||
);
|
);
|
||||||
|
|
||||||
// To turn on all proposed features use: client.registerProposedFeatures();
|
// To turn on all proposed features use: client.registerProposedFeatures();
|
||||||
client.registerFeature(new ExperimentalFeatures());
|
client.registerFeature(new ExperimentalFeatures(config));
|
||||||
client.registerFeature(new OverrideFeatures());
|
client.registerFeature(new OverrideFeatures());
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExperimentalFeatures implements lc.StaticFeature {
|
class ExperimentalFeatures implements lc.StaticFeature {
|
||||||
|
private readonly testExplorer: boolean;
|
||||||
|
|
||||||
|
constructor(config: Config) {
|
||||||
|
this.testExplorer = config.testExplorer || false;
|
||||||
|
}
|
||||||
getState(): lc.FeatureState {
|
getState(): lc.FeatureState {
|
||||||
return { kind: "static" };
|
return { kind: "static" };
|
||||||
}
|
}
|
||||||
|
@ -391,6 +396,7 @@ class ExperimentalFeatures implements lc.StaticFeature {
|
||||||
colorDiagnosticOutput: true,
|
colorDiagnosticOutput: true,
|
||||||
openServerLogs: true,
|
openServerLogs: true,
|
||||||
localDocs: true,
|
localDocs: true,
|
||||||
|
testExplorer: this.testExplorer,
|
||||||
commands: {
|
commands: {
|
||||||
commands: [
|
commands: [
|
||||||
"rust-analyzer.runSingle",
|
"rust-analyzer.runSingle",
|
||||||
|
|
|
@ -266,6 +266,10 @@ export class Config {
|
||||||
return this.get<string | undefined>("cargoRunner");
|
return this.get<string | undefined>("cargoRunner");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get testExplorer() {
|
||||||
|
return this.get<boolean | undefined>("testExplorer");
|
||||||
|
}
|
||||||
|
|
||||||
get runnablesExtraEnv() {
|
get runnablesExtraEnv() {
|
||||||
const item = this.get<any>("runnables.extraEnv") ?? this.get<any>("runnableEnv");
|
const item = this.get<any>("runnables.extraEnv") ?? this.get<any>("runnableEnv");
|
||||||
if (!item) return item;
|
if (!item) return item;
|
||||||
|
|
|
@ -75,7 +75,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
private _client: lc.LanguageClient | undefined;
|
private _client: lc.LanguageClient | undefined;
|
||||||
private _serverPath: string | undefined;
|
private _serverPath: string | undefined;
|
||||||
private traceOutputChannel: vscode.OutputChannel | undefined;
|
private traceOutputChannel: vscode.OutputChannel | undefined;
|
||||||
private testController: vscode.TestController;
|
private testController: vscode.TestController | undefined;
|
||||||
private outputChannel: vscode.OutputChannel | undefined;
|
private outputChannel: vscode.OutputChannel | undefined;
|
||||||
private clientSubscriptions: Disposable[];
|
private clientSubscriptions: Disposable[];
|
||||||
private state: PersistentState;
|
private state: PersistentState;
|
||||||
|
@ -104,18 +104,20 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
) {
|
) {
|
||||||
extCtx.subscriptions.push(this);
|
extCtx.subscriptions.push(this);
|
||||||
|
this.config = new Config(extCtx);
|
||||||
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
|
||||||
this.testController = vscode.tests.createTestController(
|
if (this.config.testExplorer) {
|
||||||
"rustAnalyzerTestController",
|
this.testController = vscode.tests.createTestController(
|
||||||
"Rust Analyzer test controller",
|
"rustAnalyzerTestController",
|
||||||
);
|
"Rust Analyzer test controller",
|
||||||
|
);
|
||||||
|
}
|
||||||
this.workspace = workspace;
|
this.workspace = workspace;
|
||||||
this.clientSubscriptions = [];
|
this.clientSubscriptions = [];
|
||||||
this.commandDisposables = [];
|
this.commandDisposables = [];
|
||||||
this.commandFactories = commandFactories;
|
this.commandFactories = commandFactories;
|
||||||
this.unlinkedFiles = [];
|
this.unlinkedFiles = [];
|
||||||
this.state = new PersistentState(extCtx.globalState);
|
this.state = new PersistentState(extCtx.globalState);
|
||||||
this.config = new Config(extCtx);
|
|
||||||
|
|
||||||
this.updateCommands("disable");
|
this.updateCommands("disable");
|
||||||
this.setServerStatus({
|
this.setServerStatus({
|
||||||
|
@ -126,7 +128,7 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
dispose() {
|
dispose() {
|
||||||
this.config.dispose();
|
this.config.dispose();
|
||||||
this.statusBar.dispose();
|
this.statusBar.dispose();
|
||||||
this.testController.dispose();
|
this.testController?.dispose();
|
||||||
void this.disposeClient();
|
void this.disposeClient();
|
||||||
this.commandDisposables.forEach((disposable) => disposable.dispose());
|
this.commandDisposables.forEach((disposable) => disposable.dispose());
|
||||||
}
|
}
|
||||||
|
@ -271,7 +273,9 @@ export class Ctx implements RustAnalyzerExtensionApi {
|
||||||
await client.start();
|
await client.start();
|
||||||
this.updateCommands();
|
this.updateCommands();
|
||||||
|
|
||||||
prepareTestExplorer(this, this.testController, client);
|
if (this.testController) {
|
||||||
|
prepareTestExplorer(this, this.testController, client);
|
||||||
|
}
|
||||||
if (this.config.showDependenciesExplorer) {
|
if (this.config.showDependenciesExplorer) {
|
||||||
this.prepareTreeDependenciesView(client);
|
this.prepareTreeDependenciesView(client);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue