diff options
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 31 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop/handlers.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/src/req.rs | 29 |
3 files changed, 31 insertions, 36 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 2f407723b..22ff0845c 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -7,40 +7,13 @@ | |||
7 | //! configure the server itself, feature flags are passed into analysis, and | 7 | //! configure the server itself, feature flags are passed into analysis, and |
8 | //! tweak things like automatic insertion of `()` in completions. | 8 | //! tweak things like automatic insertion of `()` in completions. |
9 | 9 | ||
10 | use ra_ide::{InlayConfig, InlayKind}; | 10 | use crate::req::InlayConfigDef; |
11 | use ra_ide::InlayConfig; | ||
11 | use rustc_hash::FxHashMap; | 12 | use rustc_hash::FxHashMap; |
12 | 13 | ||
13 | use ra_project_model::CargoFeatures; | 14 | use ra_project_model::CargoFeatures; |
14 | use serde::{Deserialize, Deserializer}; | 15 | use serde::{Deserialize, Deserializer}; |
15 | 16 | ||
16 | #[derive(Deserialize)] | ||
17 | #[serde(remote = "InlayKind")] | ||
18 | pub enum InlayKindDef { | ||
19 | TypeHint, | ||
20 | ParameterHint, | ||
21 | } | ||
22 | |||
23 | // Work-around until better serde support is added | ||
24 | // https://github.com/serde-rs/serde/issues/723#issuecomment-382501277 | ||
25 | fn vec_inlay_kind<'de, D>(deserializer: D) -> Result<Vec<InlayKind>, D::Error> | ||
26 | where | ||
27 | D: Deserializer<'de>, | ||
28 | { | ||
29 | #[derive(Deserialize)] | ||
30 | struct Wrapper(#[serde(with = "InlayKindDef")] InlayKind); | ||
31 | |||
32 | let v = Vec::deserialize(deserializer)?; | ||
33 | Ok(v.into_iter().map(|Wrapper(a)| a).collect()) | ||
34 | } | ||
35 | |||
36 | #[derive(Deserialize)] | ||
37 | #[serde(remote = "InlayConfig")] | ||
38 | pub struct InlayConfigDef { | ||
39 | #[serde(deserialize_with = "vec_inlay_kind")] | ||
40 | pub display_type: Vec<InlayKind>, | ||
41 | pub max_length: Option<usize>, | ||
42 | } | ||
43 | |||
44 | /// Client provided initialization options | 17 | /// Client provided initialization options |
45 | #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] | 18 | #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] |
46 | #[serde(rename_all = "camelCase", default)] | 19 | #[serde(rename_all = "camelCase", default)] |
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index 4f58bcb0a..23463b28e 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs | |||
@@ -37,7 +37,7 @@ use crate::{ | |||
37 | }, | 37 | }, |
38 | diagnostics::DiagnosticTask, | 38 | diagnostics::DiagnosticTask, |
39 | from_json, | 39 | from_json, |
40 | req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind}, | 40 | req::{self, Decoration, InlayHint, InlayHintsParams}, |
41 | semantic_tokens::SemanticTokensBuilder, | 41 | semantic_tokens::SemanticTokensBuilder, |
42 | world::WorldSnapshot, | 42 | world::WorldSnapshot, |
43 | LspError, Result, | 43 | LspError, Result, |
@@ -1002,10 +1002,7 @@ pub fn handle_inlay_hints( | |||
1002 | .map(|api_type| InlayHint { | 1002 | .map(|api_type| InlayHint { |
1003 | label: api_type.label.to_string(), | 1003 | label: api_type.label.to_string(), |
1004 | range: api_type.range.conv_with(&line_index), | 1004 | range: api_type.range.conv_with(&line_index), |
1005 | kind: match api_type.kind { | 1005 | kind: api_type.kind, |
1006 | ra_ide::InlayKind::TypeHint => InlayKind::TypeHint, | ||
1007 | ra_ide::InlayKind::ParameterHint => InlayKind::ParameterHint, | ||
1008 | }, | ||
1009 | }) | 1006 | }) |
1010 | .collect()) | 1007 | .collect()) |
1011 | } | 1008 | } |
diff --git a/crates/rust-analyzer/src/req.rs b/crates/rust-analyzer/src/req.rs index a3efe3b9f..dab05405e 100644 --- a/crates/rust-analyzer/src/req.rs +++ b/crates/rust-analyzer/src/req.rs | |||
@@ -2,7 +2,9 @@ | |||
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, Serialize}; | 5 | use serde::{Deserialize, Deserializer, Serialize}; |
6 | |||
7 | use ra_ide::{InlayConfig, InlayKind}; | ||
6 | 8 | ||
7 | pub use lsp_types::{ | 9 | pub use lsp_types::{ |
8 | notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, | 10 | notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, |
@@ -196,14 +198,37 @@ pub struct InlayHintsParams { | |||
196 | } | 198 | } |
197 | 199 | ||
198 | #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] | 200 | #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] |
199 | pub enum InlayKind { | 201 | #[serde(remote = "InlayKind")] |
202 | pub enum InlayKindDef { | ||
200 | TypeHint, | 203 | TypeHint, |
201 | ParameterHint, | 204 | ParameterHint, |
202 | } | 205 | } |
203 | 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)] | ||
221 | #[serde(remote = "InlayConfig")] | ||
222 | pub struct InlayConfigDef { | ||
223 | #[serde(deserialize_with = "vec_inlay_kind")] | ||
224 | pub display_type: Vec<InlayKind>, | ||
225 | pub max_length: Option<usize>, | ||
226 | } | ||
227 | |||
204 | #[derive(Debug, Deserialize, Serialize)] | 228 | #[derive(Debug, Deserialize, Serialize)] |
205 | pub struct InlayHint { | 229 | pub struct InlayHint { |
206 | pub range: Range, | 230 | pub range: Range, |
231 | #[serde(with = "InlayKindDef")] | ||
207 | pub kind: InlayKind, | 232 | pub kind: InlayKind, |
208 | pub label: String, | 233 | pub label: String, |
209 | } | 234 | } |