Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor changes in the test explorer lsp extension #16794

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/flycheck/src/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::command::{CommandHandle, ParseFromLine};
pub enum TestState {
Started,
Ok,
Ignored,
Failed { stdout: String },
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rust-analyzer/src/lsp/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub struct DiscoverTestParams {

#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub enum TestItemIcon {
pub enum TestItemKind {
Package,
Module,
Test,
Expand All @@ -182,7 +182,7 @@ pub enum TestItemIcon {
pub struct TestItem {
pub id: String,
pub label: String,
pub icon: TestItemIcon,
pub kind: TestItemKind,
pub can_resolve_children: bool,
pub parent: Option<String>,
pub text_document: Option<TextDocumentIdentifier>,
Expand Down
8 changes: 4 additions & 4 deletions crates/rust-analyzer/src/lsp/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1506,10 +1506,10 @@ pub(crate) fn test_item(
lsp_ext::TestItem {
id: test_item.id,
label: test_item.label,
icon: match test_item.kind {
ide::TestItemKind::Crate => lsp_ext::TestItemIcon::Package,
ide::TestItemKind::Module => lsp_ext::TestItemIcon::Module,
ide::TestItemKind::Function => lsp_ext::TestItemIcon::Test,
kind: match test_item.kind {
ide::TestItemKind::Crate => lsp_ext::TestItemKind::Package,
ide::TestItemKind::Module => lsp_ext::TestItemKind::Module,
ide::TestItemKind::Function => lsp_ext::TestItemKind::Test,
},
can_resolve_children: matches!(
test_item.kind,
Expand Down
1 change: 1 addition & 0 deletions crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ impl GlobalState {
flycheck::CargoTestMessage::Test { name, state } => {
let state = match state {
flycheck::TestState::Started => lsp_ext::TestState::Started,
flycheck::TestState::Ignored => lsp_ext::TestState::Skipped,
flycheck::TestState::Ok => lsp_ext::TestState::Passed,
flycheck::TestState::Failed { stdout } => {
lsp_ext::TestState::Failed { message: stdout }
Expand Down
31 changes: 25 additions & 6 deletions docs/dev/lsp-extensions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!---
lsp/ext.rs hash: 4b06686d086b7d9b
lsp/ext.rs hash: 6bc140531b403717

If you need to change the above hash to make the test pass, please check if you
need to adjust this doc as well and ping this issue:
Expand Down Expand Up @@ -416,7 +416,9 @@ interface TestItem {
range?: lc.Range | undefined;
// A human readable name for this test
label: string;
icon: "package" | "module" | "test";
// The kind of this test item. Based on the kind,
// an icon is chosen by the editor.
kind: "package" | "module" | "test";
// True if this test may have children not available eagerly
canResolveChildren: boolean;
// The id of the parent test in the test tree. If not present, this test
Expand All @@ -425,6 +427,10 @@ interface TestItem {
// The information useful for running the test. The client can use `runTest`
// request for simple execution, but for more complex execution forms
// like debugging, this field is useful.
// Note that this field includes some information about label and location as well, but
// those exist just for keeping things in sync with other methods of running runnables
// (for example using one consistent name in the vscode's launch.json) so for any propose
// other than running tests this field should not be used.
runnable?: Runnable | undefined;
};

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

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

```typescript
type TestState = { tag: "failed"; message: string }
| { tag: "passed" }
| { tag: "started" };
type TestState = { tag: "passed" }
| {
tag: "failed";
// The standard error of the test, containing the panic message. Clients should
// render it similar to a terminal, and e.g. handle ansi colors.
message: string;
}
| { tag: "started" }
| { tag: "enqueued" }
| { tag: "skipped" };

interface ChangeTestStateParams {
testId: string;
Expand Down
9 changes: 7 additions & 2 deletions editors/code/src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,20 @@ export type RunTestParams = {
export type TestItem = {
id: string;
label: string;
icon: "package" | "module" | "test";
kind: "package" | "module" | "test";
canResolveChildren: boolean;
parent?: string | undefined;
textDocument?: lc.TextDocumentIdentifier | undefined;
range?: lc.Range | undefined;
runnable?: Runnable | undefined;
};
export type DiscoverTestResults = { tests: TestItem[]; scope: string[] };
export type TestState = { tag: "failed"; message: string } | { tag: "passed" } | { tag: "started" };
export type TestState =
| { tag: "failed"; message: string }
| { tag: "passed" }
| { tag: "started" }
| { tag: "enqueued" }
| { tag: "skipped" };
export type ChangeTestStateParams = { testId: string; state: TestState };
export const discoverTest = new lc.RequestType<DiscoverTestParams, DiscoverTestResults, void>(
"experimental/discoverTest",
Expand Down
6 changes: 5 additions & 1 deletion editors/code/src/test_explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const prepareTestExplorer = (
};
const test = testController.createTestItem(
item.id,
`$(${iconToVscodeMap[item.icon]}) ${item.label}`,
`$(${iconToVscodeMap[item.kind]}) ${item.label}`,
uri,
);
test.range = range;
Expand Down Expand Up @@ -150,6 +150,10 @@ export const prepareTestExplorer = (
currentTestRun!.passed(test);
} else if (results.state.tag === "started") {
currentTestRun!.started(test);
} else if (results.state.tag === "skipped") {
currentTestRun!.skipped(test);
} else if (results.state.tag === "enqueued") {
currentTestRun!.enqueued(test);
}
}),
);
Expand Down
Loading