aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/config.rs31
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs7
-rw-r--r--crates/rust-analyzer/src/req.rs29
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
10use ra_ide::{InlayConfig, InlayKind}; 10use crate::req::InlayConfigDef;
11use ra_ide::InlayConfig;
11use rustc_hash::FxHashMap; 12use rustc_hash::FxHashMap;
12 13
13use ra_project_model::CargoFeatures; 14use ra_project_model::CargoFeatures;
14use serde::{Deserialize, Deserializer}; 15use serde::{Deserialize, Deserializer};
15 16
16#[derive(Deserialize)]
17#[serde(remote = "InlayKind")]
18pub 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
25fn vec_inlay_kind<'de, D>(deserializer: D) -> Result<Vec<InlayKind>, D::Error>
26where
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")]
38pub 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
3use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url}; 3use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url};
4use rustc_hash::FxHashMap; 4use rustc_hash::FxHashMap;
5use serde::{Deserialize, Serialize}; 5use serde::{Deserialize, Deserializer, Serialize};
6
7use ra_ide::{InlayConfig, InlayKind};
6 8
7pub use lsp_types::{ 9pub 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)]
199pub enum InlayKind { 201#[serde(remote = "InlayKind")]
202pub 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
209fn vec_inlay_kind<'de, D>(deserializer: D) -> Result<Vec<InlayKind>, D::Error>
210where
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")]
222pub 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)]
205pub struct InlayHint { 229pub 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}