Skip to content

Commit b3fa731

Browse files
committed
Simpler deserialization
1 parent fd3ece2 commit b3fa731

File tree

6 files changed

+38
-28
lines changed

6 files changed

+38
-28
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//! configure the server itself, feature flags are passed into analysis, and
88
//! tweak things like automatic insertion of `()` in completions.
99
10-
use crate::req::InlayConfigDef;
11-
use ra_ide::InlayHintsOptions;
1210
use rustc_hash::FxHashMap;
1311

1412
use ra_project_model::CargoFeatures;
@@ -32,8 +30,11 @@ pub struct ServerConfig {
3230

3331
pub lru_capacity: Option<usize>,
3432

35-
#[serde(with = "InlayConfigDef")]
36-
pub inlay_hints: InlayHintsOptions,
33+
#[serde(deserialize_with = "nullable_bool_true")]
34+
pub inlay_hints_type: bool,
35+
#[serde(deserialize_with = "nullable_bool_true")]
36+
pub inlay_hints_parameter: bool,
37+
pub inlay_hints_max_length: Option<usize>,
3738

3839
pub cargo_watch_enable: bool,
3940
pub cargo_watch_args: Vec<String>,
@@ -63,7 +64,9 @@ impl Default for ServerConfig {
6364
exclude_globs: Vec::new(),
6465
use_client_watching: false,
6566
lru_capacity: None,
66-
inlay_hints: Default::default(),
67+
inlay_hints_type: true,
68+
inlay_hints_parameter: true,
69+
inlay_hints_max_length: None,
6770
cargo_watch_enable: true,
6871
cargo_watch_args: Vec::new(),
6972
cargo_watch_command: "check".to_string(),

crates/rust-analyzer/src/conv.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use lsp_types::{
1111
use ra_ide::{
1212
translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition,
1313
FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag,
14-
InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo, ReferenceAccess, Severity,
15-
SourceChange, SourceFileEdit,
14+
InlayHint, InlayKind, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo,
15+
ReferenceAccess, Severity, SourceChange, SourceFileEdit,
1616
};
1717
use ra_syntax::{SyntaxKind, TextRange, TextUnit};
1818
use ra_text_edit::{AtomTextEdit, TextEdit};
@@ -323,6 +323,20 @@ impl ConvWith<&FoldConvCtx<'_>> for Fold {
323323
}
324324
}
325325

326+
impl ConvWith<&LineIndex> for InlayHint {
327+
type Output = req::InlayHint;
328+
fn conv_with(self, line_index: &LineIndex) -> Self::Output {
329+
req::InlayHint {
330+
label: self.label.to_string(),
331+
range: self.range.conv_with(line_index),
332+
kind: match self.kind {
333+
InlayKind::ParameterHint => req::InlayKind::ParameterHint,
334+
InlayKind::TypeHint => req::InlayKind::TypeHint,
335+
},
336+
}
337+
}
338+
}
339+
326340
impl Conv for Highlight {
327341
type Output = (u32, u32);
328342

crates/rust-analyzer/src/main_loop.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crossbeam_channel::{select, unbounded, RecvError, Sender};
1818
use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
1919
use lsp_types::{ClientCapabilities, NumberOrString};
2020
use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask};
21-
use ra_ide::{Canceled, FileId, LibraryData, SourceRootId};
21+
use ra_ide::{Canceled, FileId, InlayHintsOptions, LibraryData, SourceRootId};
2222
use ra_prof::profile;
2323
use ra_vfs::{VfsFile, VfsTask, Watch};
2424
use relative_path::RelativePathBuf;
@@ -177,7 +177,11 @@ pub fn main_loop(
177177
.and_then(|it| it.folding_range.as_ref())
178178
.and_then(|it| it.line_folding_only)
179179
.unwrap_or(false),
180-
inlay_hints: config.inlay_hints,
180+
inlay_hints: InlayHintsOptions {
181+
type_hints: config.inlay_hints_type,
182+
parameter_hints: config.inlay_hints_parameter,
183+
max_length: config.inlay_hints_max_length,
184+
},
181185
cargo_watch: CheckOptions {
182186
enable: config.cargo_watch_enable,
183187
args: config.cargo_watch_args,

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,7 @@ pub fn handle_inlay_hints(
999999
Ok(analysis
10001000
.inlay_hints(file_id, &world.options.inlay_hints)?
10011001
.into_iter()
1002-
.map(|api_type| InlayHint {
1003-
label: api_type.label.to_string(),
1004-
range: api_type.range.conv_with(&line_index),
1005-
kind: api_type.kind,
1006-
})
1002+
.map_conv_with(&line_index)
10071003
.collect())
10081004
}
10091005

crates/rust-analyzer/src/req.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url};
44
use rustc_hash::FxHashMap;
55
use serde::{Deserialize, Serialize};
66

7-
use ra_ide::{InlayHintsOptions, InlayKind};
8-
97
pub use lsp_types::{
108
notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
119
CodeLensParams, CompletionParams, CompletionResponse, DiagnosticTag,
@@ -198,24 +196,14 @@ pub struct InlayHintsParams {
198196
}
199197

200198
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
201-
#[serde(remote = "InlayKind")]
202-
pub enum InlayKindDef {
199+
pub enum InlayKind {
203200
TypeHint,
204201
ParameterHint,
205202
}
206203

207-
#[derive(Deserialize)]
208-
#[serde(remote = "InlayConfig", rename_all = "camelCase")]
209-
pub struct InlayConfigDef {
210-
pub type_hints: bool,
211-
pub parameter_hints: bool,
212-
pub max_length: Option<usize>,
213-
}
214-
215204
#[derive(Debug, Deserialize, Serialize)]
216205
pub struct InlayHint {
217206
pub range: Range,
218-
#[serde(with = "InlayKindDef")]
219207
pub kind: InlayKind,
220208
pub label: String,
221209
}

editors/code/src/client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ export async function createClient(config: Config, serverPath: string): Promise<
2929
initializationOptions: {
3030
publishDecorations: !config.highlightingSemanticTokens,
3131
lruCapacity: config.lruCapacity,
32-
inlayHints: config.inlayHints,
32+
33+
inlayHintsType: config.inlayHints.typeHints,
34+
inlayHintsParameter: config.inlayHints.parameterHints,
35+
inlayHintsMaxLength: config.inlayHints.maxLength,
36+
3337
cargoWatchEnable: cargoWatchOpts.enable,
3438
cargoWatchArgs: cargoWatchOpts.arguments,
3539
cargoWatchCommand: cargoWatchOpts.command,
3640
cargoWatchAllTargets: cargoWatchOpts.allTargets,
41+
3742
excludeGlobs: config.excludeGlobs,
3843
useClientWatching: config.useClientWatching,
3944
featureFlags: config.featureFlags,

0 commit comments

Comments
 (0)