mirror of
https://github.com/kbwo/testing-language-server.git
synced 2025-08-03 15:18:16 +00:00
feat(adapter): use new interface of run-file-test
This commit is contained in:
parent
1fae0f701a
commit
2fa914973f
9 changed files with 112 additions and 78 deletions
|
@ -106,7 +106,7 @@ impl Runner for CargoNextestRunner {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use lsp_types::{Diagnostic, DiagnosticSeverity, Position, Range};
|
||||
use testing_language_server::spec::{RunFileTestResultItem, TestItem};
|
||||
use testing_language_server::spec::{FileDiagnostics, TestItem};
|
||||
|
||||
use crate::runner::util::MAX_CHAR_LENGTH;
|
||||
|
||||
|
@ -171,24 +171,27 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
|||
|
||||
assert_eq!(
|
||||
diagnostics,
|
||||
vec![RunFileTestResultItem {
|
||||
path: file_paths.first().unwrap().to_owned(),
|
||||
diagnostics: vec![Diagnostic {
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: 85,
|
||||
character: 63
|
||||
RunFileTestResult {
|
||||
data: vec![FileDiagnostics {
|
||||
path: file_paths.first().unwrap().to_owned(),
|
||||
diagnostics: vec![Diagnostic {
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: 85,
|
||||
character: 63
|
||||
},
|
||||
end: Position {
|
||||
line: 85,
|
||||
character: MAX_CHAR_LENGTH
|
||||
}
|
||||
},
|
||||
end: Position {
|
||||
line: 85,
|
||||
character: MAX_CHAR_LENGTH
|
||||
}
|
||||
},
|
||||
message: message.to_string(),
|
||||
severity: Some(DiagnosticSeverity::ERROR),
|
||||
..Diagnostic::default()
|
||||
}]
|
||||
}]
|
||||
message: message.to_string(),
|
||||
severity: Some(DiagnosticSeverity::ERROR),
|
||||
..Diagnostic::default()
|
||||
}]
|
||||
}],
|
||||
messages: vec!()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ impl Runner for CargoTestRunner {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use lsp_types::{Diagnostic, DiagnosticSeverity, Position, Range};
|
||||
use testing_language_server::spec::RunFileTestResultItem;
|
||||
use testing_language_server::spec::FileDiagnostics;
|
||||
|
||||
use crate::runner::util::MAX_CHAR_LENGTH;
|
||||
|
||||
|
@ -166,24 +166,27 @@ note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
|
|||
|
||||
assert_eq!(
|
||||
diagnostics,
|
||||
vec![RunFileTestResultItem {
|
||||
path: file_paths.first().unwrap().to_owned(),
|
||||
diagnostics: vec![Diagnostic {
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: 85,
|
||||
character: 63
|
||||
RunFileTestResult {
|
||||
data: vec![FileDiagnostics {
|
||||
path: file_paths.first().unwrap().to_owned(),
|
||||
diagnostics: vec![Diagnostic {
|
||||
range: Range {
|
||||
start: Position {
|
||||
line: 85,
|
||||
character: 63
|
||||
},
|
||||
end: Position {
|
||||
line: 85,
|
||||
character: MAX_CHAR_LENGTH
|
||||
}
|
||||
},
|
||||
end: Position {
|
||||
line: 85,
|
||||
character: MAX_CHAR_LENGTH
|
||||
}
|
||||
},
|
||||
message: message.to_string(),
|
||||
severity: Some(DiagnosticSeverity::ERROR),
|
||||
..Diagnostic::default()
|
||||
}]
|
||||
}]
|
||||
message: message.to_string(),
|
||||
severity: Some(DiagnosticSeverity::ERROR),
|
||||
..Diagnostic::default()
|
||||
}]
|
||||
}],
|
||||
messages: vec![]
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,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::RunFileTestResult;
|
||||
use testing_language_server::spec::RunFileTestResultItem;
|
||||
use testing_language_server::spec::TestItem;
|
||||
|
||||
use crate::model::Runner;
|
||||
|
@ -89,10 +89,13 @@ fn parse_diagnostics(
|
|||
message += line;
|
||||
}
|
||||
}
|
||||
Ok(result_map
|
||||
.into_iter()
|
||||
.map(|(path, diagnostics)| RunFileTestResultItem { path, diagnostics })
|
||||
.collect())
|
||||
Ok(RunFileTestResult {
|
||||
data: result_map
|
||||
.into_iter()
|
||||
.map(|(path, diagnostics)| FileDiagnostics { path, diagnostics })
|
||||
.collect(),
|
||||
messages: vec![],
|
||||
})
|
||||
}
|
||||
|
||||
fn detect_workspaces(file_paths: Vec<String>) -> DetectWorkspaceResult {
|
||||
|
@ -229,7 +232,7 @@ mod tests {
|
|||
let target_file_path = "/home/demo/test/dneo/main_test.ts";
|
||||
let diagnostics =
|
||||
parse_diagnostics(&test_result, workspace, &[target_file_path.to_string()]).unwrap();
|
||||
assert_eq!(diagnostics.len(), 1);
|
||||
assert_eq!(diagnostics.data.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -14,8 +14,8 @@ 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::RunFileTestResult;
|
||||
use testing_language_server::spec::RunFileTestResultItem;
|
||||
use testing_language_server::spec::TestItem;
|
||||
|
||||
use super::util::detect_workspaces_from_file_list;
|
||||
|
@ -130,10 +130,13 @@ fn parse_diagnostics(
|
|||
}
|
||||
}
|
||||
|
||||
Ok(result_map
|
||||
.into_iter()
|
||||
.map(|(path, diagnostics)| RunFileTestResultItem { path, diagnostics })
|
||||
.collect())
|
||||
Ok(RunFileTestResult {
|
||||
data: result_map
|
||||
.into_iter()
|
||||
.map(|(path, diagnostics)| FileDiagnostics { path, diagnostics })
|
||||
.collect(),
|
||||
messages: vec![],
|
||||
})
|
||||
}
|
||||
|
||||
fn discover(file_path: &str) -> Result<Vec<TestItem>, LSError> {
|
||||
|
@ -305,7 +308,7 @@ mod tests {
|
|||
let target_file_path = "/home/demo/test/go/src/test/cases_test.go";
|
||||
let result =
|
||||
parse_diagnostics(&contents, workspace, &[target_file_path.to_string()]).unwrap();
|
||||
let result = result.first().unwrap();
|
||||
let result = result.data.first().unwrap();
|
||||
assert_eq!(result.path, target_file_path);
|
||||
let diagnostic = result.diagnostics.first().unwrap();
|
||||
assert_eq!(diagnostic.range.start.line, 30);
|
||||
|
|
|
@ -9,8 +9,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::RunFileTestResult;
|
||||
use testing_language_server::spec::RunFileTestResultItem;
|
||||
use testing_language_server::spec::TestItem;
|
||||
|
||||
use crate::model::Runner;
|
||||
|
@ -67,10 +67,13 @@ fn parse_diagnostics(
|
|||
})
|
||||
}
|
||||
}
|
||||
Ok(result_map
|
||||
.into_iter()
|
||||
.map(|(path, diagnostics)| RunFileTestResultItem { path, diagnostics })
|
||||
.collect())
|
||||
Ok(RunFileTestResult {
|
||||
data: result_map
|
||||
.into_iter()
|
||||
.map(|(path, diagnostics)| FileDiagnostics { path, diagnostics })
|
||||
.collect(),
|
||||
messages: vec![],
|
||||
})
|
||||
}
|
||||
|
||||
fn detect_workspaces(file_paths: Vec<String>) -> DetectWorkspaceResult {
|
||||
|
@ -229,7 +232,7 @@ mod tests {
|
|||
],
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(diagnostics.len(), 2);
|
||||
assert_eq!(diagnostics.data.len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -4,8 +4,8 @@ use regex::Regex;
|
|||
use testing_language_server::{
|
||||
error::LSError,
|
||||
spec::{
|
||||
DetectWorkspaceResult, DiscoverResult, DiscoverResultItem, RunFileTestResult,
|
||||
RunFileTestResultItem, TestItem,
|
||||
DetectWorkspaceResult, DiscoverResult, DiscoverResultItem, FileDiagnostics,
|
||||
RunFileTestResult, TestItem,
|
||||
},
|
||||
};
|
||||
use xml::{reader::XmlEvent, ParserConfig};
|
||||
|
@ -194,14 +194,18 @@ impl Runner for NodeTestRunner {
|
|||
}
|
||||
let stdout = String::from_utf8(stdout).unwrap();
|
||||
let result_from_xml = get_result_from_xml(&stdout, &file_paths)?;
|
||||
let diagnostics: RunFileTestResult = result_from_xml
|
||||
let result_item: Vec<FileDiagnostics> = result_from_xml
|
||||
.into_iter()
|
||||
.map(|result_from_xml| {
|
||||
let result_item: RunFileTestResultItem = result_from_xml.into();
|
||||
let result_item: FileDiagnostics = result_from_xml.into();
|
||||
result_item
|
||||
})
|
||||
.collect();
|
||||
send_stdout(&diagnostics)?;
|
||||
let result = RunFileTestResult {
|
||||
data: result_item,
|
||||
messages: vec![],
|
||||
};
|
||||
send_stdout(&result)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ use std::io::BufReader;
|
|||
use std::process::Output;
|
||||
use testing_language_server::error::LSError;
|
||||
use testing_language_server::spec::{
|
||||
DetectWorkspaceResult, DiscoverResult, DiscoverResultItem, RunFileTestResult,
|
||||
RunFileTestResultItem, TestItem,
|
||||
DetectWorkspaceResult, DiscoverResult, DiscoverResultItem, FileDiagnostics, RunFileTestResult,
|
||||
TestItem,
|
||||
};
|
||||
use xml::reader::{ParserConfig, XmlEvent};
|
||||
|
||||
|
@ -177,14 +177,18 @@ impl Runner for PhpunitRunner {
|
|||
return Err(LSError::Adapter(String::from_utf8(stderr).unwrap()));
|
||||
}
|
||||
let result_from_xml = get_result_from_xml(log_path.to_str().unwrap())?;
|
||||
let diagnostics: RunFileTestResult = result_from_xml
|
||||
let result_item: Vec<FileDiagnostics> = result_from_xml
|
||||
.into_iter()
|
||||
.map(|result_from_xml| {
|
||||
let result_item: RunFileTestResultItem = result_from_xml.into();
|
||||
let result_item: FileDiagnostics = result_from_xml.into();
|
||||
result_item
|
||||
})
|
||||
.collect();
|
||||
send_stdout(&diagnostics)?;
|
||||
let result = RunFileTestResult {
|
||||
data: result_item,
|
||||
messages: vec![],
|
||||
};
|
||||
send_stdout(&result)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::sync::LazyLock;
|
|||
use lsp_types::{Diagnostic, DiagnosticSeverity, Position, Range};
|
||||
use regex::Regex;
|
||||
use serde::Serialize;
|
||||
use testing_language_server::spec::{RunFileTestResultItem, TestItem};
|
||||
use testing_language_server::spec::{FileDiagnostics, TestItem};
|
||||
use testing_language_server::{error::LSError, spec::RunFileTestResult};
|
||||
use tree_sitter::{Language, Point, Query, QueryCursor};
|
||||
|
||||
|
@ -30,9 +30,10 @@ pub struct ResultFromXml {
|
|||
pub col: u32,
|
||||
}
|
||||
|
||||
impl Into<RunFileTestResultItem> for ResultFromXml {
|
||||
fn into(self) -> RunFileTestResultItem {
|
||||
RunFileTestResultItem {
|
||||
#[allow(clippy::from_over_into)]
|
||||
impl Into<FileDiagnostics> for ResultFromXml {
|
||||
fn into(self) -> FileDiagnostics {
|
||||
FileDiagnostics {
|
||||
path: self.path,
|
||||
diagnostics: vec![Diagnostic {
|
||||
message: self.message,
|
||||
|
@ -371,10 +372,19 @@ pub fn parse_cargo_diagnostics(
|
|||
}
|
||||
}
|
||||
|
||||
result_map
|
||||
let no_diagnostic = result_map
|
||||
.values()
|
||||
.all(|diagnostics| !diagnostics.is_empty());
|
||||
|
||||
let data = result_map
|
||||
.into_iter()
|
||||
.map(|(path, diagnostics)| RunFileTestResultItem { path, diagnostics })
|
||||
.collect()
|
||||
.map(|(path, diagnostics)| FileDiagnostics { path, diagnostics })
|
||||
.collect();
|
||||
|
||||
RunFileTestResult {
|
||||
data,
|
||||
messages: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
/// remove this function because duplicate implementation
|
||||
|
|
|
@ -7,9 +7,7 @@ use lsp_types::{Diagnostic, DiagnosticSeverity};
|
|||
use serde_json::Value;
|
||||
use testing_language_server::{
|
||||
error::LSError,
|
||||
spec::{
|
||||
DiscoverResult, DiscoverResultItem, RunFileTestResult, RunFileTestResultItem, TestItem,
|
||||
},
|
||||
spec::{DiscoverResult, DiscoverResultItem, FileDiagnostics, RunFileTestResult, TestItem},
|
||||
};
|
||||
|
||||
use crate::model::Runner;
|
||||
|
@ -124,10 +122,13 @@ fn parse_diagnostics(
|
|||
})
|
||||
}
|
||||
}
|
||||
Ok(result_map
|
||||
.into_iter()
|
||||
.map(|(path, diagnostics)| RunFileTestResultItem { path, diagnostics })
|
||||
.collect())
|
||||
Ok(RunFileTestResult {
|
||||
data: result_map
|
||||
.into_iter()
|
||||
.map(|(path, diagnostics)| FileDiagnostics { path, diagnostics })
|
||||
.collect(),
|
||||
messages: vec![],
|
||||
})
|
||||
}
|
||||
|
||||
impl Runner for VitestRunner {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue