From d28384c3deec1497d28f0f6bd16cf51de832e572 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 30 Aug 2023 16:31:31 +0100 Subject: 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, } pub struct TestDefinitions { pub discovered: Vec, pub injected: Vec, pub script_version: String, } ``` Now: ```rust pub struct TestDefinition { pub id: String, pub name: String, pub range: Option, pub is_dynamic: bool, // True for 'injected' module, not statically detected but added at runtime. pub parent_id: Option, pub step_ids: HashSet, } pub struct TestModule { pub specifier: ModuleSpecifier, pub script_version: String, pub defs: HashMap, } ``` 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. --- cli/tools/test/mod.rs | 7 ------- 1 file changed, 7 deletions(-) (limited to 'cli/tools/test') diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index 2a0938e96..296d306e2 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -15,7 +15,6 @@ use crate::graph_util::graph_valid_with_cli_options; use crate::graph_util::has_graph_root_local_dependent_changed; use crate::module_loader::ModuleLoadPreparer; use crate::ops; -use crate::util::checksum; use crate::util::file_watcher; use crate::util::fs::collect_specifiers; use crate::util::path::get_extension; @@ -174,12 +173,6 @@ pub struct TestDescription { pub location: TestLocation, } -impl TestDescription { - pub fn static_id(&self) -> String { - checksum::gen(&[self.location.file_name.as_bytes(), self.name.as_bytes()]) - } -} - #[derive(Debug, Clone, Eq, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] pub enum TestOutput { -- cgit v1.2.3