aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r--crates/ra_lsp_server/src/cargo_target_spec.rs98
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs6
2 files changed, 52 insertions, 52 deletions
diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs
index e08cc30e2..d0a52670a 100644
--- a/crates/ra_lsp_server/src/cargo_target_spec.rs
+++ b/crates/ra_lsp_server/src/cargo_target_spec.rs
@@ -5,55 +5,6 @@ use ra_project_model::{self, ProjectWorkspace, TargetKind};
5 5
6use crate::{world::WorldSnapshot, Result}; 6use crate::{world::WorldSnapshot, Result};
7 7
8pub(crate) fn runnable_args(
9 spec: Option<CargoTargetSpec>,
10 kind: &RunnableKind,
11) -> Result<Vec<String>> {
12 let mut res = Vec::new();
13 match kind {
14 RunnableKind::Test { test_id } => {
15 res.push("test".to_string());
16 if let Some(spec) = spec {
17 spec.push_to(&mut res);
18 }
19 res.push("--".to_string());
20 res.push(test_id.to_string());
21 if let TestId::Path(_) = test_id {
22 res.push("--exact".to_string());
23 }
24 res.push("--nocapture".to_string());
25 }
26 RunnableKind::TestMod { path } => {
27 res.push("test".to_string());
28 if let Some(spec) = spec {
29 spec.push_to(&mut res);
30 }
31 res.push("--".to_string());
32 res.push(path.to_string());
33 res.push("--nocapture".to_string());
34 }
35 RunnableKind::Bench { test_id } => {
36 res.push("bench".to_string());
37 if let Some(spec) = spec {
38 spec.push_to(&mut res);
39 }
40 res.push("--".to_string());
41 res.push(test_id.to_string());
42 if let TestId::Path(_) = test_id {
43 res.push("--exact".to_string());
44 }
45 res.push("--nocapture".to_string());
46 }
47 RunnableKind::Bin => {
48 res.push("run".to_string());
49 if let Some(spec) = spec {
50 spec.push_to(&mut res);
51 }
52 }
53 }
54 Ok(res)
55}
56
57pub(crate) struct CargoTargetSpec { 8pub(crate) struct CargoTargetSpec {
58 pub(crate) package: String, 9 pub(crate) package: String,
59 pub(crate) target: String, 10 pub(crate) target: String,
@@ -61,6 +12,55 @@ pub(crate) struct CargoTargetSpec {
61} 12}
62 13
63impl CargoTargetSpec { 14impl CargoTargetSpec {
15 pub(crate) fn runnable_args(
16 spec: Option<CargoTargetSpec>,
17 kind: &RunnableKind,
18 ) -> Result<Vec<String>> {
19 let mut res = Vec::new();
20 match kind {
21 RunnableKind::Test { test_id } => {
22 res.push("test".to_string());
23 if let Some(spec) = spec {
24 spec.push_to(&mut res);
25 }
26 res.push("--".to_string());
27 res.push(test_id.to_string());
28 if let TestId::Path(_) = test_id {
29 res.push("--exact".to_string());
30 }
31 res.push("--nocapture".to_string());
32 }
33 RunnableKind::TestMod { path } => {
34 res.push("test".to_string());
35 if let Some(spec) = spec {
36 spec.push_to(&mut res);
37 }
38 res.push("--".to_string());
39 res.push(path.to_string());
40 res.push("--nocapture".to_string());
41 }
42 RunnableKind::Bench { test_id } => {
43 res.push("bench".to_string());
44 if let Some(spec) = spec {
45 spec.push_to(&mut res);
46 }
47 res.push("--".to_string());
48 res.push(test_id.to_string());
49 if let TestId::Path(_) = test_id {
50 res.push("--exact".to_string());
51 }
52 res.push("--nocapture".to_string());
53 }
54 RunnableKind::Bin => {
55 res.push("run".to_string());
56 if let Some(spec) = spec {
57 spec.push_to(&mut res);
58 }
59 }
60 }
61 Ok(res)
62 }
63
64 pub(crate) fn for_file( 64 pub(crate) fn for_file(
65 world: &WorldSnapshot, 65 world: &WorldSnapshot,
66 file_id: FileId, 66 file_id: FileId,
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 833f31d96..92f219e28 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -29,7 +29,7 @@ use serde::{Deserialize, Serialize};
29use serde_json::to_value; 29use serde_json::to_value;
30 30
31use crate::{ 31use crate::{
32 cargo_target_spec::{runnable_args, CargoTargetSpec}, 32 cargo_target_spec::CargoTargetSpec,
33 conv::{ 33 conv::{
34 to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith, 34 to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith,
35 TryConvWithToVec, 35 TryConvWithToVec,
@@ -921,8 +921,8 @@ fn to_lsp_runnable(
921 file_id: FileId, 921 file_id: FileId,
922 runnable: Runnable, 922 runnable: Runnable,
923) -> Result<req::Runnable> { 923) -> Result<req::Runnable> {
924 let spec: Option<CargoTargetSpec> = CargoTargetSpec::for_file(world, file_id)?; 924 let spec = CargoTargetSpec::for_file(world, file_id)?;
925 let args = runnable_args(spec, &runnable.kind)?; 925 let args = CargoTargetSpec::runnable_args(spec, &runnable.kind)?;
926 let line_index = world.analysis().file_line_index(file_id)?; 926 let line_index = world.analysis().file_line_index(file_id)?;
927 let label = match &runnable.kind { 927 let label = match &runnable.kind {
928 RunnableKind::Test { test_id } => format!("test {}", test_id), 928 RunnableKind::Test { test_id } => format!("test {}", test_id),