mirror of
https://github.com/kbwo/testing-language-server.git
synced 2025-07-24 11:23:42 +00:00
rename some symbols
This commit is contained in:
parent
4a4f5411e4
commit
b6899587db
9 changed files with 75 additions and 57 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -521,6 +521,28 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "testing-language-server"
|
||||
version = "0.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8cc86bccfcfd40400582bd0e9a970e0904e0fcfd3890ca935caaa868cf0a787c"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"dirs",
|
||||
"glob",
|
||||
"lsp-types",
|
||||
"once_cell",
|
||||
"regex",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"strum",
|
||||
"thiserror",
|
||||
"tracing",
|
||||
"tracing-appender",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "testing-language-server"
|
||||
version = "0.0.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
@ -549,7 +571,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"testing-language-server",
|
||||
"testing-language-server 0.0.2",
|
||||
"tree-sitter",
|
||||
"tree-sitter-javascript",
|
||||
"tree-sitter-rust",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "testing-language-server"
|
||||
version = "0.0.2"
|
||||
version = "0.0.3"
|
||||
edition = "2021"
|
||||
author = "Kodai Kabasawa <kabaaa1126@gmail.com>"
|
||||
description = "LSP server for testing"
|
||||
|
|
|
@ -8,8 +8,7 @@ license = "MIT"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# testing-language-server = "0.0.1"
|
||||
testing-language-server = { path = "../../" }
|
||||
testing-language-server = "0.0.2"
|
||||
lsp-types = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::io::Write;
|
|||
use std::str::FromStr;
|
||||
use testing_language_server::error::LSError;
|
||||
use testing_language_server::spec::AdapterCommands;
|
||||
use testing_language_server::spec::DetectWorkspaceRootArgs;
|
||||
use testing_language_server::spec::DetectWorkspaceArgs;
|
||||
use testing_language_server::spec::DiscoverArgs;
|
||||
use testing_language_server::spec::RunFileTestArgs;
|
||||
pub mod model;
|
||||
|
@ -39,9 +39,9 @@ fn handle(commands: AdapterCommands) -> Result<(), LSError> {
|
|||
test_kind.run_file_test(RunFileTestArgs { extra, ..commands })?;
|
||||
Ok(())
|
||||
}
|
||||
AdapterCommands::DetectWorkspaceRoot(mut commands) => {
|
||||
AdapterCommands::DetectWorkspace(mut commands) => {
|
||||
let (extra, test_kind) = pick_test_from_extra(&mut commands.extra)?;
|
||||
test_kind.detect_workspaces_root(DetectWorkspaceRootArgs { extra, ..commands })?;
|
||||
test_kind.detect_workspaces_root(DetectWorkspaceArgs { extra, ..commands })?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::runner::cargo_test::CargoTestRunner;
|
||||
use std::str::FromStr;
|
||||
use testing_language_server::error::LSError;
|
||||
use testing_language_server::spec::DetectWorkspaceRootArgs;
|
||||
use testing_language_server::spec::DetectWorkspaceArgs;
|
||||
use testing_language_server::spec::DiscoverArgs;
|
||||
use testing_language_server::spec::RunFileTestArgs;
|
||||
|
||||
|
@ -27,7 +27,7 @@ impl Runner for AvailableTestKind {
|
|||
}
|
||||
}
|
||||
|
||||
fn detect_workspaces_root(&self, args: DetectWorkspaceRootArgs) -> Result<(), LSError> {
|
||||
fn detect_workspaces_root(&self, args: DetectWorkspaceArgs) -> Result<(), LSError> {
|
||||
match self {
|
||||
AvailableTestKind::CargoTest(runner) => runner.detect_workspaces_root(args),
|
||||
AvailableTestKind::Jest(runner) => runner.detect_workspaces_root(args),
|
||||
|
@ -50,5 +50,5 @@ impl FromStr for AvailableTestKind {
|
|||
pub trait Runner {
|
||||
fn disover(&self, args: DiscoverArgs) -> Result<(), LSError>;
|
||||
fn run_file_test(&self, args: RunFileTestArgs) -> Result<(), LSError>;
|
||||
fn detect_workspaces_root(&self, args: DetectWorkspaceRootArgs) -> Result<(), LSError>;
|
||||
fn detect_workspaces_root(&self, args: DetectWorkspaceArgs) -> Result<(), LSError>;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::path::PathBuf;
|
|||
use std::process::Output;
|
||||
use std::str::FromStr;
|
||||
use testing_language_server::error::LSError;
|
||||
use testing_language_server::spec::DetectWorkspaceRootResult;
|
||||
use testing_language_server::spec::DetectWorkspaceResult;
|
||||
use testing_language_server::spec::RunFileTestResult;
|
||||
use testing_language_server::spec::TestItem;
|
||||
use tree_sitter::Point;
|
||||
|
@ -194,7 +194,7 @@ fn detect_workspace_from_file(file_path: PathBuf) -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
fn detect_workspaces(file_paths: Vec<String>) -> Result<DetectWorkspaceRootResult, LSError> {
|
||||
fn detect_workspaces(file_paths: Vec<String>) -> Result<DetectWorkspaceResult, LSError> {
|
||||
let mut result_map: HashMap<String, Vec<String>> = HashMap::new();
|
||||
let mut file_paths = file_paths.clone();
|
||||
file_paths.sort_by_key(|b| std::cmp::Reverse(b.len()));
|
||||
|
@ -265,7 +265,7 @@ impl Runner for CargoTestRunner {
|
|||
|
||||
fn detect_workspaces_root(
|
||||
&self,
|
||||
args: testing_language_server::spec::DetectWorkspaceRootArgs,
|
||||
args: testing_language_server::spec::DetectWorkspaceArgs,
|
||||
) -> Result<(), LSError> {
|
||||
let file_paths = args.file_paths;
|
||||
let detect_result = detect_workspaces(file_paths)?;
|
||||
|
|
|
@ -10,7 +10,7 @@ use std::str::FromStr;
|
|||
use tempfile::tempdir;
|
||||
use testing_language_server::error::LSError;
|
||||
|
||||
use testing_language_server::spec::DetectWorkspaceRootResult;
|
||||
use testing_language_server::spec::DetectWorkspaceResult;
|
||||
use testing_language_server::spec::DiscoverResult;
|
||||
use testing_language_server::spec::DiscoverResultItem;
|
||||
use testing_language_server::spec::RunFileTestResult;
|
||||
|
@ -94,7 +94,7 @@ fn detect_workspace_from_file(file_path: PathBuf) -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
fn detect_workspaces(file_paths: Vec<String>) -> Result<DetectWorkspaceRootResult, LSError> {
|
||||
fn detect_workspaces(file_paths: Vec<String>) -> Result<DetectWorkspaceResult, LSError> {
|
||||
let mut result_map: HashMap<String, Vec<String>> = HashMap::new();
|
||||
let mut file_paths: Vec<String> = file_paths
|
||||
.into_iter()
|
||||
|
@ -305,7 +305,7 @@ impl Runner for JestRunner {
|
|||
|
||||
fn detect_workspaces_root(
|
||||
&self,
|
||||
args: testing_language_server::spec::DetectWorkspaceRootArgs,
|
||||
args: testing_language_server::spec::DetectWorkspaceArgs,
|
||||
) -> Result<(), LSError> {
|
||||
let file_paths = args.file_paths;
|
||||
let detect_result = detect_workspaces(file_paths)?;
|
||||
|
|
|
@ -52,7 +52,7 @@ pub struct InitializedOptions {
|
|||
pub struct TestingLS {
|
||||
pub initialize_params: InitializeParams,
|
||||
pub options: InitializedOptions,
|
||||
pub workspace_root_cache: Vec<WorkspaceAnalysis>,
|
||||
pub workspaces_cache: Vec<WorkspaceAnalysis>,
|
||||
}
|
||||
|
||||
impl Default for TestingLS {
|
||||
|
@ -66,7 +66,7 @@ impl TestingLS {
|
|||
Self {
|
||||
initialize_params: Default::default(),
|
||||
options: Default::default(),
|
||||
workspace_root_cache: Vec::new(),
|
||||
workspaces_cache: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,20 +236,20 @@ impl TestingLS {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn refresh_workspace_root_cache(&mut self) -> Result<(), LSError> {
|
||||
pub fn refresh_workspaces_cache(&mut self) -> Result<(), LSError> {
|
||||
let adapter_commands = self.adapter_commands();
|
||||
let default_workspace_root = self
|
||||
let default_project_dir = self
|
||||
.initialize_params
|
||||
.clone()
|
||||
.workspace_folders
|
||||
.ok_or(LSError::Any(anyhow::anyhow!("No workspace folders found")))?;
|
||||
let default_workspace_uri = default_workspace_root[0].uri.clone();
|
||||
let default_workspace_uri = default_project_dir[0].uri.clone();
|
||||
let project_dir = self
|
||||
.options
|
||||
.project_dir
|
||||
.clone()
|
||||
.unwrap_or(default_workspace_uri.to_file_path().unwrap());
|
||||
self.workspace_root_cache = vec![];
|
||||
self.workspaces_cache = vec![];
|
||||
// Nested and multiple loops, but each count is small
|
||||
for adapter_commands in adapter_commands.values() {
|
||||
for adapter in adapter_commands {
|
||||
|
@ -281,29 +281,29 @@ impl TestingLS {
|
|||
.map_err(|err| LSError::Adapter(err.to_string()))?;
|
||||
let adapter_result = String::from_utf8(output.stdout)
|
||||
.map_err(|err| LSError::Adapter(err.to_string()))?;
|
||||
let workspace_root: DetectWorkspaceResult = serde_json::from_str(&adapter_result)?;
|
||||
self.workspace_root_cache
|
||||
.push(WorkspaceAnalysis::new(adapter.clone(), workspace_root))
|
||||
let workspace: DetectWorkspaceResult = serde_json::from_str(&adapter_result)?;
|
||||
self.workspaces_cache
|
||||
.push(WorkspaceAnalysis::new(adapter.clone(), workspace))
|
||||
}
|
||||
}
|
||||
send_stdout(&json!({
|
||||
"jsonrpc": "2.0",
|
||||
"method": "$/detectedWorkspaceRoots",
|
||||
"params": self.workspace_root_cache,
|
||||
"method": "$/detectedWorkspace",
|
||||
"params": self.workspaces_cache,
|
||||
}))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn check_workspace(&mut self) -> Result<(), LSError> {
|
||||
self.refresh_workspace_root_cache()?;
|
||||
self.refresh_workspaces_cache()?;
|
||||
|
||||
self.workspace_root_cache.iter().for_each(
|
||||
self.workspaces_cache.iter().for_each(
|
||||
|WorkspaceAnalysis {
|
||||
adapter_config: adapter,
|
||||
workspace_roots: workspaces,
|
||||
workspaces,
|
||||
}| {
|
||||
workspaces.iter().for_each(|(workspace_root, paths)| {
|
||||
let _ = self.check(adapter, workspace_root, paths);
|
||||
workspaces.iter().for_each(|(workspace, paths)| {
|
||||
let _ = self.check(adapter, workspace, paths);
|
||||
})
|
||||
},
|
||||
);
|
||||
|
@ -313,18 +313,18 @@ impl TestingLS {
|
|||
pub fn check_file(&mut self, path: &str, refresh_needed: bool) -> Result<(), LSError> {
|
||||
let path = path.replace("file://", "");
|
||||
if refresh_needed {
|
||||
self.refresh_workspace_root_cache()?;
|
||||
self.refresh_workspaces_cache()?;
|
||||
}
|
||||
self.workspace_root_cache.iter().for_each(
|
||||
self.workspaces_cache.iter().for_each(
|
||||
|WorkspaceAnalysis {
|
||||
adapter_config: adapter,
|
||||
workspace_roots: workspaces,
|
||||
workspaces,
|
||||
}| {
|
||||
for (workspace_root, paths) in workspaces.iter() {
|
||||
for (workspace, paths) in workspaces.iter() {
|
||||
if !paths.contains(&path.to_string()) {
|
||||
continue;
|
||||
}
|
||||
let _ = self.check(adapter, workspace_root, paths);
|
||||
let _ = self.check(adapter, workspace, paths);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -334,12 +334,12 @@ impl TestingLS {
|
|||
fn get_diagnostics(
|
||||
&self,
|
||||
adapter: &AdapterConfiguration,
|
||||
workspace_root: &str,
|
||||
workspace: &str,
|
||||
paths: &[String],
|
||||
) -> Result<Vec<(String, Vec<Diagnostic>)>, LSError> {
|
||||
let mut adapter_command = Command::new(&adapter.path);
|
||||
let mut diagnostics: Vec<(String, Vec<Diagnostic>)> = vec![];
|
||||
let cwd = PathBuf::from(workspace_root);
|
||||
let cwd = PathBuf::from(workspace);
|
||||
let adapter_command = adapter_command.current_dir(&cwd);
|
||||
let mut args: Vec<&str> = vec!["--workspace", cwd.to_str().unwrap()];
|
||||
paths.iter().for_each(|path| {
|
||||
|
@ -404,7 +404,7 @@ impl TestingLS {
|
|||
fn check(
|
||||
&self,
|
||||
adapter: &AdapterConfiguration,
|
||||
workspace_root: &str,
|
||||
workspace: &str,
|
||||
paths: &[String],
|
||||
) -> Result<(), LSError> {
|
||||
let token = NumberOrString::String("testing-ls/start_testing".to_string());
|
||||
|
@ -434,7 +434,7 @@ impl TestingLS {
|
|||
"params": params,
|
||||
}))
|
||||
.unwrap();
|
||||
let diagnostics = self.get_diagnostics(adapter, workspace_root, paths)?;
|
||||
let diagnostics = self.get_diagnostics(adapter, workspace, paths)?;
|
||||
for (path, diagnostics) in diagnostics {
|
||||
self.send_diagnostics(
|
||||
Url::from_file_path(path.replace("file://", "")).unwrap(),
|
||||
|
@ -464,8 +464,8 @@ impl TestingLS {
|
|||
let mut result: DiscoverResult = vec![];
|
||||
for WorkspaceAnalysis {
|
||||
adapter_config: adapter,
|
||||
workspace_roots: workspaces,
|
||||
} in &self.workspace_root_cache
|
||||
workspaces,
|
||||
} in &self.workspaces_cache
|
||||
{
|
||||
for (_, paths) in workspaces.iter() {
|
||||
if !paths.contains(&path.to_string()) {
|
||||
|
@ -536,7 +536,7 @@ mod tests {
|
|||
adapter_command: HashMap::from([(String::from(".rs"), vec![])]),
|
||||
project_dir: None,
|
||||
},
|
||||
workspace_root_cache: Vec::new(),
|
||||
workspaces_cache: Vec::new(),
|
||||
};
|
||||
let librs = abs_path_of_test_proj.join("lib.rs");
|
||||
server.check_file(librs.to_str().unwrap(), true).unwrap();
|
||||
|
@ -571,20 +571,20 @@ mod tests {
|
|||
adapter_command: HashMap::from([(String::from(".rs"), vec![adapter_conf])]),
|
||||
project_dir: None,
|
||||
},
|
||||
workspace_root_cache: Vec::new(),
|
||||
workspaces_cache: Vec::new(),
|
||||
};
|
||||
server.check_workspace().unwrap();
|
||||
server
|
||||
.workspace_root_cache
|
||||
.workspaces_cache
|
||||
.iter()
|
||||
.for_each(|workspace_analysis| {
|
||||
let adapter_command_path = workspace_analysis.adapter_config.path.clone();
|
||||
assert!(adapter_command_path.contains("target/debug/testing-ls-adapter"));
|
||||
workspace_analysis
|
||||
.workspace_roots
|
||||
.workspaces
|
||||
.iter()
|
||||
.for_each(|(workspace_root, paths)| {
|
||||
assert_eq!(workspace_root, abs_path_of_test_proj.to_str().unwrap());
|
||||
.for_each(|(workspace, paths)| {
|
||||
assert_eq!(workspace, abs_path_of_test_proj.to_str().unwrap());
|
||||
paths.iter().for_each(|path| {
|
||||
assert!(path.contains("rust/src"));
|
||||
});
|
||||
|
@ -645,7 +645,7 @@ mod tests {
|
|||
adapter_command: HashMap::from([(String::from(".rs"), vec![adapter_conf.clone()])]),
|
||||
project_dir: None,
|
||||
},
|
||||
workspace_root_cache: Vec::new(),
|
||||
workspaces_cache: Vec::new(),
|
||||
};
|
||||
let diagnostics = server
|
||||
.get_diagnostics(
|
||||
|
|
11
src/spec.rs
11
src/spec.rs
|
@ -28,7 +28,7 @@ pub struct RunFileTestArgs {
|
|||
pub file_paths: Vec<String>,
|
||||
|
||||
#[arg(short, long)]
|
||||
pub workspace_root: String,
|
||||
pub workspace: String,
|
||||
|
||||
#[arg(last = true)]
|
||||
pub extra: Vec<String>,
|
||||
|
@ -50,17 +50,14 @@ pub(crate) type WorkspaceFilePath = String;
|
|||
#[derive(Debug, Serialize, Clone)]
|
||||
pub struct WorkspaceAnalysis {
|
||||
pub adapter_config: AdapterConfiguration,
|
||||
pub workspace_roots: DetectWorkspaceResult,
|
||||
pub workspaces: DetectWorkspaceResult,
|
||||
}
|
||||
|
||||
impl WorkspaceAnalysis {
|
||||
pub fn new(
|
||||
adapter_config: AdapterConfiguration,
|
||||
workspace_roots: DetectWorkspaceResult,
|
||||
) -> Self {
|
||||
pub fn new(adapter_config: AdapterConfiguration, workspaces: DetectWorkspaceResult) -> Self {
|
||||
Self {
|
||||
adapter_config,
|
||||
workspace_roots,
|
||||
workspaces,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue