2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-03-29 18:59:27 -04:00
|
|
|
|
|
|
|
use super::collectors::TestCollector;
|
refactor(lsp): store test definitions in adjacency list (#20330)
Previously:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: SourceRange,
pub steps: Vec<TestDefinition>,
}
pub struct TestDefinitions {
pub discovered: Vec<TestDefinition>,
pub injected: Vec<lsp_custom::TestData>,
pub script_version: String,
}
```
Now:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: Option<Range>,
pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime.
pub parent_id: Option<String>,
pub step_ids: HashSet<String>,
}
pub struct TestModule {
pub specifier: ModuleSpecifier,
pub script_version: String,
pub defs: HashMap<String, TestDefinition>,
}
```
Storing the test tree as a literal tree diminishes the value of IDs,
even though vscode stores them that way. This makes all data easily
accessible from `TestModule`. It unifies the interface between
'discovered' and 'injected' tests. This unblocks some enhancements wrt
syncing tests between the LSP and extension, such as this TODO:
https://github.com/denoland/vscode_deno/blob/61f08d5a71536a0a5f7dce965955b09e6bd957e1/client/src/testing.ts#L251-L259
and https://github.com/denoland/vscode_deno/issues/900. We should also
get more flexibility overall.
`TestCollector` is cleaned up, now stores a `&mut TestModule` directly
and registers tests as it comes across them with
`TestModule::register()`. This method ensures sanity in the redundant
data from having both of `TestDefinition::{parent_id,step_ids}`.
All of the messy conversions between `TestDescription`,
`LspTestDescription`, `TestDefinition`, `TestData` and `TestIdentifier`
are cleaned up. They shouldn't have been using `impl From` and now the
full list of tests is available to their implementations.
2023-08-30 11:31:31 -04:00
|
|
|
use super::definitions::TestModule;
|
2022-03-29 18:59:27 -04:00
|
|
|
use super::execution::TestRun;
|
|
|
|
use super::lsp_custom;
|
|
|
|
|
|
|
|
use crate::lsp::client::Client;
|
|
|
|
use crate::lsp::client::TestingNotification;
|
|
|
|
use crate::lsp::config;
|
2023-03-29 16:25:48 -04:00
|
|
|
use crate::lsp::documents::DocumentsFilter;
|
2022-03-29 18:59:27 -04:00
|
|
|
use crate::lsp::language_server::StateSnapshot;
|
|
|
|
use crate::lsp::performance::Performance;
|
|
|
|
|
|
|
|
use deno_ast::swc::visit::VisitWith;
|
|
|
|
use deno_core::error::AnyError;
|
|
|
|
use deno_core::parking_lot::Mutex;
|
|
|
|
use deno_core::serde_json::json;
|
|
|
|
use deno_core::serde_json::Value;
|
|
|
|
use deno_core::ModuleSpecifier;
|
|
|
|
use deno_runtime::tokio_util::create_basic_runtime;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashSet;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::thread;
|
|
|
|
use tokio::sync::mpsc;
|
2022-04-03 00:17:30 -04:00
|
|
|
use tower_lsp::jsonrpc::Error as LspError;
|
|
|
|
use tower_lsp::jsonrpc::Result as LspResult;
|
|
|
|
use tower_lsp::lsp_types as lsp;
|
2022-03-29 18:59:27 -04:00
|
|
|
|
|
|
|
fn as_delete_notification(uri: ModuleSpecifier) -> TestingNotification {
|
|
|
|
TestingNotification::DeleteModule(
|
|
|
|
lsp_custom::TestModuleDeleteNotificationParams {
|
|
|
|
text_document: lsp::TextDocumentIdentifier { uri },
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The main structure which handles requests and sends notifications related
|
|
|
|
/// to the Testing API.
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct TestServer {
|
|
|
|
client: Client,
|
|
|
|
performance: Arc<Performance>,
|
|
|
|
/// A channel for handling run requests from the client
|
|
|
|
run_channel: mpsc::UnboundedSender<u32>,
|
|
|
|
/// A map of run ids to test runs
|
|
|
|
runs: Arc<Mutex<HashMap<u32, TestRun>>>,
|
|
|
|
/// Tests that are discovered from a versioned document
|
refactor(lsp): store test definitions in adjacency list (#20330)
Previously:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: SourceRange,
pub steps: Vec<TestDefinition>,
}
pub struct TestDefinitions {
pub discovered: Vec<TestDefinition>,
pub injected: Vec<lsp_custom::TestData>,
pub script_version: String,
}
```
Now:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: Option<Range>,
pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime.
pub parent_id: Option<String>,
pub step_ids: HashSet<String>,
}
pub struct TestModule {
pub specifier: ModuleSpecifier,
pub script_version: String,
pub defs: HashMap<String, TestDefinition>,
}
```
Storing the test tree as a literal tree diminishes the value of IDs,
even though vscode stores them that way. This makes all data easily
accessible from `TestModule`. It unifies the interface between
'discovered' and 'injected' tests. This unblocks some enhancements wrt
syncing tests between the LSP and extension, such as this TODO:
https://github.com/denoland/vscode_deno/blob/61f08d5a71536a0a5f7dce965955b09e6bd957e1/client/src/testing.ts#L251-L259
and https://github.com/denoland/vscode_deno/issues/900. We should also
get more flexibility overall.
`TestCollector` is cleaned up, now stores a `&mut TestModule` directly
and registers tests as it comes across them with
`TestModule::register()`. This method ensures sanity in the redundant
data from having both of `TestDefinition::{parent_id,step_ids}`.
All of the messy conversions between `TestDescription`,
`LspTestDescription`, `TestDefinition`, `TestData` and `TestIdentifier`
are cleaned up. They shouldn't have been using `impl From` and now the
full list of tests is available to their implementations.
2023-08-30 11:31:31 -04:00
|
|
|
tests: Arc<Mutex<HashMap<ModuleSpecifier, TestModule>>>,
|
2022-03-29 18:59:27 -04:00
|
|
|
/// A channel for requesting that changes to documents be statically analyzed
|
|
|
|
/// for tests
|
|
|
|
update_channel: mpsc::UnboundedSender<Arc<StateSnapshot>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestServer {
|
|
|
|
pub fn new(
|
|
|
|
client: Client,
|
|
|
|
performance: Arc<Performance>,
|
|
|
|
maybe_root_uri: Option<ModuleSpecifier>,
|
|
|
|
) -> Self {
|
refactor(lsp): store test definitions in adjacency list (#20330)
Previously:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: SourceRange,
pub steps: Vec<TestDefinition>,
}
pub struct TestDefinitions {
pub discovered: Vec<TestDefinition>,
pub injected: Vec<lsp_custom::TestData>,
pub script_version: String,
}
```
Now:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: Option<Range>,
pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime.
pub parent_id: Option<String>,
pub step_ids: HashSet<String>,
}
pub struct TestModule {
pub specifier: ModuleSpecifier,
pub script_version: String,
pub defs: HashMap<String, TestDefinition>,
}
```
Storing the test tree as a literal tree diminishes the value of IDs,
even though vscode stores them that way. This makes all data easily
accessible from `TestModule`. It unifies the interface between
'discovered' and 'injected' tests. This unblocks some enhancements wrt
syncing tests between the LSP and extension, such as this TODO:
https://github.com/denoland/vscode_deno/blob/61f08d5a71536a0a5f7dce965955b09e6bd957e1/client/src/testing.ts#L251-L259
and https://github.com/denoland/vscode_deno/issues/900. We should also
get more flexibility overall.
`TestCollector` is cleaned up, now stores a `&mut TestModule` directly
and registers tests as it comes across them with
`TestModule::register()`. This method ensures sanity in the redundant
data from having both of `TestDefinition::{parent_id,step_ids}`.
All of the messy conversions between `TestDescription`,
`LspTestDescription`, `TestDefinition`, `TestData` and `TestIdentifier`
are cleaned up. They shouldn't have been using `impl From` and now the
full list of tests is available to their implementations.
2023-08-30 11:31:31 -04:00
|
|
|
let tests: Arc<Mutex<HashMap<ModuleSpecifier, TestModule>>> =
|
2022-03-29 18:59:27 -04:00
|
|
|
Arc::new(Mutex::new(HashMap::new()));
|
|
|
|
|
|
|
|
let (update_channel, mut update_rx) =
|
|
|
|
mpsc::unbounded_channel::<Arc<StateSnapshot>>();
|
|
|
|
let (run_channel, mut run_rx) = mpsc::unbounded_channel::<u32>();
|
|
|
|
|
|
|
|
let server = Self {
|
|
|
|
client,
|
|
|
|
performance,
|
|
|
|
run_channel,
|
|
|
|
runs: Default::default(),
|
|
|
|
tests,
|
|
|
|
update_channel,
|
|
|
|
};
|
|
|
|
|
|
|
|
let tests = server.tests.clone();
|
|
|
|
let client = server.client.clone();
|
|
|
|
let performance = server.performance.clone();
|
|
|
|
let mru = maybe_root_uri.clone();
|
|
|
|
let _update_join_handle = thread::spawn(move || {
|
|
|
|
let runtime = create_basic_runtime();
|
|
|
|
|
|
|
|
runtime.block_on(async {
|
|
|
|
loop {
|
|
|
|
match update_rx.recv().await {
|
|
|
|
None => break,
|
|
|
|
Some(snapshot) => {
|
2023-11-30 21:54:59 -05:00
|
|
|
let mark = performance.mark("lsp.testing_update");
|
2022-03-29 18:59:27 -04:00
|
|
|
let mut tests = tests.lock();
|
|
|
|
// we create a list of test modules we currently are tracking
|
|
|
|
// eliminating any we go over when iterating over the document
|
|
|
|
let mut keys: HashSet<ModuleSpecifier> =
|
|
|
|
tests.keys().cloned().collect();
|
2023-03-29 16:25:48 -04:00
|
|
|
for document in snapshot
|
|
|
|
.documents
|
|
|
|
.documents(DocumentsFilter::AllDiagnosable)
|
|
|
|
{
|
2022-03-29 18:59:27 -04:00
|
|
|
let specifier = document.specifier();
|
2023-09-09 14:37:01 -04:00
|
|
|
if !snapshot.config.specifier_enabled_for_test(specifier) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-03-29 18:59:27 -04:00
|
|
|
keys.remove(specifier);
|
|
|
|
let script_version = document.script_version();
|
|
|
|
let valid = if let Some(test) = tests.get(specifier) {
|
|
|
|
test.script_version == script_version
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
};
|
|
|
|
if !valid {
|
|
|
|
if let Some(Ok(parsed_source)) =
|
|
|
|
document.maybe_parsed_source()
|
|
|
|
{
|
refactor(lsp): store test definitions in adjacency list (#20330)
Previously:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: SourceRange,
pub steps: Vec<TestDefinition>,
}
pub struct TestDefinitions {
pub discovered: Vec<TestDefinition>,
pub injected: Vec<lsp_custom::TestData>,
pub script_version: String,
}
```
Now:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: Option<Range>,
pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime.
pub parent_id: Option<String>,
pub step_ids: HashSet<String>,
}
pub struct TestModule {
pub specifier: ModuleSpecifier,
pub script_version: String,
pub defs: HashMap<String, TestDefinition>,
}
```
Storing the test tree as a literal tree diminishes the value of IDs,
even though vscode stores them that way. This makes all data easily
accessible from `TestModule`. It unifies the interface between
'discovered' and 'injected' tests. This unblocks some enhancements wrt
syncing tests between the LSP and extension, such as this TODO:
https://github.com/denoland/vscode_deno/blob/61f08d5a71536a0a5f7dce965955b09e6bd957e1/client/src/testing.ts#L251-L259
and https://github.com/denoland/vscode_deno/issues/900. We should also
get more flexibility overall.
`TestCollector` is cleaned up, now stores a `&mut TestModule` directly
and registers tests as it comes across them with
`TestModule::register()`. This method ensures sanity in the redundant
data from having both of `TestDefinition::{parent_id,step_ids}`.
All of the messy conversions between `TestDescription`,
`LspTestDescription`, `TestDefinition`, `TestData` and `TestIdentifier`
are cleaned up. They shouldn't have been using `impl From` and now the
full list of tests is available to their implementations.
2023-08-30 11:31:31 -04:00
|
|
|
let was_empty = tests
|
|
|
|
.remove(specifier)
|
|
|
|
.map(|tm| tm.is_empty())
|
|
|
|
.unwrap_or(true);
|
2022-12-19 14:58:36 -05:00
|
|
|
let mut collector = TestCollector::new(
|
|
|
|
specifier.clone(),
|
refactor(lsp): store test definitions in adjacency list (#20330)
Previously:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: SourceRange,
pub steps: Vec<TestDefinition>,
}
pub struct TestDefinitions {
pub discovered: Vec<TestDefinition>,
pub injected: Vec<lsp_custom::TestData>,
pub script_version: String,
}
```
Now:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: Option<Range>,
pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime.
pub parent_id: Option<String>,
pub step_ids: HashSet<String>,
}
pub struct TestModule {
pub specifier: ModuleSpecifier,
pub script_version: String,
pub defs: HashMap<String, TestDefinition>,
}
```
Storing the test tree as a literal tree diminishes the value of IDs,
even though vscode stores them that way. This makes all data easily
accessible from `TestModule`. It unifies the interface between
'discovered' and 'injected' tests. This unblocks some enhancements wrt
syncing tests between the LSP and extension, such as this TODO:
https://github.com/denoland/vscode_deno/blob/61f08d5a71536a0a5f7dce965955b09e6bd957e1/client/src/testing.ts#L251-L259
and https://github.com/denoland/vscode_deno/issues/900. We should also
get more flexibility overall.
`TestCollector` is cleaned up, now stores a `&mut TestModule` directly
and registers tests as it comes across them with
`TestModule::register()`. This method ensures sanity in the redundant
data from having both of `TestDefinition::{parent_id,step_ids}`.
All of the messy conversions between `TestDescription`,
`LspTestDescription`, `TestDefinition`, `TestData` and `TestIdentifier`
are cleaned up. They shouldn't have been using `impl From` and now the
full list of tests is available to their implementations.
2023-08-30 11:31:31 -04:00
|
|
|
script_version,
|
2022-12-19 14:58:36 -05:00
|
|
|
parsed_source.text_info().clone(),
|
|
|
|
);
|
2022-03-29 18:59:27 -04:00
|
|
|
parsed_source.module().visit_with(&mut collector);
|
refactor(lsp): store test definitions in adjacency list (#20330)
Previously:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: SourceRange,
pub steps: Vec<TestDefinition>,
}
pub struct TestDefinitions {
pub discovered: Vec<TestDefinition>,
pub injected: Vec<lsp_custom::TestData>,
pub script_version: String,
}
```
Now:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: Option<Range>,
pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime.
pub parent_id: Option<String>,
pub step_ids: HashSet<String>,
}
pub struct TestModule {
pub specifier: ModuleSpecifier,
pub script_version: String,
pub defs: HashMap<String, TestDefinition>,
}
```
Storing the test tree as a literal tree diminishes the value of IDs,
even though vscode stores them that way. This makes all data easily
accessible from `TestModule`. It unifies the interface between
'discovered' and 'injected' tests. This unblocks some enhancements wrt
syncing tests between the LSP and extension, such as this TODO:
https://github.com/denoland/vscode_deno/blob/61f08d5a71536a0a5f7dce965955b09e6bd957e1/client/src/testing.ts#L251-L259
and https://github.com/denoland/vscode_deno/issues/900. We should also
get more flexibility overall.
`TestCollector` is cleaned up, now stores a `&mut TestModule` directly
and registers tests as it comes across them with
`TestModule::register()`. This method ensures sanity in the redundant
data from having both of `TestDefinition::{parent_id,step_ids}`.
All of the messy conversions between `TestDescription`,
`LspTestDescription`, `TestDefinition`, `TestData` and `TestIdentifier`
are cleaned up. They shouldn't have been using `impl From` and now the
full list of tests is available to their implementations.
2023-08-30 11:31:31 -04:00
|
|
|
let test_module = collector.take();
|
|
|
|
if !test_module.is_empty() {
|
2022-03-29 18:59:27 -04:00
|
|
|
client.send_test_notification(
|
refactor(lsp): store test definitions in adjacency list (#20330)
Previously:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: SourceRange,
pub steps: Vec<TestDefinition>,
}
pub struct TestDefinitions {
pub discovered: Vec<TestDefinition>,
pub injected: Vec<lsp_custom::TestData>,
pub script_version: String,
}
```
Now:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: Option<Range>,
pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime.
pub parent_id: Option<String>,
pub step_ids: HashSet<String>,
}
pub struct TestModule {
pub specifier: ModuleSpecifier,
pub script_version: String,
pub defs: HashMap<String, TestDefinition>,
}
```
Storing the test tree as a literal tree diminishes the value of IDs,
even though vscode stores them that way. This makes all data easily
accessible from `TestModule`. It unifies the interface between
'discovered' and 'injected' tests. This unblocks some enhancements wrt
syncing tests between the LSP and extension, such as this TODO:
https://github.com/denoland/vscode_deno/blob/61f08d5a71536a0a5f7dce965955b09e6bd957e1/client/src/testing.ts#L251-L259
and https://github.com/denoland/vscode_deno/issues/900. We should also
get more flexibility overall.
`TestCollector` is cleaned up, now stores a `&mut TestModule` directly
and registers tests as it comes across them with
`TestModule::register()`. This method ensures sanity in the redundant
data from having both of `TestDefinition::{parent_id,step_ids}`.
All of the messy conversions between `TestDescription`,
`LspTestDescription`, `TestDefinition`, `TestData` and `TestIdentifier`
are cleaned up. They shouldn't have been using `impl From` and now the
full list of tests is available to their implementations.
2023-08-30 11:31:31 -04:00
|
|
|
test_module.as_replace_notification(mru.as_ref()),
|
2022-03-29 18:59:27 -04:00
|
|
|
);
|
refactor(lsp): store test definitions in adjacency list (#20330)
Previously:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: SourceRange,
pub steps: Vec<TestDefinition>,
}
pub struct TestDefinitions {
pub discovered: Vec<TestDefinition>,
pub injected: Vec<lsp_custom::TestData>,
pub script_version: String,
}
```
Now:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: Option<Range>,
pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime.
pub parent_id: Option<String>,
pub step_ids: HashSet<String>,
}
pub struct TestModule {
pub specifier: ModuleSpecifier,
pub script_version: String,
pub defs: HashMap<String, TestDefinition>,
}
```
Storing the test tree as a literal tree diminishes the value of IDs,
even though vscode stores them that way. This makes all data easily
accessible from `TestModule`. It unifies the interface between
'discovered' and 'injected' tests. This unblocks some enhancements wrt
syncing tests between the LSP and extension, such as this TODO:
https://github.com/denoland/vscode_deno/blob/61f08d5a71536a0a5f7dce965955b09e6bd957e1/client/src/testing.ts#L251-L259
and https://github.com/denoland/vscode_deno/issues/900. We should also
get more flexibility overall.
`TestCollector` is cleaned up, now stores a `&mut TestModule` directly
and registers tests as it comes across them with
`TestModule::register()`. This method ensures sanity in the redundant
data from having both of `TestDefinition::{parent_id,step_ids}`.
All of the messy conversions between `TestDescription`,
`LspTestDescription`, `TestDefinition`, `TestData` and `TestIdentifier`
are cleaned up. They shouldn't have been using `impl From` and now the
full list of tests is available to their implementations.
2023-08-30 11:31:31 -04:00
|
|
|
} else if !was_empty {
|
2023-08-29 04:43:11 -04:00
|
|
|
client.send_test_notification(as_delete_notification(
|
|
|
|
specifier.clone(),
|
|
|
|
));
|
2022-03-29 18:59:27 -04:00
|
|
|
}
|
refactor(lsp): store test definitions in adjacency list (#20330)
Previously:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: SourceRange,
pub steps: Vec<TestDefinition>,
}
pub struct TestDefinitions {
pub discovered: Vec<TestDefinition>,
pub injected: Vec<lsp_custom::TestData>,
pub script_version: String,
}
```
Now:
```rust
pub struct TestDefinition {
pub id: String,
pub name: String,
pub range: Option<Range>,
pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime.
pub parent_id: Option<String>,
pub step_ids: HashSet<String>,
}
pub struct TestModule {
pub specifier: ModuleSpecifier,
pub script_version: String,
pub defs: HashMap<String, TestDefinition>,
}
```
Storing the test tree as a literal tree diminishes the value of IDs,
even though vscode stores them that way. This makes all data easily
accessible from `TestModule`. It unifies the interface between
'discovered' and 'injected' tests. This unblocks some enhancements wrt
syncing tests between the LSP and extension, such as this TODO:
https://github.com/denoland/vscode_deno/blob/61f08d5a71536a0a5f7dce965955b09e6bd957e1/client/src/testing.ts#L251-L259
and https://github.com/denoland/vscode_deno/issues/900. We should also
get more flexibility overall.
`TestCollector` is cleaned up, now stores a `&mut TestModule` directly
and registers tests as it comes across them with
`TestModule::register()`. This method ensures sanity in the redundant
data from having both of `TestDefinition::{parent_id,step_ids}`.
All of the messy conversions between `TestDescription`,
`LspTestDescription`, `TestDefinition`, `TestData` and `TestIdentifier`
are cleaned up. They shouldn't have been using `impl From` and now the
full list of tests is available to their implementations.
2023-08-30 11:31:31 -04:00
|
|
|
tests.insert(specifier.clone(), test_module);
|
2022-03-29 18:59:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for key in keys {
|
|
|
|
client.send_test_notification(as_delete_notification(key));
|
|
|
|
}
|
|
|
|
performance.measure(mark);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
let client = server.client.clone();
|
|
|
|
let runs = server.runs.clone();
|
|
|
|
let _run_join_handle = thread::spawn(move || {
|
|
|
|
let runtime = create_basic_runtime();
|
|
|
|
|
|
|
|
runtime.block_on(async {
|
|
|
|
loop {
|
|
|
|
match run_rx.recv().await {
|
|
|
|
None => break,
|
|
|
|
Some(id) => {
|
|
|
|
let maybe_run = {
|
|
|
|
let runs = runs.lock();
|
|
|
|
runs.get(&id).cloned()
|
|
|
|
};
|
|
|
|
if let Some(run) = maybe_run {
|
|
|
|
match run.exec(&client, maybe_root_uri.as_ref()).await {
|
|
|
|
Ok(_) => (),
|
|
|
|
Err(err) => {
|
2023-03-15 10:34:23 -04:00
|
|
|
client.show_message(lsp::MessageType::ERROR, err);
|
2022-03-29 18:59:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
client.send_test_notification(TestingNotification::Progress(
|
|
|
|
lsp_custom::TestRunProgressParams {
|
|
|
|
id,
|
|
|
|
message: lsp_custom::TestRunProgressMessage::End,
|
|
|
|
},
|
|
|
|
));
|
|
|
|
runs.lock().remove(&id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
server
|
|
|
|
}
|
|
|
|
|
|
|
|
fn enqueue_run(&self, id: u32) -> Result<(), AnyError> {
|
|
|
|
self.run_channel.send(id).map_err(|err| err.into())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A request from the client to cancel a test run.
|
|
|
|
pub fn run_cancel_request(
|
|
|
|
&self,
|
|
|
|
params: lsp_custom::TestRunCancelParams,
|
|
|
|
) -> LspResult<Option<Value>> {
|
|
|
|
if let Some(run) = self.runs.lock().get(¶ms.id) {
|
|
|
|
run.cancel();
|
|
|
|
Ok(Some(json!(true)))
|
|
|
|
} else {
|
|
|
|
Ok(Some(json!(false)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A request from the client to start a test run.
|
|
|
|
pub fn run_request(
|
|
|
|
&self,
|
|
|
|
params: lsp_custom::TestRunRequestParams,
|
|
|
|
workspace_settings: config::WorkspaceSettings,
|
|
|
|
) -> LspResult<Option<Value>> {
|
|
|
|
let test_run =
|
|
|
|
{ TestRun::new(¶ms, self.tests.clone(), workspace_settings) };
|
|
|
|
let enqueued = test_run.as_enqueued();
|
|
|
|
{
|
|
|
|
let mut runs = self.runs.lock();
|
|
|
|
runs.insert(params.id, test_run);
|
|
|
|
}
|
|
|
|
self.enqueue_run(params.id).map_err(|err| {
|
|
|
|
log::error!("cannot enqueue run: {}", err);
|
|
|
|
LspError::internal_error()
|
|
|
|
})?;
|
|
|
|
Ok(Some(json!({ "enqueued": enqueued })))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn update(
|
|
|
|
&self,
|
|
|
|
snapshot: Arc<StateSnapshot>,
|
|
|
|
) -> Result<(), AnyError> {
|
|
|
|
self.update_channel.send(snapshot).map_err(|err| err.into())
|
|
|
|
}
|
|
|
|
}
|