feat(adapter): use new interface of detect-workspace

This commit is contained in:
kbwo 2024-12-07 23:04:55 +09:00
parent df0631a6d6
commit 787e92fe87
8 changed files with 49 additions and 34 deletions

View file

@ -7,7 +7,7 @@ use testing_language_server::spec::DetectWorkspaceResult;
use testing_language_server::spec::RunFileTestResult;
use testing_language_server::spec::DiscoverResult;
use testing_language_server::spec::DiscoverResultItem;
use testing_language_server::spec::FoundFileTests;
use testing_language_server::spec::TestItem;
use crate::model::Runner;
@ -18,7 +18,9 @@ use super::util::parse_cargo_diagnostics;
use super::util::write_result_log;
fn detect_workspaces(file_paths: &[String]) -> DetectWorkspaceResult {
detect_workspaces_from_file_list(file_paths, &["Cargo.toml".to_string()])
DetectWorkspaceResult {
data: detect_workspaces_from_file_list(file_paths, &["Cargo.toml".to_string()]),
}
}
#[derive(Eq, PartialEq, Hash, Debug)]
@ -32,7 +34,7 @@ impl Runner for CargoNextestRunner {
for file_path in file_paths {
let tests = discover_rust_tests(&file_path)?;
discover_results.data.push(DiscoverResultItem {
discover_results.data.push(FoundFileTests {
tests,
path: file_path,
});
@ -214,8 +216,10 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
.collect();
let workspaces = detect_workspaces(&file_paths);
assert_eq!(workspaces.len(), 2);
assert!(workspaces.contains_key(absolute_path_of_demo.to_str().unwrap()));
assert!(workspaces.contains_key(current_dir.to_str().unwrap()));
assert_eq!(workspaces.data.len(), 2);
assert!(workspaces
.data
.contains_key(absolute_path_of_demo.to_str().unwrap()));
assert!(workspaces.data.contains_key(current_dir.to_str().unwrap()));
}
}

View file

@ -7,7 +7,7 @@ use testing_language_server::spec::DetectWorkspaceResult;
use testing_language_server::spec::RunFileTestResult;
use testing_language_server::spec::DiscoverResult;
use testing_language_server::spec::DiscoverResultItem;
use testing_language_server::spec::FoundFileTests;
use testing_language_server::spec::TestItem;
use crate::model::Runner;
@ -18,7 +18,9 @@ use super::util::parse_cargo_diagnostics;
use super::util::write_result_log;
fn detect_workspaces(file_paths: &[String]) -> DetectWorkspaceResult {
detect_workspaces_from_file_list(file_paths, &["Cargo.toml".to_string()])
DetectWorkspaceResult {
data: detect_workspaces_from_file_list(file_paths, &["Cargo.toml".to_string()]),
}
}
#[derive(Eq, PartialEq, Hash, Debug)]
@ -32,7 +34,7 @@ impl Runner for CargoTestRunner {
for file_path in file_paths {
let tests = discover_rust_tests(&file_path)?;
discover_results.data.push(DiscoverResultItem {
discover_results.data.push(FoundFileTests {
tests,
path: file_path,
});
@ -209,8 +211,10 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
.collect();
let workspaces = detect_workspaces(&file_paths);
assert_eq!(workspaces.len(), 2);
assert!(workspaces.contains_key(absolute_path_of_demo.to_str().unwrap()));
assert!(workspaces.contains_key(current_dir.to_str().unwrap()));
assert_eq!(workspaces.data.len(), 2);
assert!(workspaces
.data
.contains_key(absolute_path_of_demo.to_str().unwrap()));
assert!(workspaces.data.contains_key(current_dir.to_str().unwrap()));
}
}

View file

@ -13,8 +13,8 @@ use testing_language_server::error::LSError;
use testing_language_server::spec::DetectWorkspaceResult;
use testing_language_server::spec::DiscoverResult;
use testing_language_server::spec::DiscoverResultItem;
use testing_language_server::spec::FileDiagnostics;
use testing_language_server::spec::FoundFileTests;
use testing_language_server::spec::RunFileTestResult;
use testing_language_server::spec::TestItem;
@ -99,7 +99,9 @@ fn parse_diagnostics(
}
fn detect_workspaces(file_paths: Vec<String>) -> DetectWorkspaceResult {
detect_workspaces_from_file_list(&file_paths, &["deno.json".to_string()])
DetectWorkspaceResult {
data: detect_workspaces_from_file_list(&file_paths, &["deno.json".to_string()]),
}
}
fn discover(file_path: &str) -> Result<Vec<TestItem>, LSError> {
@ -166,7 +168,7 @@ impl Runner for DenoRunner {
let file_paths = args.file_paths;
let mut discover_results: DiscoverResult = DiscoverResult { data: vec![] };
for file_path in file_paths {
discover_results.data.push(DiscoverResultItem {
discover_results.data.push(FoundFileTests {
tests: discover(&file_path)?,
path: file_path,
})
@ -245,8 +247,8 @@ mod tests {
.map(|file_path| file_path.to_str().unwrap().to_string())
.collect();
let detect_result = detect_workspaces(file_paths);
assert_eq!(detect_result.len(), 1);
detect_result.iter().for_each(|(workspace, _)| {
assert_eq!(detect_result.data.len(), 1);
detect_result.data.iter().for_each(|(workspace, _)| {
assert_eq!(workspace, absolute_path_of_demo.to_str().unwrap());
});
}

View file

@ -13,8 +13,8 @@ use std::process::Output;
use std::str::FromStr;
use testing_language_server::error::LSError;
use testing_language_server::spec::DiscoverResult;
use testing_language_server::spec::DiscoverResultItem;
use testing_language_server::spec::FileDiagnostics;
use testing_language_server::spec::FoundFileTests;
use testing_language_server::spec::RunFileTestResult;
use testing_language_server::spec::TestItem;
@ -239,7 +239,7 @@ impl Runner for GoTestRunner {
for file_path in file_paths {
let tests = discover(&file_path)?;
discover_results.data.push(DiscoverResultItem {
discover_results.data.push(FoundFileTests {
tests,
path: file_path,
});

View file

@ -8,8 +8,8 @@ use testing_language_server::error::LSError;
use testing_language_server::spec::DetectWorkspaceResult;
use testing_language_server::spec::DiscoverResult;
use testing_language_server::spec::DiscoverResultItem;
use testing_language_server::spec::FileDiagnostics;
use testing_language_server::spec::FoundFileTests;
use testing_language_server::spec::RunFileTestResult;
use testing_language_server::spec::TestItem;
@ -77,7 +77,9 @@ fn parse_diagnostics(
}
fn detect_workspaces(file_paths: Vec<String>) -> DetectWorkspaceResult {
detect_workspaces_from_file_list(&file_paths, &["package.json".to_string()])
DetectWorkspaceResult {
data: detect_workspaces_from_file_list(&file_paths, &["package.json".to_string()]),
}
}
fn discover(file_path: &str) -> Result<Vec<TestItem>, LSError> {
@ -164,7 +166,7 @@ impl Runner for JestRunner {
let file_paths = args.file_paths;
let mut discover_results: DiscoverResult = DiscoverResult { data: vec![] };
for file_path in file_paths {
discover_results.data.push(DiscoverResultItem {
discover_results.data.push(FoundFileTests {
tests: discover(&file_path)?,
path: file_path,
})
@ -245,8 +247,8 @@ mod tests {
.map(|file_path| file_path.to_str().unwrap().to_string())
.collect();
let detect_result = detect_workspaces(file_paths);
assert_eq!(detect_result.len(), 1);
detect_result.iter().for_each(|(workspace, _)| {
assert_eq!(detect_result.data.len(), 1);
detect_result.data.iter().for_each(|(workspace, _)| {
assert_eq!(workspace, absolute_path_of_demo.to_str().unwrap());
});
}

View file

@ -4,8 +4,8 @@ use regex::Regex;
use testing_language_server::{
error::LSError,
spec::{
DetectWorkspaceResult, DiscoverResult, DiscoverResultItem, FileDiagnostics,
RunFileTestResult, TestItem,
DetectWorkspaceResult, DiscoverResult, FileDiagnostics, FoundFileTests, RunFileTestResult,
TestItem,
},
};
use xml::{reader::XmlEvent, ParserConfig};
@ -164,7 +164,7 @@ impl Runner for NodeTestRunner {
let file_paths = args.file_paths;
let mut discover_results: DiscoverResult = DiscoverResult { data: vec![] };
for file_path in file_paths {
discover_results.data.push(DiscoverResultItem {
discover_results.data.push(FoundFileTests {
tests: discover(&file_path)?,
path: file_path,
})
@ -215,8 +215,9 @@ impl Runner for NodeTestRunner {
args: testing_language_server::spec::DetectWorkspaceArgs,
) -> Result<(), LSError> {
let file_paths = args.file_paths;
let detect_result: DetectWorkspaceResult =
detect_workspaces_from_file_list(&file_paths, &["package.json".to_string()]);
let detect_result: DetectWorkspaceResult = DetectWorkspaceResult {
data: detect_workspaces_from_file_list(&file_paths, &["package.json".to_string()]),
};
send_stdout(&detect_result)?;
Ok(())
}

View file

@ -3,7 +3,7 @@ use std::io::BufReader;
use std::process::Output;
use testing_language_server::error::LSError;
use testing_language_server::spec::{
DetectWorkspaceResult, DiscoverResult, DiscoverResultItem, FileDiagnostics, RunFileTestResult,
DetectWorkspaceResult, DiscoverResult, FileDiagnostics, FoundFileTests, RunFileTestResult,
TestItem,
};
use xml::reader::{ParserConfig, XmlEvent};
@ -16,7 +16,9 @@ use super::util::{
};
fn detect_workspaces(file_paths: Vec<String>) -> DetectWorkspaceResult {
detect_workspaces_from_file_list(&file_paths, &["composer.json".to_string()])
DetectWorkspaceResult {
data: detect_workspaces_from_file_list(&file_paths, &["composer.json".to_string()]),
}
}
fn get_result_from_characters(characters: &str) -> Result<ResultFromXml, anyhow::Error> {
@ -127,7 +129,7 @@ impl Runner for PhpunitRunner {
let file_paths = args.file_paths;
let mut discover_results: DiscoverResult = DiscoverResult { data: vec![] };
for file_path in file_paths {
discover_results.data.push(DiscoverResultItem {
discover_results.data.push(FoundFileTests {
tests: discover(&file_path)?,
path: file_path,
})

View file

@ -7,7 +7,7 @@ use lsp_types::{Diagnostic, DiagnosticSeverity};
use serde_json::Value;
use testing_language_server::{
error::LSError,
spec::{DiscoverResult, DiscoverResultItem, FileDiagnostics, RunFileTestResult, TestItem},
spec::{DiscoverResult, FileDiagnostics, FoundFileTests, RunFileTestResult, TestItem},
};
use crate::model::Runner;
@ -139,7 +139,7 @@ impl Runner for VitestRunner {
for file_path in file_paths {
let tests = discover(&file_path)?;
discover_results.data.push(DiscoverResultItem {
discover_results.data.push(FoundFileTests {
tests,
path: file_path,
});