From 96855b782c46993407cf3e0fb79addfe319f866a Mon Sep 17 00:00:00 2001 From: kbwo Date: Sat, 12 Oct 2024 17:17:15 +0900 Subject: [PATCH] chore: change adapter config specification simplify key names --- .vim/coc-settings.json | 4 +- Cargo.lock | 153 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + demo/.vim/coc-settings.json | 31 ++++---- src/server.rs | 32 +++----- src/spec.rs | 6 +- 6 files changed, 186 insertions(+), 41 deletions(-) diff --git a/.vim/coc-settings.json b/.vim/coc-settings.json index 1312f7e..910953d 100644 --- a/.vim/coc-settings.json +++ b/.vim/coc-settings.json @@ -6,8 +6,8 @@ { "path": "testing-ls-adapter", "extra_args": ["--test-kind=cargo-test", "--workspace"], - "include_patterns": ["/**/*.rs"], - "exclude_patterns": ["/demo/**/*"], + "include": ["/**/*.rs"], + "exclude": ["/demo/**/*"], "workspace_dir": "." } ] diff --git a/Cargo.lock b/Cargo.lock index bfc5b16..5711706 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.13" @@ -65,6 +80,12 @@ version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + [[package]] name = "bitflags" version = "1.3.2" @@ -87,6 +108,12 @@ dependencies = [ "serde", ] +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + [[package]] name = "cc" version = "1.0.106" @@ -99,6 +126,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.5", +] + [[package]] name = "clap" version = "4.5.4" @@ -145,6 +186,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + [[package]] name = "crossbeam-channel" version = "0.5.12" @@ -287,6 +334,29 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "iana-time-zone" +version = "0.1.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -319,6 +389,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -378,6 +457,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -630,6 +718,7 @@ name = "testing-language-server" version = "0.0.10" dependencies = [ "anyhow", + "chrono", "clap", "dirs", "glob", @@ -906,6 +995,61 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" + [[package]] name = "winapi-util" version = "0.1.8" @@ -915,6 +1059,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index e431c91..4fdf840 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,3 +47,4 @@ strum = { workspace = true, features = ["derive"] } glob = { workspace = true } globwalk = "0.9.1" tree-sitter-php = "0.22.8" +chrono = "0.4.38" diff --git a/demo/.vim/coc-settings.json b/demo/.vim/coc-settings.json index 4a72552..a332b62 100644 --- a/demo/.vim/coc-settings.json +++ b/demo/.vim/coc-settings.json @@ -10,59 +10,56 @@ { "path": "testing-ls-adapter", "extra_args": ["--test-kind=cargo-test"], - "include_patterns": ["/**/src/**/*.rs"], - "exclude_patterns": ["/**/target/**"] + "include": ["/**/src/**/*.rs"], + "exclude": ["/**/target/**"] } ], "cargo-nextest": [ { "path": "testing-ls-adapter", "extra_args": ["--test-kind=cargo-nextest"], - "include_patterns": ["/**/src/**/*.rs"], - "exclude_patterns": ["/**/target/**"] + "include": ["/**/src/**/*.rs"], + "exclude": ["/**/target/**"] } ], "jest": [ { "path": "testing-ls-adapter", "extra_args": ["--test-kind=jest"], - "include_patterns": ["/jest/*.js"], - "exclude_patterns": ["/jest/**/node_modules/**/*"] + "include": ["/jest/*.js"], + "exclude": ["/jest/**/node_modules/**/*"] } ], "vitest": [ { "path": "testing-ls-adapter", "extra_args": ["--test-kind=vitest"], - "include_patterns": [ - "/vitest/*.test.ts", - "/vitest/config/**/*.test.ts" - ], - "exclude_patterns": ["/vitest/**/node_modules/**/*"] + "include": ["/vitest/*.test.ts", "/vitest/config/**/*.test.ts"], + "exclude": ["/vitest/**/node_modules/**/*"] } ], "deno": [ { "path": "testing-ls-adapter", "extra_args": ["--test-kind=deno"], - "include_patterns": ["/deno/*.ts"], - "exclude_patterns": [] + "include": ["/deno/*.ts"], + "exclude": [] } ], "go": [ { "path": "testing-ls-adapter", "extra_args": ["--test-kind=go-test"], - "include_patterns": ["/**/*.go"], - "exclude_patterns": [] + "include": ["/**/*.go"], + "exclude": [] } ], "phpunit": [ { "path": "testing-ls-adapter", "extra_args": ["--test-kind=phpunit"], - "include_patterns": ["/**/*Test.php"], - "exclude_patterns": ["/phpunit/vendor/**/*.php"] + "include": ["/**/*Test.php"], + "exclude": ["/phpunit/vendor/**/*.php"] } ] } diff --git a/src/server.rs b/src/server.rs index 11faf84..c982f86 100644 --- a/src/server.rs +++ b/src/server.rs @@ -91,21 +91,17 @@ impl TestingLS { self.options.adapter_command.clone() } - fn project_files( - base_dir: &Path, - include_patterns: &[String], - exclude_patterns: &[String], - ) -> Vec { + fn project_files(base_dir: &Path, include: &[String], exclude: &[String]) -> Vec { let mut result: Vec = vec![]; - let exclude_pattern = exclude_patterns + let exclude_pattern = exclude .iter() .filter_map(|exclude_pattern| { Pattern::new(base_dir.join(exclude_pattern).to_str().unwrap()).ok() }) .collect::>(); let base_dir = base_dir.to_str().unwrap(); - let entries = globwalk::GlobWalkerBuilder::from_patterns(base_dir, include_patterns) + let entries = globwalk::GlobWalkerBuilder::from_patterns(base_dir, include) .follow_links(true) .build() .unwrap() @@ -159,14 +155,13 @@ impl TestingLS { let AdapterConfiguration { path, extra_args, - envs, - include_patterns, - exclude_patterns, + env, + include, + exclude, workspace_dir, .. } = &adapter; - let file_paths = - Self::project_files(&project_dir, include_patterns, exclude_patterns); + let file_paths = Self::project_files(&project_dir, include, exclude); if file_paths.is_empty() { continue; } @@ -181,7 +176,7 @@ impl TestingLS { .args(args_file_path) .arg("--") .args(extra_args) - .envs(envs) + .envs(env) .output() .map_err(|err| LSError::Adapter(err.to_string()))?; let adapter_result = String::from_utf8(output.stdout) @@ -241,8 +236,8 @@ impl TestingLS { let base_dir = self.project_dir(); match base_dir { Ok(base_dir) => self.workspaces_cache.iter().any(|cache| { - let include_patterns = &cache.adapter_config.include_patterns; - let exclude_patterns = &cache.adapter_config.exclude_patterns; + let include = &cache.adapter_config.include; + let exclude = &cache.adapter_config.exclude; if cache .workspaces .iter() @@ -251,8 +246,7 @@ impl TestingLS { return false; } - Self::project_files(&base_dir, include_patterns, exclude_patterns) - .contains(&path.to_owned()) + Self::project_files(&base_dir, include, exclude).contains(&path.to_owned()) }), Err(e) => { tracing::error!("Error: {:?}", e); @@ -305,7 +299,7 @@ impl TestingLS { .args(args) .arg("--") .args(&adapter.extra_args) - .envs(&adapter.envs) + .envs(&adapter.env) .output() .map_err(|err| LSError::Adapter(err.to_string()))?; let Output { stdout, stderr, .. } = output; @@ -450,7 +444,7 @@ impl TestingLS { .args(args) .arg("--") .args(&adapter.extra_args) - .envs(&adapter.envs) + .envs(&adapter.env) .output() .map_err(|err| LSError::Adapter(err.to_string()))?; diff --git a/src/spec.rs b/src/spec.rs index d159e4a..f342380 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -71,9 +71,9 @@ pub struct AdapterConfiguration { #[serde(default)] pub extra_args: Vec, #[serde(default)] - pub envs: HashMap, - pub include_patterns: Vec, - pub exclude_patterns: Vec, + pub env: HashMap, + pub include: Vec, + pub exclude: Vec, pub workspace_dir: Option, }