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/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 24 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 10 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 1 |
7 files changed, 38 insertions, 25 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/lib.rs b/crates/ra_lsp_server/src/lib.rs index 1208c1343..a3464a5a3 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -31,6 +31,8 @@ mod config; | |||
31 | mod world; | 31 | mod world; |
32 | mod diagnostics; | 32 | mod diagnostics; |
33 | 33 | ||
34 | use serde::de::DeserializeOwned; | ||
35 | |||
34 | pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; | 36 | pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; |
35 | pub use crate::{ | 37 | pub use crate::{ |
36 | caps::server_capabilities, | 38 | caps::server_capabilities, |
@@ -38,3 +40,9 @@ pub use crate::{ | |||
38 | main_loop::LspError, | 40 | main_loop::LspError, |
39 | main_loop::{main_loop, show_message}, | 41 | main_loop::{main_loop, show_message}, |
40 | }; | 42 | }; |
43 | |||
44 | pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> { | ||
45 | let res = T::deserialize(&json) | ||
46 | .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?; | ||
47 | Ok(res) | ||
48 | } | ||
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 3879eeff2..ed2eaabd4 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! `ra_lsp_server` binary | 1 | //! `ra_lsp_server` binary |
2 | 2 | ||
3 | use lsp_server::Connection; | 3 | use lsp_server::Connection; |
4 | use ra_lsp_server::{show_message, Result, ServerConfig}; | 4 | use ra_lsp_server::{from_json, show_message, Result, ServerConfig}; |
5 | use ra_prof; | 5 | use ra_prof; |
6 | 6 | ||
7 | fn main() -> Result<()> { | 7 | fn main() -> Result<()> { |
@@ -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 | ||
@@ -45,7 +40,8 @@ fn run_server() -> Result<()> { | |||
45 | let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap(); | 40 | let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap(); |
46 | 41 | ||
47 | let initialize_params = connection.initialize(server_capabilities)?; | 42 | let initialize_params = connection.initialize(server_capabilities)?; |
48 | let initialize_params: lsp_types::InitializeParams = serde_json::from_value(initialize_params)?; | 43 | let initialize_params = |
44 | from_json::<lsp_types::InitializeParams>("InitializeParams", initialize_params)?; | ||
49 | 45 | ||
50 | if let Some(client_info) = initialize_params.client_info { | 46 | if let Some(client_info) = initialize_params.client_info { |
51 | log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); | 47 | log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); |
@@ -62,17 +58,13 @@ fn run_server() -> Result<()> { | |||
62 | .filter(|workspaces| !workspaces.is_empty()) | 58 | .filter(|workspaces| !workspaces.is_empty()) |
63 | .unwrap_or_else(|| vec![root]); | 59 | .unwrap_or_else(|| vec![root]); |
64 | 60 | ||
65 | let server_config: ServerConfig = initialize_params | 61 | let server_config = initialize_params |
66 | .initialization_options | 62 | .initialization_options |
67 | .and_then(|v| { | 63 | .and_then(|v| { |
68 | serde_json::from_value(v) | 64 | from_json::<ServerConfig>("config", v) |
69 | .map_err(|e| { | 65 | .map_err(|e| { |
70 | log::error!("failed to deserialize config: {}", e); | 66 | log::error!("{}", e); |
71 | show_message( | 67 | show_message(lsp_types::MessageType::Error, e.to_string(), &connection.sender); |
72 | lsp_types::MessageType::Error, | ||
73 | format!("failed to deserialize config: {}", e), | ||
74 | &connection.sender, | ||
75 | ); | ||
76 | }) | 68 | }) |
77 | .ok() | 69 | .ok() |
78 | }) | 70 | }) |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index ceff82fda..1e70cea13 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 | ||
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 65e8bc856..3893430c0 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -35,6 +35,7 @@ use crate::{ | |||
35 | TryConvWithToVec, | 35 | TryConvWithToVec, |
36 | }, | 36 | }, |
37 | diagnostics::DiagnosticTask, | 37 | diagnostics::DiagnosticTask, |
38 | from_json, | ||
38 | req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind}, | 39 | req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind}, |
39 | world::WorldSnapshot, | 40 | world::WorldSnapshot, |
40 | LspError, Result, | 41 | LspError, Result, |
@@ -589,6 +590,7 @@ pub fn handle_formatting( | |||
589 | 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); |
590 | 591 | ||
591 | let mut rustfmt = process::Command::new("rustfmt"); | 592 | let mut rustfmt = process::Command::new("rustfmt"); |
593 | rustfmt.args(&world.options.rustfmt_args); | ||
592 | if let Some(&crate_id) = crate_ids.first() { | 594 | if let Some(&crate_id) = crate_ids.first() { |
593 | // Assume all crates are in the same edition | 595 | // Assume all crates are in the same edition |
594 | let edition = world.analysis().crate_edition(crate_id)?; | 596 | let edition = world.analysis().crate_edition(crate_id)?; |
@@ -757,7 +759,7 @@ pub fn handle_code_lens( | |||
757 | // Gather runnables | 759 | // Gather runnables |
758 | for runnable in world.analysis().runnables(file_id)? { | 760 | for runnable in world.analysis().runnables(file_id)? { |
759 | let title = match &runnable.kind { | 761 | let title = match &runnable.kind { |
760 | RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "▶️Run Test", | 762 | RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "▶️\u{fe0e}Run Test", |
761 | RunnableKind::Bench { .. } => "Run Bench", | 763 | RunnableKind::Bench { .. } => "Run Bench", |
762 | RunnableKind::Bin => "Run", | 764 | RunnableKind::Bin => "Run", |
763 | } | 765 | } |
@@ -811,7 +813,7 @@ enum CodeLensResolveData { | |||
811 | pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result<CodeLens> { | 813 | pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result<CodeLens> { |
812 | let _p = profile("handle_code_lens_resolve"); | 814 | let _p = profile("handle_code_lens_resolve"); |
813 | let data = code_lens.data.unwrap(); | 815 | let data = code_lens.data.unwrap(); |
814 | let resolve = serde_json::from_value(data)?; | 816 | let resolve = from_json::<Option<CodeLensResolveData>>("CodeLensResolveData", data)?; |
815 | match resolve { | 817 | match resolve { |
816 | Some(CodeLensResolveData::Impls(lens_params)) => { | 818 | Some(CodeLensResolveData::Impls(lens_params)) => { |
817 | let locations: Vec<Location> = | 819 | let locations: Vec<Location> = |
@@ -917,9 +919,9 @@ fn to_lsp_runnable( | |||
917 | let args = runnable_args(world, file_id, &runnable.kind)?; | 919 | let args = runnable_args(world, file_id, &runnable.kind)?; |
918 | let line_index = world.analysis().file_line_index(file_id)?; | 920 | let line_index = world.analysis().file_line_index(file_id)?; |
919 | let label = match &runnable.kind { | 921 | let label = match &runnable.kind { |
920 | RunnableKind::Test { name } => format!("test {}", name), | 922 | RunnableKind::Test { test_id } => format!("test {}", test_id), |
921 | RunnableKind::TestMod { path } => format!("test-mod {}", path), | 923 | RunnableKind::TestMod { path } => format!("test-mod {}", path), |
922 | RunnableKind::Bench { name } => format!("bench {}", name), | 924 | RunnableKind::Bench { test_id } => format!("bench {}", test_id), |
923 | RunnableKind::Bin => "run binary".to_string(), | 925 | RunnableKind::Bin => "run binary".to_string(), |
924 | }; | 926 | }; |
925 | Ok(req::Runnable { | 927 | Ok(req::Runnable { |
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 | ||