Some minor changes in the test explorer lsp extension

This commit is contained in:
hkalbasi 2024-03-09 01:20:43 +03:30
parent ce15e73a8e
commit dc99ad912a
7 changed files with 45 additions and 15 deletions

View file

@ -14,6 +14,7 @@ use crate::command::{CommandHandle, ParseFromLine};
pub enum TestState {
Started,
Ok,
Ignored,
Failed { stdout: String },
}

View file

@ -171,7 +171,7 @@ pub struct DiscoverTestParams {
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub enum TestItemIcon {
pub enum TestItemKind {
Package,
Module,
Test,
@ -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>,

View file

@ -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,

View file

@ -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 }

View file

@ -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:
@ -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
@ -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;
};
@ -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;
}
```
@ -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;

View file

@ -76,7 +76,7 @@ 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;
@ -84,7 +84,12 @@ export type TestItem = {
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",

View file

@ -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;
@ -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);
}
}),
);