Skip to content

Commit

Permalink
Add configuration deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jun 14, 2021
1 parent 9043c5d commit 178b5ff
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
49 changes: 39 additions & 10 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ config_data! {
/// Whether to show `Run` action. Only applies when
/// `#rust-analyzer.hoverActions.enable#` is set.
hoverActions_run: bool = "true",
#[deprecated = "Use hover.linksInHover instead"]
/// Use markdown syntax for links in hover.
hoverActions_linksInHover: bool = "false",

/// Whether to show inlay type hints for method chains.
inlayHints_chainingHints: bool = "true",
Expand Down Expand Up @@ -729,7 +732,7 @@ impl Config {
run: self.data.hoverActions_enable && self.data.hoverActions_run,
debug: self.data.hoverActions_enable && self.data.hoverActions_debug,
goto_type_def: self.data.hoverActions_enable && self.data.hoverActions_gotoTypeDef,
links_in_hover: self.data.hover_linksInHover,
links_in_hover: self.data.hoverActions_linksInHover || self.data.hover_linksInHover,
markdown: try_or!(
self.caps
.text_document
Expand Down Expand Up @@ -826,6 +829,7 @@ enum WorskpaceSymbolSearchKindDef {
macro_rules! _config_data {
(struct $name:ident {
$(
$(#[deprecated=$deprecation_msg:literal])?
$(#[doc=$doc:literal])*
$field:ident $(| $alias:ident)*: $ty:ty = $default:expr,
)*
Expand All @@ -850,7 +854,9 @@ macro_rules! _config_data {
$({
let field = stringify!($field);
let ty = stringify!($ty);
(field, ty, &[$($doc),*], $default)
let deprecation_msg = None $( .or(Some($deprecation_msg)) )?;

(field, ty, &[$($doc),*], $default, deprecation_msg)
},)*
])
}
Expand All @@ -861,7 +867,9 @@ macro_rules! _config_data {
$({
let field = stringify!($field);
let ty = stringify!($ty);
(field, ty, &[$($doc),*], $default)
let deprecation_msg = None $( .or(Some($deprecation_msg)) )?;

(field, ty, &[$($doc),*], $default, deprecation_msg)
},)*
])
}
Expand Down Expand Up @@ -891,7 +899,9 @@ fn get_field<T: DeserializeOwned>(
.unwrap_or(default)
}

fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value {
fn schema(
fields: &[(&'static str, &'static str, &[&str], &str, Option<&str>)],
) -> serde_json::Value {
for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) {
fn key(f: &str) -> &str {
f.splitn(2, '_').next().unwrap()
Expand All @@ -901,17 +911,23 @@ fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json:

let map = fields
.iter()
.map(|(field, ty, doc, default)| {
.map(|(field, ty, doc, default, deprecation_msg)| {
let name = field.replace("_", ".");
let name = format!("rust-analyzer.{}", name);
let props = field_props(field, ty, doc, default);
let props = field_props(field, ty, doc, default, deprecation_msg.as_deref());
(name, props)
})
.collect::<serde_json::Map<_, _>>();
map.into()
}

fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json::Value {
fn field_props(
field: &str,
ty: &str,
doc: &[&str],
default: &str,
deprecation_msg: Option<&str>,
) -> serde_json::Value {
let doc = doc_comment_to_string(doc);
let doc = doc.trim_end_matches('\n');
assert!(
Expand All @@ -930,6 +946,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
}
set!("markdownDescription": doc);
set!("default": default);
if let Some(deprecation_msg) = deprecation_msg {
set!("deprecationMessage": deprecation_msg);
}

match ty {
"bool" => set!("type": "boolean"),
Expand Down Expand Up @@ -1026,13 +1045,23 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
}

#[cfg(test)]
fn manual(fields: &[(&'static str, &'static str, &[&str], &str)]) -> String {
fn manual(fields: &[(&'static str, &'static str, &[&str], &str, Option<&str>)]) -> String {
fields
.iter()
.map(|(field, _ty, doc, default)| {
.map(|(field, _ty, doc, default, deprecation_msg)| {
let name = format!("rust-analyzer.{}", field.replace("_", "."));
let doc = doc_comment_to_string(*doc);
format!("[[{}]]{} (default: `{}`)::\n+\n--\n{}--\n", name, name, default, doc)
match deprecation_msg {
Some(deprecation_msg) => {
format!(
"[[{}]]{} (deprecated: `{}`)::\n+\n--\n{}--\n",
name, name, deprecation_msg, doc
)
}
None => {
format!("[[{}]]{} (default: `{}`)::\n+\n--\n{}--\n", name, name, default, doc)
}
}
})
.collect::<String>()
}
Expand Down
5 changes: 5 additions & 0 deletions docs/user/generated_config.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ Whether to show `References` action. Only applies when
Whether to show `Run` action. Only applies when
`#rust-analyzer.hoverActions.enable#` is set.
--
[[rust-analyzer.hoverActions.linksInHover]]rust-analyzer.hoverActions.linksInHover (deprecated: `Use hover.linksInHover instead`)::
+
--
Use markdown syntax for links in hover.
--
[[rust-analyzer.inlayHints.chainingHints]]rust-analyzer.inlayHints.chainingHints (default: `true`)::
+
--
Expand Down
6 changes: 6 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@
"default": true,
"type": "boolean"
},
"rust-analyzer.hoverActions.linksInHover": {
"markdownDescription": "Use markdown syntax for links in hover.",
"default": false,
"deprecationMessage": "Use hover.linksInHover instead",
"type": "boolean"
},
"rust-analyzer.inlayHints.chainingHints": {
"markdownDescription": "Whether to show inlay type hints for method chains.",
"default": true,
Expand Down

0 comments on commit 178b5ff

Please sign in to comment.