From 865759925be6b72f7ef39124ed0e4c86c0412a69 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 18 Feb 2020 12:37:45 +0100 Subject: Rename folder --- crates/ra_lsp_server/src/cargo_target_spec.rs | 118 -------------------------- 1 file changed, 118 deletions(-) delete mode 100644 crates/ra_lsp_server/src/cargo_target_spec.rs (limited to 'crates/ra_lsp_server/src/cargo_target_spec.rs') diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs deleted file mode 100644 index 53751aafb..000000000 --- a/crates/ra_lsp_server/src/cargo_target_spec.rs +++ /dev/null @@ -1,118 +0,0 @@ -//! See `CargoTargetSpec` - -use ra_ide::{FileId, RunnableKind, TestId}; -use ra_project_model::{self, ProjectWorkspace, TargetKind}; - -use crate::{world::WorldSnapshot, Result}; - -/// Abstract representation of Cargo target. -/// -/// We use it to cook up the set of cli args we need to pass to Cargo to -/// build/test/run the target. -pub(crate) struct CargoTargetSpec { - pub(crate) package: String, - pub(crate) target: String, - pub(crate) target_kind: TargetKind, -} - -impl CargoTargetSpec { - pub(crate) fn runnable_args( - spec: Option, - kind: &RunnableKind, - ) -> Result> { - let mut res = Vec::new(); - match kind { - RunnableKind::Test { test_id } => { - res.push("test".to_string()); - if let Some(spec) = spec { - spec.push_to(&mut res); - } - res.push("--".to_string()); - res.push(test_id.to_string()); - if let TestId::Path(_) = test_id { - res.push("--exact".to_string()); - } - res.push("--nocapture".to_string()); - } - RunnableKind::TestMod { path } => { - res.push("test".to_string()); - if let Some(spec) = spec { - spec.push_to(&mut res); - } - res.push("--".to_string()); - res.push(path.to_string()); - res.push("--nocapture".to_string()); - } - RunnableKind::Bench { test_id } => { - res.push("bench".to_string()); - if let Some(spec) = spec { - spec.push_to(&mut res); - } - res.push("--".to_string()); - res.push(test_id.to_string()); - if let TestId::Path(_) = test_id { - res.push("--exact".to_string()); - } - res.push("--nocapture".to_string()); - } - RunnableKind::Bin => { - res.push("run".to_string()); - if let Some(spec) = spec { - spec.push_to(&mut res); - } - } - } - Ok(res) - } - - pub(crate) fn for_file( - world: &WorldSnapshot, - file_id: FileId, - ) -> Result> { - let &crate_id = match world.analysis().crate_for(file_id)?.first() { - Some(crate_id) => crate_id, - None => return Ok(None), - }; - let file_id = world.analysis().crate_root(crate_id)?; - let path = world.file_id_to_path(file_id); - let res = world.workspaces.iter().find_map(|ws| match ws { - ProjectWorkspace::Cargo { cargo, .. } => { - let tgt = cargo.target_by_root(&path)?; - Some(CargoTargetSpec { - package: tgt.package(&cargo).name(&cargo).to_string(), - target: tgt.name(&cargo).to_string(), - target_kind: tgt.kind(&cargo), - }) - } - ProjectWorkspace::Json { .. } => None, - }); - Ok(res) - } - - pub(crate) fn push_to(self, buf: &mut Vec) { - buf.push("--package".to_string()); - buf.push(self.package); - match self.target_kind { - TargetKind::Bin => { - buf.push("--bin".to_string()); - buf.push(self.target); - } - TargetKind::Test => { - buf.push("--test".to_string()); - buf.push(self.target); - } - TargetKind::Bench => { - buf.push("--bench".to_string()); - buf.push(self.target); - } - TargetKind::Example => { - buf.push("--example".to_string()); - buf.push(self.target); - } - TargetKind::Lib => { - buf.push("--lib".to_string()); - } - TargetKind::Other => (), - } - } -} -- cgit v1.2.3