Skip to content

Commit 574e23e

Browse files
committed
Auto merge of #16794 - HKalbasi:test-explorer, r=lnicola
Some minor changes in the test explorer lsp extension followup #16662 cc `@nemethf` `@ShuiRuTian`
2 parents 8f08bbe + dc99ad9 commit 574e23e

File tree

7 files changed

+45
-15
lines changed

7 files changed

+45
-15
lines changed

crates/flycheck/src/test_runner.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::command::{CommandHandle, ParseFromLine};
1414
pub enum TestState {
1515
Started,
1616
Ok,
17+
Ignored,
1718
Failed { stdout: String },
1819
}
1920

crates/rust-analyzer/src/lsp/ext.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub struct DiscoverTestParams {
171171

172172
#[derive(Deserialize, Serialize, Debug)]
173173
#[serde(rename_all = "camelCase")]
174-
pub enum TestItemIcon {
174+
pub enum TestItemKind {
175175
Package,
176176
Module,
177177
Test,
@@ -182,7 +182,7 @@ pub enum TestItemIcon {
182182
pub struct TestItem {
183183
pub id: String,
184184
pub label: String,
185-
pub icon: TestItemIcon,
185+
pub kind: TestItemKind,
186186
pub can_resolve_children: bool,
187187
pub parent: Option<String>,
188188
pub text_document: Option<TextDocumentIdentifier>,

crates/rust-analyzer/src/lsp/to_proto.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1506,10 +1506,10 @@ pub(crate) fn test_item(
15061506
lsp_ext::TestItem {
15071507
id: test_item.id,
15081508
label: test_item.label,
1509-
icon: match test_item.kind {
1510-
ide::TestItemKind::Crate => lsp_ext::TestItemIcon::Package,
1511-
ide::TestItemKind::Module => lsp_ext::TestItemIcon::Module,
1512-
ide::TestItemKind::Function => lsp_ext::TestItemIcon::Test,
1509+
kind: match test_item.kind {
1510+
ide::TestItemKind::Crate => lsp_ext::TestItemKind::Package,
1511+
ide::TestItemKind::Module => lsp_ext::TestItemKind::Module,
1512+
ide::TestItemKind::Function => lsp_ext::TestItemKind::Test,
15131513
},
15141514
can_resolve_children: matches!(
15151515
test_item.kind,

crates/rust-analyzer/src/main_loop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ impl GlobalState {
779779
flycheck::CargoTestMessage::Test { name, state } => {
780780
let state = match state {
781781
flycheck::TestState::Started => lsp_ext::TestState::Started,
782+
flycheck::TestState::Ignored => lsp_ext::TestState::Skipped,
782783
flycheck::TestState::Ok => lsp_ext::TestState::Passed,
783784
flycheck::TestState::Failed { stdout } => {
784785
lsp_ext::TestState::Failed { message: stdout }

docs/dev/lsp-extensions.md

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!---
2-
lsp/ext.rs hash: 4b06686d086b7d9b
2+
lsp/ext.rs hash: 6bc140531b403717
33
44
If you need to change the above hash to make the test pass, please check if you
55
need to adjust this doc as well and ping this issue:
@@ -416,7 +416,9 @@ interface TestItem {
416416
range?: lc.Range | undefined;
417417
// A human readable name for this test
418418
label: string;
419-
icon: "package" | "module" | "test";
419+
// The kind of this test item. Based on the kind,
420+
// an icon is chosen by the editor.
421+
kind: "package" | "module" | "test";
420422
// True if this test may have children not available eagerly
421423
canResolveChildren: boolean;
422424
// The id of the parent test in the test tree. If not present, this test
@@ -425,6 +427,10 @@ interface TestItem {
425427
// The information useful for running the test. The client can use `runTest`
426428
// request for simple execution, but for more complex execution forms
427429
// like debugging, this field is useful.
430+
// Note that this field includes some information about label and location as well, but
431+
// those exist just for keeping things in sync with other methods of running runnables
432+
// (for example using one consistent name in the vscode's launch.json) so for any propose
433+
// other than running tests this field should not be used.
428434
runnable?: Runnable | undefined;
429435
};
430436

@@ -451,8 +457,14 @@ the same as the one in `experimental/discoverTest` response.
451457
**Request:** `RunTestParams`
452458

453459
```typescript
454-
interface DiscoverTestParams {
460+
interface RunTestParams {
461+
// Id of the tests to be run. If a test is included, all of its children are included implicitly. If
462+
// this property is undefined, then the server should simply run all tests.
455463
include?: string[] | undefined;
464+
// An array of test ids the user has marked as excluded from the test included in this run; exclusions
465+
// should apply after inclusions.
466+
// May be omitted if no exclusions were requested. Server should not run excluded tests or
467+
// any children of excluded tests.
456468
exclude?: string[] | undefined;
457469
}
458470
```
@@ -480,9 +492,16 @@ a `experimental/endRunTest` when is done.
480492
**Notification:** `ChangeTestStateParams`
481493

482494
```typescript
483-
type TestState = { tag: "failed"; message: string }
484-
| { tag: "passed" }
485-
| { tag: "started" };
495+
type TestState = { tag: "passed" }
496+
| {
497+
tag: "failed";
498+
// The standard error of the test, containing the panic message. Clients should
499+
// render it similar to a terminal, and e.g. handle ansi colors.
500+
message: string;
501+
}
502+
| { tag: "started" }
503+
| { tag: "enqueued" }
504+
| { tag: "skipped" };
486505

487506
interface ChangeTestStateParams {
488507
testId: string;

editors/code/src/lsp_ext.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@ export type RunTestParams = {
7676
export type TestItem = {
7777
id: string;
7878
label: string;
79-
icon: "package" | "module" | "test";
79+
kind: "package" | "module" | "test";
8080
canResolveChildren: boolean;
8181
parent?: string | undefined;
8282
textDocument?: lc.TextDocumentIdentifier | undefined;
8383
range?: lc.Range | undefined;
8484
runnable?: Runnable | undefined;
8585
};
8686
export type DiscoverTestResults = { tests: TestItem[]; scope: string[] };
87-
export type TestState = { tag: "failed"; message: string } | { tag: "passed" } | { tag: "started" };
87+
export type TestState =
88+
| { tag: "failed"; message: string }
89+
| { tag: "passed" }
90+
| { tag: "started" }
91+
| { tag: "enqueued" }
92+
| { tag: "skipped" };
8893
export type ChangeTestStateParams = { testId: string; state: TestState };
8994
export const discoverTest = new lc.RequestType<DiscoverTestParams, DiscoverTestResults, void>(
9095
"experimental/discoverTest",

editors/code/src/test_explorer.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const prepareTestExplorer = (
8585
};
8686
const test = testController.createTestItem(
8787
item.id,
88-
`$(${iconToVscodeMap[item.icon]}) ${item.label}`,
88+
`$(${iconToVscodeMap[item.kind]}) ${item.label}`,
8989
uri,
9090
);
9191
test.range = range;
@@ -150,6 +150,10 @@ export const prepareTestExplorer = (
150150
currentTestRun!.passed(test);
151151
} else if (results.state.tag === "started") {
152152
currentTestRun!.started(test);
153+
} else if (results.state.tag === "skipped") {
154+
currentTestRun!.skipped(test);
155+
} else if (results.state.tag === "enqueued") {
156+
currentTestRun!.enqueued(test);
153157
}
154158
}),
155159
);

0 commit comments

Comments
 (0)