Switch from Vec<InlayKind> to object with props

- Instead of a single object type, use several individual nested types
  to allow toggling from the settings GUI
- Remove unused struct definitions
- Install and test that the toggles work
This commit is contained in:
Steffen Lyngbaek
2020-03-11 20:14:39 -07:00
parent 974ed7155a
commit 58248e24cd
11 changed files with 41 additions and 85 deletions

View File

@@ -33,7 +33,7 @@ pub struct ServerConfig {
pub lru_capacity: Option<usize>,
#[serde(with = "InlayConfigDef")]
pub inlay_hint_opts: InlayConfig,
pub inlay_hints: InlayConfig,
pub cargo_watch_enable: bool,
pub cargo_watch_args: Vec<String>,
@@ -60,7 +60,7 @@ impl Default for ServerConfig {
exclude_globs: Vec::new(),
use_client_watching: false,
lru_capacity: None,
inlay_hint_opts: Default::default(),
inlay_hints: Default::default(),
cargo_watch_enable: true,
cargo_watch_args: Vec::new(),
cargo_watch_command: "check".to_string(),

View File

@@ -177,7 +177,7 @@ pub fn main_loop(
.and_then(|it| it.folding_range.as_ref())
.and_then(|it| it.line_folding_only)
.unwrap_or(false),
inlay_hint_opts: config.inlay_hint_opts,
inlay_hints: config.inlay_hints,
cargo_watch: CheckOptions {
enable: config.cargo_watch_enable,
args: config.cargo_watch_args,

View File

@@ -997,7 +997,7 @@ pub fn handle_inlay_hints(
let analysis = world.analysis();
let line_index = analysis.file_line_index(file_id)?;
Ok(analysis
.inlay_hints(file_id, &world.options.inlay_hint_opts)?
.inlay_hints(file_id, &world.options.inlay_hints)?
.into_iter()
.map(|api_type| InlayHint {
label: api_type.label.to_string(),

View File

@@ -2,7 +2,7 @@
use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url};
use rustc_hash::FxHashMap;
use serde::{Deserialize, Deserializer, Serialize};
use serde::{Deserialize, Serialize};
use ra_ide::{InlayConfig, InlayKind};
@@ -204,24 +204,11 @@ pub enum InlayKindDef {
ParameterHint,
}
// Work-around until better serde support is added
// https://github.com/serde-rs/serde/issues/723#issuecomment-382501277
fn vec_inlay_kind<'de, D>(deserializer: D) -> Result<Vec<InlayKind>, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct Wrapper(#[serde(with = "InlayKindDef")] InlayKind);
let v = Vec::deserialize(deserializer)?;
Ok(v.into_iter().map(|Wrapper(a)| a).collect())
}
#[derive(Deserialize)]
#[serde(remote = "InlayConfig")]
#[serde(remote = "InlayConfig", rename_all = "camelCase")]
pub struct InlayConfigDef {
#[serde(deserialize_with = "vec_inlay_kind")]
pub display_type: Vec<InlayKind>,
pub type_hints: bool,
pub parameter_hints: bool,
pub max_length: Option<usize>,
}

View File

@@ -33,7 +33,7 @@ pub struct Options {
pub publish_decorations: bool,
pub supports_location_link: bool,
pub line_folding_only: bool,
pub inlay_hint_opts: InlayConfig,
pub inlay_hints: InlayConfig,
pub rustfmt_args: Vec<String>,
pub cargo_watch: CheckOptions,
}