diff options
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/cargo_target_spec.rs | 16 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/config.rs | 3 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 7 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 10 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/req.rs | 13 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 1 |
7 files changed, 39 insertions, 13 deletions
diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs index 594caffe2..5fd1e7b6b 100644 --- a/crates/ra_lsp_server/src/cargo_target_spec.rs +++ b/crates/ra_lsp_server/src/cargo_target_spec.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_ide::{FileId, RunnableKind}; | 3 | use ra_ide::{FileId, RunnableKind, TestId}; |
4 | use ra_project_model::{self, ProjectWorkspace, TargetKind}; | 4 | use ra_project_model::{self, ProjectWorkspace, TargetKind}; |
5 | 5 | ||
6 | use crate::{world::WorldSnapshot, Result}; | 6 | use crate::{world::WorldSnapshot, Result}; |
@@ -13,13 +13,16 @@ pub(crate) fn runnable_args( | |||
13 | let spec = CargoTargetSpec::for_file(world, file_id)?; | 13 | let spec = CargoTargetSpec::for_file(world, file_id)?; |
14 | let mut res = Vec::new(); | 14 | let mut res = Vec::new(); |
15 | match kind { | 15 | match kind { |
16 | RunnableKind::Test { name } => { | 16 | RunnableKind::Test { test_id } => { |
17 | res.push("test".to_string()); | 17 | res.push("test".to_string()); |
18 | if let Some(spec) = spec { | 18 | if let Some(spec) = spec { |
19 | spec.push_to(&mut res); | 19 | spec.push_to(&mut res); |
20 | } | 20 | } |
21 | res.push("--".to_string()); | 21 | res.push("--".to_string()); |
22 | res.push(name.to_string()); | 22 | res.push(test_id.to_string()); |
23 | if let TestId::Path(_) = test_id { | ||
24 | res.push("--exact".to_string()); | ||
25 | } | ||
23 | res.push("--nocapture".to_string()); | 26 | res.push("--nocapture".to_string()); |
24 | } | 27 | } |
25 | RunnableKind::TestMod { path } => { | 28 | RunnableKind::TestMod { path } => { |
@@ -31,13 +34,16 @@ pub(crate) fn runnable_args( | |||
31 | res.push(path.to_string()); | 34 | res.push(path.to_string()); |
32 | res.push("--nocapture".to_string()); | 35 | res.push("--nocapture".to_string()); |
33 | } | 36 | } |
34 | RunnableKind::Bench { name } => { | 37 | RunnableKind::Bench { test_id } => { |
35 | res.push("bench".to_string()); | 38 | res.push("bench".to_string()); |
36 | if let Some(spec) = spec { | 39 | if let Some(spec) = spec { |
37 | spec.push_to(&mut res); | 40 | spec.push_to(&mut res); |
38 | } | 41 | } |
39 | res.push("--".to_string()); | 42 | res.push("--".to_string()); |
40 | res.push(name.to_string()); | 43 | res.push(test_id.to_string()); |
44 | if let TestId::Path(_) = test_id { | ||
45 | res.push("--exact".to_string()); | ||
46 | } | ||
41 | res.push("--nocapture".to_string()); | 47 | res.push("--nocapture".to_string()); |
42 | } | 48 | } |
43 | RunnableKind::Bin => { | 49 | RunnableKind::Bin => { |
diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs index 2d7948d74..3314269ec 100644 --- a/crates/ra_lsp_server/src/config.rs +++ b/crates/ra_lsp_server/src/config.rs | |||
@@ -44,6 +44,8 @@ pub struct ServerConfig { | |||
44 | /// Fine grained feature flags to disable specific features. | 44 | /// Fine grained feature flags to disable specific features. |
45 | pub feature_flags: FxHashMap<String, bool>, | 45 | pub feature_flags: FxHashMap<String, bool>, |
46 | 46 | ||
47 | pub rustfmt_args: Vec<String>, | ||
48 | |||
47 | /// Cargo feature configurations. | 49 | /// Cargo feature configurations. |
48 | pub cargo_features: CargoFeatures, | 50 | pub cargo_features: CargoFeatures, |
49 | } | 51 | } |
@@ -63,6 +65,7 @@ impl Default for ServerConfig { | |||
63 | with_sysroot: true, | 65 | with_sysroot: true, |
64 | feature_flags: FxHashMap::default(), | 66 | feature_flags: FxHashMap::default(), |
65 | cargo_features: Default::default(), | 67 | cargo_features: Default::default(), |
68 | rustfmt_args: Vec::new(), | ||
66 | } | 69 | } |
67 | } | 70 | } |
68 | } | 71 | } |
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index c8a017c5c..ed2eaabd4 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -15,13 +15,8 @@ fn main() -> Result<()> { | |||
15 | 15 | ||
16 | fn setup_logging() -> Result<()> { | 16 | fn setup_logging() -> Result<()> { |
17 | std::env::set_var("RUST_BACKTRACE", "short"); | 17 | std::env::set_var("RUST_BACKTRACE", "short"); |
18 | |||
19 | env_logger::try_init()?; | 18 | env_logger::try_init()?; |
20 | 19 | ra_prof::init(); | |
21 | ra_prof::set_filter(match std::env::var("RA_PROFILE") { | ||
22 | Ok(spec) => ra_prof::Filter::from_spec(&spec), | ||
23 | Err(_) => ra_prof::Filter::disabled(), | ||
24 | }); | ||
25 | Ok(()) | 20 | Ok(()) |
26 | } | 21 | } |
27 | 22 | ||
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index ceff82fda..7ae2e1e6f 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -178,6 +178,7 @@ pub fn main_loop( | |||
178 | command: config.cargo_watch_command, | 178 | command: config.cargo_watch_command, |
179 | all_targets: config.cargo_watch_all_targets, | 179 | all_targets: config.cargo_watch_all_targets, |
180 | }, | 180 | }, |
181 | rustfmt_args: config.rustfmt_args, | ||
181 | } | 182 | } |
182 | }; | 183 | }; |
183 | 184 | ||
@@ -526,6 +527,7 @@ fn on_request( | |||
526 | .on::<req::CallHierarchyPrepare>(handlers::handle_call_hierarchy_prepare)? | 527 | .on::<req::CallHierarchyPrepare>(handlers::handle_call_hierarchy_prepare)? |
527 | .on::<req::CallHierarchyIncomingCalls>(handlers::handle_call_hierarchy_incoming)? | 528 | .on::<req::CallHierarchyIncomingCalls>(handlers::handle_call_hierarchy_incoming)? |
528 | .on::<req::CallHierarchyOutgoingCalls>(handlers::handle_call_hierarchy_outgoing)? | 529 | .on::<req::CallHierarchyOutgoingCalls>(handlers::handle_call_hierarchy_outgoing)? |
530 | .on::<req::Ssr>(handlers::handle_ssr)? | ||
529 | .finish(); | 531 | .finish(); |
530 | Ok(()) | 532 | Ok(()) |
531 | } | 533 | } |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 2e598fdcd..ae51141cb 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -590,6 +590,7 @@ pub fn handle_formatting( | |||
590 | let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); | 590 | let end_position = TextUnit::of_str(&file).conv_with(&file_line_index); |
591 | 591 | ||
592 | let mut rustfmt = process::Command::new("rustfmt"); | 592 | let mut rustfmt = process::Command::new("rustfmt"); |
593 | rustfmt.args(&world.options.rustfmt_args); | ||
593 | if let Some(&crate_id) = crate_ids.first() { | 594 | if let Some(&crate_id) = crate_ids.first() { |
594 | // Assume all crates are in the same edition | 595 | // Assume all crates are in the same edition |
595 | let edition = world.analysis().crate_edition(crate_id)?; | 596 | let edition = world.analysis().crate_edition(crate_id)?; |
@@ -881,6 +882,11 @@ pub fn handle_document_highlight( | |||
881 | )) | 882 | )) |
882 | } | 883 | } |
883 | 884 | ||
885 | pub fn handle_ssr(world: WorldSnapshot, params: req::SsrParams) -> Result<req::SourceChange> { | ||
886 | let _p = profile("handle_ssr"); | ||
887 | world.analysis().structural_search_replace(¶ms.arg)??.try_conv_with(&world) | ||
888 | } | ||
889 | |||
884 | pub fn publish_diagnostics(world: &WorldSnapshot, file_id: FileId) -> Result<DiagnosticTask> { | 890 | pub fn publish_diagnostics(world: &WorldSnapshot, file_id: FileId) -> Result<DiagnosticTask> { |
885 | let _p = profile("publish_diagnostics"); | 891 | let _p = profile("publish_diagnostics"); |
886 | let line_index = world.analysis().file_line_index(file_id)?; | 892 | let line_index = world.analysis().file_line_index(file_id)?; |
@@ -918,9 +924,9 @@ fn to_lsp_runnable( | |||
918 | let args = runnable_args(world, file_id, &runnable.kind)?; | 924 | let args = runnable_args(world, file_id, &runnable.kind)?; |
919 | let line_index = world.analysis().file_line_index(file_id)?; | 925 | let line_index = world.analysis().file_line_index(file_id)?; |
920 | let label = match &runnable.kind { | 926 | let label = match &runnable.kind { |
921 | RunnableKind::Test { name } => format!("test {}", name), | 927 | RunnableKind::Test { test_id } => format!("test {}", test_id), |
922 | RunnableKind::TestMod { path } => format!("test-mod {}", path), | 928 | RunnableKind::TestMod { path } => format!("test-mod {}", path), |
923 | RunnableKind::Bench { name } => format!("bench {}", name), | 929 | RunnableKind::Bench { test_id } => format!("bench {}", test_id), |
924 | RunnableKind::Bin => "run binary".to_string(), | 930 | RunnableKind::Bin => "run binary".to_string(), |
925 | }; | 931 | }; |
926 | Ok(req::Runnable { | 932 | Ok(req::Runnable { |
diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index dc327f53d..7ff7f60b3 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs | |||
@@ -206,3 +206,16 @@ pub struct InlayHint { | |||
206 | pub kind: InlayKind, | 206 | pub kind: InlayKind, |
207 | pub label: String, | 207 | pub label: String, |
208 | } | 208 | } |
209 | |||
210 | pub enum Ssr {} | ||
211 | |||
212 | impl Request for Ssr { | ||
213 | type Params = SsrParams; | ||
214 | type Result = SourceChange; | ||
215 | const METHOD: &'static str = "rust-analyzer/ssr"; | ||
216 | } | ||
217 | |||
218 | #[derive(Debug, Deserialize, Serialize)] | ||
219 | pub struct SsrParams { | ||
220 | pub arg: String, | ||
221 | } | ||
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 1ee02b47c..d993c5fc4 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -34,6 +34,7 @@ pub struct Options { | |||
34 | pub supports_location_link: bool, | 34 | pub supports_location_link: bool, |
35 | pub line_folding_only: bool, | 35 | pub line_folding_only: bool, |
36 | pub max_inlay_hint_length: Option<usize>, | 36 | pub max_inlay_hint_length: Option<usize>, |
37 | pub rustfmt_args: Vec<String>, | ||
37 | pub cargo_watch: CheckOptions, | 38 | pub cargo_watch: CheckOptions, |
38 | } | 39 | } |
39 | 40 | ||