Skip to content

Commit 974ed71

Browse files
committed
Deduplicate some Inlay definitions
- Remove match conversion for InlayKind since we're using remote
1 parent cfb48df commit 974ed71

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,13 @@
77
//! configure the server itself, feature flags are passed into analysis, and
88
//! tweak things like automatic insertion of `()` in completions.
99
10-
use ra_ide::{InlayConfig, InlayKind};
10+
use crate::req::InlayConfigDef;
11+
use ra_ide::InlayConfig;
1112
use rustc_hash::FxHashMap;
1213

1314
use ra_project_model::CargoFeatures;
1415
use serde::{Deserialize, Deserializer};
1516

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-
4417
/// Client provided initialization options
4518
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
4619
#[serde(rename_all = "camelCase", default)]

crates/rust-analyzer/src/main_loop/handlers.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::{
3737
},
3838
diagnostics::DiagnosticTask,
3939
from_json,
40-
req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind},
40+
req::{self, Decoration, InlayHint, InlayHintsParams},
4141
semantic_tokens::SemanticTokensBuilder,
4242
world::WorldSnapshot,
4343
LspError, Result,
@@ -1002,10 +1002,7 @@ pub fn handle_inlay_hints(
10021002
.map(|api_type| InlayHint {
10031003
label: api_type.label.to_string(),
10041004
range: api_type.range.conv_with(&line_index),
1005-
kind: match api_type.kind {
1006-
ra_ide::InlayKind::TypeHint => InlayKind::TypeHint,
1007-
ra_ide::InlayKind::ParameterHint => InlayKind::ParameterHint,
1008-
},
1005+
kind: api_type.kind,
10091006
})
10101007
.collect())
10111008
}

crates/rust-analyzer/src/req.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url};
44
use rustc_hash::FxHashMap;
5-
use serde::{Deserialize, Serialize};
5+
use serde::{Deserialize, Deserializer, Serialize};
6+
7+
use ra_ide::{InlayConfig, InlayKind};
68

79
pub use lsp_types::{
810
notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
@@ -196,14 +198,37 @@ pub struct InlayHintsParams {
196198
}
197199

198200
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
199-
pub enum InlayKind {
201+
#[serde(remote = "InlayKind")]
202+
pub enum InlayKindDef {
200203
TypeHint,
201204
ParameterHint,
202205
}
203206

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+
204228
#[derive(Debug, Deserialize, Serialize)]
205229
pub struct InlayHint {
206230
pub range: Range,
231+
#[serde(with = "InlayKindDef")]
207232
pub kind: InlayKind,
208233
pub label: String,
209234
}

0 commit comments

Comments
 (0)