aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/config.rs49
1 files changed, 39 insertions, 10 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 5d3deb232..2adf95185 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -163,6 +163,9 @@ config_data! {
163 /// Whether to show `Run` action. Only applies when 163 /// Whether to show `Run` action. Only applies when
164 /// `#rust-analyzer.hoverActions.enable#` is set. 164 /// `#rust-analyzer.hoverActions.enable#` is set.
165 hoverActions_run: bool = "true", 165 hoverActions_run: bool = "true",
166 #[deprecated = "Use hover.linksInHover instead"]
167 /// Use markdown syntax for links in hover.
168 hoverActions_linksInHover: bool = "false",
166 169
167 /// Whether to show inlay type hints for method chains. 170 /// Whether to show inlay type hints for method chains.
168 inlayHints_chainingHints: bool = "true", 171 inlayHints_chainingHints: bool = "true",
@@ -729,7 +732,7 @@ impl Config {
729 run: self.data.hoverActions_enable && self.data.hoverActions_run, 732 run: self.data.hoverActions_enable && self.data.hoverActions_run,
730 debug: self.data.hoverActions_enable && self.data.hoverActions_debug, 733 debug: self.data.hoverActions_enable && self.data.hoverActions_debug,
731 goto_type_def: self.data.hoverActions_enable && self.data.hoverActions_gotoTypeDef, 734 goto_type_def: self.data.hoverActions_enable && self.data.hoverActions_gotoTypeDef,
732 links_in_hover: self.data.hover_linksInHover, 735 links_in_hover: self.data.hoverActions_linksInHover || self.data.hover_linksInHover,
733 markdown: try_or!( 736 markdown: try_or!(
734 self.caps 737 self.caps
735 .text_document 738 .text_document
@@ -826,6 +829,7 @@ enum WorskpaceSymbolSearchKindDef {
826macro_rules! _config_data { 829macro_rules! _config_data {
827 (struct $name:ident { 830 (struct $name:ident {
828 $( 831 $(
832 $(#[deprecated=$deprecation_msg:literal])?
829 $(#[doc=$doc:literal])* 833 $(#[doc=$doc:literal])*
830 $field:ident $(| $alias:ident)*: $ty:ty = $default:expr, 834 $field:ident $(| $alias:ident)*: $ty:ty = $default:expr,
831 )* 835 )*
@@ -850,7 +854,9 @@ macro_rules! _config_data {
850 $({ 854 $({
851 let field = stringify!($field); 855 let field = stringify!($field);
852 let ty = stringify!($ty); 856 let ty = stringify!($ty);
853 (field, ty, &[$($doc),*], $default) 857 let deprecation_msg = None $( .or(Some($deprecation_msg)) )?;
858
859 (field, ty, &[$($doc),*], $default, deprecation_msg)
854 },)* 860 },)*
855 ]) 861 ])
856 } 862 }
@@ -861,7 +867,9 @@ macro_rules! _config_data {
861 $({ 867 $({
862 let field = stringify!($field); 868 let field = stringify!($field);
863 let ty = stringify!($ty); 869 let ty = stringify!($ty);
864 (field, ty, &[$($doc),*], $default) 870 let deprecation_msg = None $( .or(Some($deprecation_msg)) )?;
871
872 (field, ty, &[$($doc),*], $default, deprecation_msg)
865 },)* 873 },)*
866 ]) 874 ])
867 } 875 }
@@ -891,7 +899,9 @@ fn get_field<T: DeserializeOwned>(
891 .unwrap_or(default) 899 .unwrap_or(default)
892} 900}
893 901
894fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value { 902fn schema(
903 fields: &[(&'static str, &'static str, &[&str], &str, Option<&str>)],
904) -> serde_json::Value {
895 for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) { 905 for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) {
896 fn key(f: &str) -> &str { 906 fn key(f: &str) -> &str {
897 f.splitn(2, '_').next().unwrap() 907 f.splitn(2, '_').next().unwrap()
@@ -901,17 +911,23 @@ fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json:
901 911
902 let map = fields 912 let map = fields
903 .iter() 913 .iter()
904 .map(|(field, ty, doc, default)| { 914 .map(|(field, ty, doc, default, deprecation_msg)| {
905 let name = field.replace("_", "."); 915 let name = field.replace("_", ".");
906 let name = format!("rust-analyzer.{}", name); 916 let name = format!("rust-analyzer.{}", name);
907 let props = field_props(field, ty, doc, default); 917 let props = field_props(field, ty, doc, default, deprecation_msg.as_deref());
908 (name, props) 918 (name, props)
909 }) 919 })
910 .collect::<serde_json::Map<_, _>>(); 920 .collect::<serde_json::Map<_, _>>();
911 map.into() 921 map.into()
912} 922}
913 923
914fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json::Value { 924fn field_props(
925 field: &str,
926 ty: &str,
927 doc: &[&str],
928 default: &str,
929 deprecation_msg: Option<&str>,
930) -> serde_json::Value {
915 let doc = doc_comment_to_string(doc); 931 let doc = doc_comment_to_string(doc);
916 let doc = doc.trim_end_matches('\n'); 932 let doc = doc.trim_end_matches('\n');
917 assert!( 933 assert!(
@@ -930,6 +946,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
930 } 946 }
931 set!("markdownDescription": doc); 947 set!("markdownDescription": doc);
932 set!("default": default); 948 set!("default": default);
949 if let Some(deprecation_msg) = deprecation_msg {
950 set!("deprecationMessage": deprecation_msg);
951 }
933 952
934 match ty { 953 match ty {
935 "bool" => set!("type": "boolean"), 954 "bool" => set!("type": "boolean"),
@@ -1026,13 +1045,23 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
1026} 1045}
1027 1046
1028#[cfg(test)] 1047#[cfg(test)]
1029fn manual(fields: &[(&'static str, &'static str, &[&str], &str)]) -> String { 1048fn manual(fields: &[(&'static str, &'static str, &[&str], &str, Option<&str>)]) -> String {
1030 fields 1049 fields
1031 .iter() 1050 .iter()
1032 .map(|(field, _ty, doc, default)| { 1051 .map(|(field, _ty, doc, default, deprecation_msg)| {
1033 let name = format!("rust-analyzer.{}", field.replace("_", ".")); 1052 let name = format!("rust-analyzer.{}", field.replace("_", "."));
1034 let doc = doc_comment_to_string(*doc); 1053 let doc = doc_comment_to_string(*doc);
1035 format!("[[{}]]{} (default: `{}`)::\n+\n--\n{}--\n", name, name, default, doc) 1054 match deprecation_msg {
1055 Some(deprecation_msg) => {
1056 format!(
1057 "[[{}]]{} (deprecated: `{}`)::\n+\n--\n{}--\n",
1058 name, name, deprecation_msg, doc
1059 )
1060 }
1061 None => {
1062 format!("[[{}]]{} (default: `{}`)::\n+\n--\n{}--\n", name, name, default, doc)
1063 }
1064 }
1036 }) 1065 })
1037 .collect::<String>() 1066 .collect::<String>()
1038} 1067}