]> git.lizzy.rs Git - rust.git/commitdiff
Simpler deserialization
authorAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 12 Mar 2020 17:01:36 +0000 (18:01 +0100)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 12 Mar 2020 17:01:36 +0000 (18:01 +0100)
crates/rust-analyzer/src/config.rs
crates/rust-analyzer/src/conv.rs
crates/rust-analyzer/src/main_loop.rs
crates/rust-analyzer/src/main_loop/handlers.rs
crates/rust-analyzer/src/req.rs
editors/code/src/client.ts

index a6f832ed7c6b97b048ce42cbdcccbf4113d6c1fa..084e17b040c90a6e249870aee22387aa50a68359 100644 (file)
@@ -7,8 +7,6 @@
 //! configure the server itself, feature flags are passed into analysis, and
 //! tweak things like automatic insertion of `()` in completions.
 
-use crate::req::InlayConfigDef;
-use ra_ide::InlayHintsOptions;
 use rustc_hash::FxHashMap;
 
 use ra_project_model::CargoFeatures;
@@ -32,8 +30,11 @@ pub struct ServerConfig {
 
     pub lru_capacity: Option<usize>,
 
-    #[serde(with = "InlayConfigDef")]
-    pub inlay_hints: InlayHintsOptions,
+    #[serde(deserialize_with = "nullable_bool_true")]
+    pub inlay_hints_type: bool,
+    #[serde(deserialize_with = "nullable_bool_true")]
+    pub inlay_hints_parameter: bool,
+    pub inlay_hints_max_length: Option<usize>,
 
     pub cargo_watch_enable: bool,
     pub cargo_watch_args: Vec<String>,
@@ -63,7 +64,9 @@ fn default() -> ServerConfig {
             exclude_globs: Vec::new(),
             use_client_watching: false,
             lru_capacity: None,
-            inlay_hints: Default::default(),
+            inlay_hints_type: true,
+            inlay_hints_parameter: true,
+            inlay_hints_max_length: None,
             cargo_watch_enable: true,
             cargo_watch_args: Vec::new(),
             cargo_watch_command: "check".to_string(),
index a2d68c344e4d50c7bf156a0422bec2b7dd794b29..fd4657d7e507ceb66b58794c74ade680bc4cf944 100644 (file)
@@ -11,8 +11,8 @@
 use ra_ide::{
     translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition,
     FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag,
-    InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo, ReferenceAccess, Severity,
-    SourceChange, SourceFileEdit,
+    InlayHint, InlayKind, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo,
+    ReferenceAccess, Severity, SourceChange, SourceFileEdit,
 };
 use ra_syntax::{SyntaxKind, TextRange, TextUnit};
 use ra_text_edit::{AtomTextEdit, TextEdit};
@@ -323,6 +323,20 @@ fn conv_with(self, ctx: &FoldConvCtx) -> lsp_types::FoldingRange {
     }
 }
 
+impl ConvWith<&LineIndex> for InlayHint {
+    type Output = req::InlayHint;
+    fn conv_with(self, line_index: &LineIndex) -> Self::Output {
+        req::InlayHint {
+            label: self.label.to_string(),
+            range: self.range.conv_with(line_index),
+            kind: match self.kind {
+                InlayKind::ParameterHint => req::InlayKind::ParameterHint,
+                InlayKind::TypeHint => req::InlayKind::TypeHint,
+            },
+        }
+    }
+}
+
 impl Conv for Highlight {
     type Output = (u32, u32);
 
index 495056da3e143c17d67f29bbc69aeac4e4f2bf3b..2b3b16d356be6cd3b03bd8d882b1d49b37a33daa 100644 (file)
@@ -18,7 +18,7 @@
 use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
 use lsp_types::{ClientCapabilities, NumberOrString};
 use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask};
-use ra_ide::{Canceled, FileId, LibraryData, SourceRootId};
+use ra_ide::{Canceled, FileId, InlayHintsOptions, LibraryData, SourceRootId};
 use ra_prof::profile;
 use ra_vfs::{VfsFile, VfsTask, Watch};
 use relative_path::RelativePathBuf;
@@ -177,7 +177,11 @@ pub fn main_loop(
                     .and_then(|it| it.folding_range.as_ref())
                     .and_then(|it| it.line_folding_only)
                     .unwrap_or(false),
-                inlay_hints: config.inlay_hints,
+                inlay_hints: InlayHintsOptions {
+                    type_hints: config.inlay_hints_type,
+                    parameter_hints: config.inlay_hints_parameter,
+                    max_length: config.inlay_hints_max_length,
+                },
                 cargo_watch: CheckOptions {
                     enable: config.cargo_watch_enable,
                     args: config.cargo_watch_args,
index 921990da030dcb05dcb5d0ca86964c6fd26cc8f0..6482f3b771acd1980d67148fbf5f1b035356ef2a 100644 (file)
@@ -999,11 +999,7 @@ pub fn handle_inlay_hints(
     Ok(analysis
         .inlay_hints(file_id, &world.options.inlay_hints)?
         .into_iter()
-        .map(|api_type| InlayHint {
-            label: api_type.label.to_string(),
-            range: api_type.range.conv_with(&line_index),
-            kind: api_type.kind,
-        })
+        .map_conv_with(&line_index)
         .collect())
 }
 
index fa7a42099b5c6159bf6c25f8680eb9d8188139c8..a3efe3b9feb5fbfa2bfa3c83b52558f1e1a6205c 100644 (file)
@@ -4,8 +4,6 @@
 use rustc_hash::FxHashMap;
 use serde::{Deserialize, Serialize};
 
-use ra_ide::{InlayHintsOptions, InlayKind};
-
 pub use lsp_types::{
     notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
     CodeLensParams, CompletionParams, CompletionResponse, DiagnosticTag,
@@ -198,24 +196,14 @@ pub struct InlayHintsParams {
 }
 
 #[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
-#[serde(remote = "InlayKind")]
-pub enum InlayKindDef {
+pub enum InlayKind {
     TypeHint,
     ParameterHint,
 }
 
-#[derive(Deserialize)]
-#[serde(remote = "InlayConfig", rename_all = "camelCase")]
-pub struct InlayConfigDef {
-    pub type_hints: bool,
-    pub parameter_hints: bool,
-    pub max_length: Option<usize>,
-}
-
 #[derive(Debug, Deserialize, Serialize)]
 pub struct InlayHint {
     pub range: Range,
-    #[serde(with = "InlayKindDef")]
     pub kind: InlayKind,
     pub label: String,
 }
index e9f261c2419f042575cf0a00c971af7ada3cf057..b2c830b309af72d8d8c86a7a41c3006fd3f8d0a2 100644 (file)
@@ -29,11 +29,16 @@ export async function createClient(config: Config, serverPath: string): Promise<
         initializationOptions: {
             publishDecorations: !config.highlightingSemanticTokens,
             lruCapacity: config.lruCapacity,
-            inlayHints: config.inlayHints,
+
+            inlayHintsType: config.inlayHints.typeHints,
+            inlayHintsParameter: config.inlayHints.parameterHints,
+            inlayHintsMaxLength: config.inlayHints.maxLength,
+
             cargoWatchEnable: cargoWatchOpts.enable,
             cargoWatchArgs: cargoWatchOpts.arguments,
             cargoWatchCommand: cargoWatchOpts.command,
             cargoWatchAllTargets: cargoWatchOpts.allTargets,
+
             excludeGlobs: config.excludeGlobs,
             useClientWatching: config.useClientWatching,
             featureFlags: config.featureFlags,