diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/inlay_hints.rs | 23 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 23 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/req.rs | 21 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 2 |
7 files changed, 21 insertions, 56 deletions
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs index 8454a975b..59922e14c 100644 --- a/crates/ra_ide/src/inlay_hints.rs +++ b/crates/ra_ide/src/inlay_hints.rs | |||
@@ -12,13 +12,14 @@ use crate::{FileId, FunctionSignature}; | |||
12 | 12 | ||
13 | #[derive(Clone, Debug, PartialEq, Eq)] | 13 | #[derive(Clone, Debug, PartialEq, Eq)] |
14 | pub struct InlayConfig { | 14 | pub struct InlayConfig { |
15 | pub display_type: Vec<InlayKind>, | 15 | pub type_hints: bool, |
16 | pub parameter_hints: bool, | ||
16 | pub max_length: Option<usize>, | 17 | pub max_length: Option<usize>, |
17 | } | 18 | } |
18 | 19 | ||
19 | impl Default for InlayConfig { | 20 | impl Default for InlayConfig { |
20 | fn default() -> Self { | 21 | fn default() -> Self { |
21 | Self { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: None } | 22 | Self { type_hints: true, parameter_hints: true, max_length: None } |
22 | } | 23 | } |
23 | } | 24 | } |
24 | 25 | ||
@@ -64,7 +65,7 @@ fn get_param_name_hints( | |||
64 | inlay_hint_opts: &InlayConfig, | 65 | inlay_hint_opts: &InlayConfig, |
65 | expr: ast::Expr, | 66 | expr: ast::Expr, |
66 | ) -> Option<()> { | 67 | ) -> Option<()> { |
67 | if !inlay_hint_opts.display_type.contains(&InlayKind::ParameterHint) { | 68 | if !inlay_hint_opts.parameter_hints { |
68 | return None; | 69 | return None; |
69 | } | 70 | } |
70 | 71 | ||
@@ -104,7 +105,7 @@ fn get_bind_pat_hints( | |||
104 | inlay_hint_opts: &InlayConfig, | 105 | inlay_hint_opts: &InlayConfig, |
105 | pat: ast::BindPat, | 106 | pat: ast::BindPat, |
106 | ) -> Option<()> { | 107 | ) -> Option<()> { |
107 | if !inlay_hint_opts.display_type.contains(&InlayKind::TypeHint) { | 108 | if !inlay_hint_opts.type_hints { |
108 | return None; | 109 | return None; |
109 | } | 110 | } |
110 | 111 | ||
@@ -223,7 +224,7 @@ fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option< | |||
223 | 224 | ||
224 | #[cfg(test)] | 225 | #[cfg(test)] |
225 | mod tests { | 226 | mod tests { |
226 | use crate::inlay_hints::{InlayConfig, InlayKind}; | 227 | use crate::inlay_hints::InlayConfig; |
227 | use insta::assert_debug_snapshot; | 228 | use insta::assert_debug_snapshot; |
228 | 229 | ||
229 | use crate::mock_analysis::single_file; | 230 | use crate::mock_analysis::single_file; |
@@ -237,7 +238,7 @@ mod tests { | |||
237 | let _x = foo(4, 4); | 238 | let _x = foo(4, 4); |
238 | }"#, | 239 | }"#, |
239 | ); | 240 | ); |
240 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ display_type: vec![InlayKind::ParameterHint], max_length: None}).unwrap(), @r###" | 241 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ parameter_hints: true, type_hints: false, max_length: None}).unwrap(), @r###" |
241 | [ | 242 | [ |
242 | InlayHint { | 243 | InlayHint { |
243 | range: [106; 107), | 244 | range: [106; 107), |
@@ -261,7 +262,7 @@ mod tests { | |||
261 | let _x = foo(4, 4); | 262 | let _x = foo(4, 4); |
262 | }"#, | 263 | }"#, |
263 | ); | 264 | ); |
264 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ display_type: vec![], max_length: None}).unwrap(), @r###"[]"###); | 265 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ type_hints: false, parameter_hints: false, max_length: None}).unwrap(), @r###"[]"###); |
265 | } | 266 | } |
266 | 267 | ||
267 | #[test] | 268 | #[test] |
@@ -273,7 +274,7 @@ mod tests { | |||
273 | let _x = foo(4, 4); | 274 | let _x = foo(4, 4); |
274 | }"#, | 275 | }"#, |
275 | ); | 276 | ); |
276 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ display_type: vec![InlayKind::TypeHint], max_length: None}).unwrap(), @r###" | 277 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ type_hints: true, parameter_hints: false, max_length: None}).unwrap(), @r###" |
277 | [ | 278 | [ |
278 | InlayHint { | 279 | InlayHint { |
279 | range: [97; 99), | 280 | range: [97; 99), |
@@ -810,7 +811,7 @@ fn main() { | |||
810 | }"#, | 811 | }"#, |
811 | ); | 812 | ); |
812 | 813 | ||
813 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: Some(8) }).unwrap(), @r###" | 814 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" |
814 | [ | 815 | [ |
815 | InlayHint { | 816 | InlayHint { |
816 | range: [74; 75), | 817 | range: [74; 75), |
@@ -1020,7 +1021,7 @@ fn main() { | |||
1020 | }"#, | 1021 | }"#, |
1021 | ); | 1022 | ); |
1022 | 1023 | ||
1023 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: Some(8) }).unwrap(), @r###" | 1024 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" |
1024 | [] | 1025 | [] |
1025 | "### | 1026 | "### |
1026 | ); | 1027 | ); |
@@ -1046,7 +1047,7 @@ fn main() { | |||
1046 | }"#, | 1047 | }"#, |
1047 | ); | 1048 | ); |
1048 | 1049 | ||
1049 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { display_type: vec![InlayKind::TypeHint, InlayKind::ParameterHint], max_length: Some(8) }).unwrap(), @r###" | 1050 | assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" |
1050 | [] | 1051 | [] |
1051 | "### | 1052 | "### |
1052 | ); | 1053 | ); |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 036c8719f..37845ca56 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -16,7 +16,6 @@ use anyhow::{bail, Context, Result}; | |||
16 | use ra_cfg::CfgOptions; | 16 | use ra_cfg::CfgOptions; |
17 | use ra_db::{CrateGraph, CrateName, Edition, Env, FileId}; | 17 | use ra_db::{CrateGraph, CrateName, Edition, Env, FileId}; |
18 | use rustc_hash::FxHashMap; | 18 | use rustc_hash::FxHashMap; |
19 | use serde::Deserialize; | ||
20 | use serde_json::from_reader; | 19 | use serde_json::from_reader; |
21 | 20 | ||
22 | pub use crate::{ | 21 | pub use crate::{ |
@@ -25,28 +24,6 @@ pub use crate::{ | |||
25 | sysroot::Sysroot, | 24 | sysroot::Sysroot, |
26 | }; | 25 | }; |
27 | 26 | ||
28 | #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] | ||
29 | #[serde(rename_all = "lowercase")] | ||
30 | pub enum InlayHintDisplayType { | ||
31 | Off, | ||
32 | TypeHints, | ||
33 | ParameterHints, | ||
34 | Full, | ||
35 | } | ||
36 | |||
37 | #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] | ||
38 | #[serde(rename_all = "camelCase", default)] | ||
39 | pub struct InlayHintOptions { | ||
40 | pub display_type: InlayHintDisplayType, | ||
41 | pub max_length: Option<usize>, | ||
42 | } | ||
43 | |||
44 | impl Default for InlayHintOptions { | ||
45 | fn default() -> Self { | ||
46 | Self { display_type: InlayHintDisplayType::Full, max_length: None } | ||
47 | } | ||
48 | } | ||
49 | |||
50 | #[derive(Clone, PartialEq, Eq, Hash, Debug)] | 27 | #[derive(Clone, PartialEq, Eq, Hash, Debug)] |
51 | pub struct CargoTomlNotFoundError { | 28 | pub struct CargoTomlNotFoundError { |
52 | pub searched_at: PathBuf, | 29 | pub searched_at: PathBuf, |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 22ff0845c..3a6cfbe7b 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -33,7 +33,7 @@ pub struct ServerConfig { | |||
33 | pub lru_capacity: Option<usize>, | 33 | pub lru_capacity: Option<usize>, |
34 | 34 | ||
35 | #[serde(with = "InlayConfigDef")] | 35 | #[serde(with = "InlayConfigDef")] |
36 | pub inlay_hint_opts: InlayConfig, | 36 | pub inlay_hints: InlayConfig, |
37 | 37 | ||
38 | pub cargo_watch_enable: bool, | 38 | pub cargo_watch_enable: bool, |
39 | pub cargo_watch_args: Vec<String>, | 39 | pub cargo_watch_args: Vec<String>, |
@@ -60,7 +60,7 @@ impl Default for ServerConfig { | |||
60 | exclude_globs: Vec::new(), | 60 | exclude_globs: Vec::new(), |
61 | use_client_watching: false, | 61 | use_client_watching: false, |
62 | lru_capacity: None, | 62 | lru_capacity: None, |
63 | inlay_hint_opts: Default::default(), | 63 | inlay_hints: Default::default(), |
64 | cargo_watch_enable: true, | 64 | cargo_watch_enable: true, |
65 | cargo_watch_args: Vec::new(), | 65 | cargo_watch_args: Vec::new(), |
66 | cargo_watch_command: "check".to_string(), | 66 | cargo_watch_command: "check".to_string(), |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 729c384ac..b6d1f28d8 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -177,7 +177,7 @@ pub fn main_loop( | |||
177 | .and_then(|it| it.folding_range.as_ref()) | 177 | .and_then(|it| it.folding_range.as_ref()) |
178 | .and_then(|it| it.line_folding_only) | 178 | .and_then(|it| it.line_folding_only) |
179 | .unwrap_or(false), | 179 | .unwrap_or(false), |
180 | inlay_hint_opts: config.inlay_hint_opts, | 180 | inlay_hints: config.inlay_hints, |
181 | cargo_watch: CheckOptions { | 181 | cargo_watch: CheckOptions { |
182 | enable: config.cargo_watch_enable, | 182 | enable: config.cargo_watch_enable, |
183 | args: config.cargo_watch_args, | 183 | args: config.cargo_watch_args, |
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 23463b28e..921990da0 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -997,7 +997,7 @@ pub fn handle_inlay_hints( | |||
997 | let analysis = world.analysis(); | 997 | let analysis = world.analysis(); |
998 | let line_index = analysis.file_line_index(file_id)?; | 998 | let line_index = analysis.file_line_index(file_id)?; |
999 | Ok(analysis | 999 | Ok(analysis |
1000 | .inlay_hints(file_id, &world.options.inlay_hint_opts)? | 1000 | .inlay_hints(file_id, &world.options.inlay_hints)? |
1001 | .into_iter() | 1001 | .into_iter() |
1002 | .map(|api_type| InlayHint { | 1002 | .map(|api_type| InlayHint { |
1003 | label: api_type.label.to_string(), | 1003 | label: api_type.label.to_string(), |
diff --git a/crates/rust-analyzer/src/req.rs b/crates/rust-analyzer/src/req.rs index dab05405e..1dcab2703 100644 --- a/crates/rust-analyzer/src/req.rs +++ b/crates/rust-analyzer/src/req.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url}; | 3 | use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url}; |
4 | use rustc_hash::FxHashMap; | 4 | use rustc_hash::FxHashMap; |
5 | use serde::{Deserialize, Deserializer, Serialize}; | 5 | use serde::{Deserialize, Serialize}; |
6 | 6 | ||
7 | use ra_ide::{InlayConfig, InlayKind}; | 7 | use ra_ide::{InlayConfig, InlayKind}; |
8 | 8 | ||
@@ -204,24 +204,11 @@ pub enum InlayKindDef { | |||
204 | ParameterHint, | 204 | ParameterHint, |
205 | } | 205 | } |
206 | 206 | ||
207 | // Work-around until better serde support is added | ||
208 | // https://github.com/serde-rs/serde/issues/723#issuecomment-382501277 | ||
209 | fn vec_inlay_kind<'de, D>(deserializer: D) -> Result<Vec<InlayKind>, D::Error> | ||
210 | where | ||
211 | D: Deserializer<'de>, | ||
212 | { | ||
213 | #[derive(Deserialize)] | ||
214 | struct Wrapper(#[serde(with = "InlayKindDef")] InlayKind); | ||
215 | |||
216 | let v = Vec::deserialize(deserializer)?; | ||
217 | Ok(v.into_iter().map(|Wrapper(a)| a).collect()) | ||
218 | } | ||
219 | |||
220 | #[derive(Deserialize)] | 207 | #[derive(Deserialize)] |
221 | #[serde(remote = "InlayConfig")] | 208 | #[serde(remote = "InlayConfig", rename_all = "camelCase")] |
222 | pub struct InlayConfigDef { | 209 | pub struct InlayConfigDef { |
223 | #[serde(deserialize_with = "vec_inlay_kind")] | 210 | pub type_hints: bool, |
224 | pub display_type: Vec<InlayKind>, | 211 | pub parameter_hints: bool, |
225 | pub max_length: Option<usize>, | 212 | pub max_length: Option<usize>, |
226 | } | 213 | } |
227 | 214 | ||
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index 6eb1ea7d2..004803b00 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -33,7 +33,7 @@ pub struct Options { | |||
33 | pub publish_decorations: bool, | 33 | pub publish_decorations: bool, |
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 inlay_hint_opts: InlayConfig, | 36 | pub inlay_hints: InlayConfig, |
37 | pub rustfmt_args: Vec<String>, | 37 | pub rustfmt_args: Vec<String>, |
38 | pub cargo_watch: CheckOptions, | 38 | pub cargo_watch: CheckOptions, |
39 | } | 39 | } |