From a93d166f0fecb748d8cb04aab7f5406bf6308c2d Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 14 Jun 2021 15:25:10 +0200 Subject: Make documentation on hover configurable --- crates/ide/src/hover.rs | 179 +++++++++++++++++------------------ crates/ide/src/lib.rs | 3 +- crates/rust-analyzer/src/config.rs | 10 +- crates/rust-analyzer/src/handlers.rs | 16 ++-- 4 files changed, 105 insertions(+), 103 deletions(-) (limited to 'crates') diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index c08516805..23f2b48b4 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -1,8 +1,5 @@ use either::Either; -use hir::{ - AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, InFile, Module, - ModuleDef, Semantics, -}; +use hir::{AsAssocItem, HasAttrs, HasSource, HirDisplay}; use ide_db::{ base_db::SourceDatabase, defs::{Definition, NameClass, NameRefClass}, @@ -40,6 +37,7 @@ pub struct HoverConfig { pub goto_type_def: bool, pub links_in_hover: bool, pub markdown: bool, + pub documentation: bool, } impl HoverConfig { @@ -51,14 +49,15 @@ impl HoverConfig { goto_type_def: false, links_in_hover: true, markdown: true, + documentation: true, }; - pub fn any(&self) -> bool { + pub fn any_actions(&self) -> bool { self.implementations || self.references || self.runnable() || self.goto_type_def } - pub fn none(&self) -> bool { - !self.any() + pub fn no_actions(&self) -> bool { + !self.any_actions() } pub fn runnable(&self) -> bool { @@ -97,9 +96,10 @@ pub(crate) fn hover( db: &RootDatabase, position: FilePosition, links_in_hover: bool, + documentation: bool, markdown: bool, ) -> Option> { - let sema = Semantics::new(db); + let sema = hir::Semantics::new(db); let file = sema.parse(position.file_id).syntax().clone(); let token = pick_best(file.token_at_offset(position.offset))?; let token = sema.descend_into_macros(token); @@ -131,7 +131,7 @@ pub(crate) fn hover( let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?; let (idl_range, link, ns) = extract_definitions_from_markdown(docs.as_str()).into_iter().find_map(|(range, link, ns)| { - let InFile { file_id, value: range } = doc_mapping.map(range)?; + let hir::InFile { file_id, value: range } = doc_mapping.map(range)?; if file_id == position.file_id.into() && range.contains(position.offset) { Some((range, link, ns)) } else { @@ -151,12 +151,14 @@ pub(crate) fn hover( if let Some(definition) = definition { let famous_defs = match &definition { - Definition::ModuleDef(ModuleDef::BuiltinType(_)) => { + Definition::ModuleDef(hir::ModuleDef::BuiltinType(_)) => { Some(FamousDefs(&sema, sema.scope(&node).krate())) } _ => None, }; - if let Some(markup) = hover_for_definition(db, definition, famous_defs.as_ref()) { + if let Some(markup) = + hover_for_definition(db, definition, famous_defs.as_ref(), documentation) + { res.markup = process_markup(sema.db, definition, &markup, links_in_hover, markdown); if let Some(action) = show_implementations_action(db, definition) { res.actions.push(action); @@ -261,8 +263,10 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option return it.try_to_nav(db).map(to_action), - Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it), + Definition::ModuleDef(hir::ModuleDef::Trait(it)) => { + return it.try_to_nav(db).map(to_action) + } + Definition::ModuleDef(hir::ModuleDef::Adt(it)) => Some(it), Definition::SelfType(it) => it.self_ty(db).as_adt(), _ => None, }?; @@ -271,25 +275,27 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option Option { match def { - Definition::ModuleDef(ModuleDef::Function(it)) => it.try_to_nav(db).map(|nav_target| { - HoverAction::Reference(FilePosition { - file_id: nav_target.file_id, - offset: nav_target.focus_or_full_range().start(), + Definition::ModuleDef(hir::ModuleDef::Function(it)) => { + it.try_to_nav(db).map(|nav_target| { + HoverAction::Reference(FilePosition { + file_id: nav_target.file_id, + offset: nav_target.focus_or_full_range().start(), + }) }) - }), + } _ => None, } } fn runnable_action( - sema: &Semantics, + sema: &hir::Semantics, def: Definition, file_id: FileId, ) -> Option { match def { Definition::ModuleDef(it) => match it { - ModuleDef::Module(it) => runnable_mod(sema, it).map(HoverAction::Runnable), - ModuleDef::Function(func) => { + hir::ModuleDef::Module(it) => runnable_mod(sema, it).map(HoverAction::Runnable), + hir::ModuleDef::Function(func) => { let src = func.source(sema.db)?; if src.file_id != file_id.into() { cov_mark::hit!(hover_macro_generated_struct_fn_doc_comment); @@ -306,19 +312,19 @@ fn runnable_action( } fn goto_type_action(db: &RootDatabase, def: Definition) -> Option { - let mut targets: Vec = Vec::new(); - let mut push_new_def = |item: ModuleDef| { + let mut targets: Vec = Vec::new(); + let mut push_new_def = |item: hir::ModuleDef| { if !targets.contains(&item) { targets.push(item); } }; - if let Definition::GenericParam(GenericParam::TypeParam(it)) = def { + if let Definition::GenericParam(hir::GenericParam::TypeParam(it)) = def { it.trait_bounds(db).into_iter().for_each(|it| push_new_def(it.into())); } else { let ty = match def { Definition::Local(it) => it.ty(db), - Definition::GenericParam(GenericParam::ConstParam(it)) => it.ty(db), + Definition::GenericParam(hir::GenericParam::ConstParam(it)) => it.ty(db), _ => return None, }; @@ -348,29 +354,20 @@ fn goto_type_action(db: &RootDatabase, def: Definition) -> Option { Some(HoverAction::GoToType(targets)) } -fn hover_markup( - docs: Option, - desc: Option, - mod_path: Option, -) -> Option { - match desc { - Some(desc) => { - let mut buf = String::new(); - - if let Some(mod_path) = mod_path { - if !mod_path.is_empty() { - format_to!(buf, "```rust\n{}\n```\n\n", mod_path); - } - } - format_to!(buf, "```rust\n{}\n```", desc); +fn hover_markup(docs: Option, desc: String, mod_path: Option) -> Option { + let mut buf = String::new(); - if let Some(doc) = docs { - format_to!(buf, "\n___\n\n{}", doc); - } - Some(buf.into()) + if let Some(mod_path) = mod_path { + if !mod_path.is_empty() { + format_to!(buf, "```rust\n{}\n```\n\n", mod_path); } - None => docs.map(Markup::from), } + format_to!(buf, "```rust\n{}\n```", desc); + + if let Some(doc) = docs { + format_to!(buf, "\n___\n\n{}", doc); + } + Some(buf.into()) } fn process_markup( @@ -396,11 +393,11 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option Definition::Field(f) => Some(f.parent_def(db).name(db)), Definition::Local(l) => l.parent(db).name(db), Definition::ModuleDef(md) => match md { - ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) { - AssocItemContainer::Trait(t) => Some(t.name(db)), - AssocItemContainer::Impl(i) => i.self_ty(db).as_adt().map(|adt| adt.name(db)), + hir::ModuleDef::Function(f) => match f.as_assoc_item(db)?.container(db) { + hir::AssocItemContainer::Trait(t) => Some(t.name(db)), + hir::AssocItemContainer::Impl(i) => i.self_ty(db).as_adt().map(|adt| adt.name(db)), }, - ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)), + hir::ModuleDef::Variant(e) => Some(e.parent_enum(db).name(db)), _ => None, }, _ => None, @@ -408,7 +405,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option .map(|name| name.to_string()) } -fn render_path(db: &RootDatabase, module: Module, item_name: Option) -> String { +fn render_path(db: &RootDatabase, module: hir::Module, item_name: Option) -> String { let crate_name = db.crate_graph()[module.krate().into()].display_name.as_ref().map(|it| it.to_string()); let module_path = module @@ -420,6 +417,9 @@ fn render_path(db: &RootDatabase, module: Module, item_name: Option) -> } fn definition_mod_path(db: &RootDatabase, def: &Definition) -> Option { + if let Definition::GenericParam(_) = def { + return None; + } def.module(db).map(|module| render_path(db, module, definition_owner_name(db, def))) } @@ -427,60 +427,53 @@ fn hover_for_definition( db: &RootDatabase, def: Definition, famous_defs: Option<&FamousDefs>, + documentation: bool, ) -> Option { let mod_path = definition_mod_path(db, &def); - return match def { + let (label, docs) = match def { Definition::Macro(it) => match &it.source(db)?.value { Either::Left(mac) => { let label = macro_label(mac); - from_def_source_labeled(db, it, Some(label), mod_path) + (label, it.attrs(db).docs()) } Either::Right(_) => { // FIXME - None + return None; } }, - Definition::Field(def) => from_hir_fmt(db, def, mod_path), + Definition::Field(def) => label_and_docs(db, def), Definition::ModuleDef(it) => match it { - ModuleDef::Module(it) => from_hir_fmt(db, it, mod_path), - ModuleDef::Function(it) => from_hir_fmt(db, it, mod_path), - ModuleDef::Adt(it) => from_hir_fmt(db, it, mod_path), - ModuleDef::Variant(it) => from_hir_fmt(db, it, mod_path), - ModuleDef::Const(it) => from_hir_fmt(db, it, mod_path), - ModuleDef::Static(it) => from_hir_fmt(db, it, mod_path), - ModuleDef::Trait(it) => from_hir_fmt(db, it, mod_path), - ModuleDef::TypeAlias(it) => from_hir_fmt(db, it, mod_path), - ModuleDef::BuiltinType(it) => famous_defs - .and_then(|fd| hover_for_builtin(fd, it)) - .or_else(|| Some(Markup::fenced_block(&it.name()))), + hir::ModuleDef::Module(it) => label_and_docs(db, it), + hir::ModuleDef::Function(it) => label_and_docs(db, it), + hir::ModuleDef::Adt(it) => label_and_docs(db, it), + hir::ModuleDef::Variant(it) => label_and_docs(db, it), + hir::ModuleDef::Const(it) => label_and_docs(db, it), + hir::ModuleDef::Static(it) => label_and_docs(db, it), + hir::ModuleDef::Trait(it) => label_and_docs(db, it), + hir::ModuleDef::TypeAlias(it) => label_and_docs(db, it), + hir::ModuleDef::BuiltinType(it) => { + return famous_defs + .and_then(|fd| hover_for_builtin(fd, it)) + .or_else(|| Some(Markup::fenced_block(&it.name()))) + } }, - Definition::Local(it) => hover_for_local(it, db), + Definition::Local(it) => return hover_for_local(it, db), Definition::SelfType(impl_def) => { - impl_def.self_ty(db).as_adt().and_then(|adt| from_hir_fmt(db, adt, mod_path)) + impl_def.self_ty(db).as_adt().map(|adt| label_and_docs(db, adt))? } - Definition::GenericParam(it) => from_hir_fmt(db, it, None), - Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), + Definition::GenericParam(it) => label_and_docs(db, it), + Definition::Label(it) => return Some(Markup::fenced_block(&it.name(db))), }; - fn from_hir_fmt(db: &RootDatabase, def: D, mod_path: Option) -> Option + return hover_markup(docs.filter(|_| documentation).map(Into::into), label, mod_path); + + fn label_and_docs(db: &RootDatabase, def: D) -> (String, Option) where D: HasAttrs + HirDisplay, { let label = def.display(db).to_string(); - from_def_source_labeled(db, def, Some(label), mod_path) - } - - fn from_def_source_labeled( - db: &RootDatabase, - def: D, - short_label: Option, - mod_path: Option, - ) -> Option - where - D: HasAttrs, - { - let docs = def.attrs(db).docs().map(Into::into); - hover_markup(docs, short_label, mod_path) + let docs = def.attrs(db).docs(); + (label, docs) } } @@ -504,11 +497,11 @@ fn hover_for_local(it: hir::Local, db: &RootDatabase) -> Option { } Either::Right(_) => format!("{}self: {}", is_mut, ty), }; - hover_markup(None, Some(desc), None) + hover_markup(None, desc, None) } fn hover_for_keyword( - sema: &Semantics, + sema: &hir::Semantics, links_in_hover: bool, markdown: bool, token: &SyntaxToken, @@ -524,7 +517,7 @@ fn hover_for_keyword( let markup = process_markup( sema.db, Definition::ModuleDef(doc_owner.into()), - &hover_markup(Some(docs.into()), Some(token.text().into()), None)?, + &hover_markup(Some(docs.into()), token.text().into(), None)?, links_in_hover, markdown, ); @@ -536,7 +529,7 @@ fn hover_for_builtin(famous_defs: &FamousDefs, builtin: hir::BuiltinType) -> Opt let primitive_mod = format!("prim_{}", builtin.name()); let doc_owner = find_std_module(famous_defs, &primitive_mod)?; let docs = doc_owner.attrs(famous_defs.0.db).docs()?; - hover_markup(Some(docs.into()), Some(builtin.name().to_string()), None) + hover_markup(Some(docs.into()), builtin.name().to_string(), None) } fn find_std_module(famous_defs: &FamousDefs, name: &str) -> Option { @@ -572,12 +565,12 @@ mod tests { fn check_hover_no_result(ra_fixture: &str) { let (analysis, position) = fixture::position(ra_fixture); - assert!(analysis.hover(position, true, true).unwrap().is_none()); + assert!(analysis.hover(position, true, true, true).unwrap().is_none()); } fn check(ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); - let hover = analysis.hover(position, true, true).unwrap().unwrap(); + let hover = analysis.hover(position, true, true, true).unwrap().unwrap(); let content = analysis.db.file_text(position.file_id); let hovered_element = &content[hover.range]; @@ -588,7 +581,7 @@ mod tests { fn check_hover_no_links(ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); - let hover = analysis.hover(position, false, true).unwrap().unwrap(); + let hover = analysis.hover(position, false, true, true).unwrap().unwrap(); let content = analysis.db.file_text(position.file_id); let hovered_element = &content[hover.range]; @@ -599,7 +592,7 @@ mod tests { fn check_hover_no_markdown(ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); - let hover = analysis.hover(position, true, false).unwrap().unwrap(); + let hover = analysis.hover(position, true, true, false).unwrap().unwrap(); let content = analysis.db.file_text(position.file_id); let hovered_element = &content[hover.range]; @@ -610,7 +603,7 @@ mod tests { fn check_actions(ra_fixture: &str, expect: Expect) { let (analysis, position) = fixture::position(ra_fixture); - let hover = analysis.hover(position, true, true).unwrap().unwrap(); + let hover = analysis.hover(position, true, true, true).unwrap().unwrap(); expect.assert_debug_eq(&hover.info.actions) } diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 0511efae3..8d0270319 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -407,9 +407,10 @@ impl Analysis { &self, position: FilePosition, links_in_hover: bool, + documentation: bool, markdown: bool, ) -> Cancellable>> { - self.with_db(|db| hover::hover(db, position, links_in_hover, markdown)) + self.with_db(|db| hover::hover(db, position, links_in_hover, documentation, markdown)) } /// Return URL(s) for the documentation of the symbol under the cursor. diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 3b20d741a..5d3deb232 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -141,6 +141,11 @@ config_data! { /// their contents. highlighting_strings: bool = "true", + /// Whether to show documentation on hover. + hover_documentation: bool = "true", + /// Use markdown syntax for links in hover. + hover_linksInHover: bool = "true", + /// Whether to show `Debug` action. Only applies when /// `#rust-analyzer.hoverActions.enable#` is set. hoverActions_debug: bool = "true", @@ -158,8 +163,6 @@ config_data! { /// Whether to show `Run` action. Only applies when /// `#rust-analyzer.hoverActions.enable#` is set. hoverActions_run: bool = "true", - /// Use markdown syntax for links in hover. - hoverActions_linksInHover: bool = "true", /// Whether to show inlay type hints for method chains. inlayHints_chainingHints: bool = "true", @@ -726,7 +729,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.hoverActions_linksInHover, + links_in_hover: self.data.hover_linksInHover, markdown: try_or!( self.caps .text_document @@ -739,6 +742,7 @@ impl Config { &[] ) .contains(&MarkupKind::Markdown), + documentation: self.data.hover_documentation, } } diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index ccf66294f..eff1e6c93 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -862,11 +862,15 @@ pub(crate) fn handle_hover( let _p = profile::span("handle_hover"); let position = from_proto::file_position(&snap, params.text_document_position_params)?; let hover_config = snap.config.hover(); - let info = - match snap.analysis.hover(position, hover_config.links_in_hover, hover_config.markdown)? { - None => return Ok(None), - Some(info) => info, - }; + let info = match snap.analysis.hover( + position, + hover_config.links_in_hover, + hover_config.documentation, + hover_config.markdown, + )? { + None => return Ok(None), + Some(info) => info, + }; let line_index = snap.file_line_index(position.file_id)?; let range = to_proto::range(&line_index, info.range); let hover = lsp_ext::Hover { @@ -1587,7 +1591,7 @@ fn prepare_hover_actions( snap: &GlobalStateSnapshot, actions: &[HoverAction], ) -> Vec { - if snap.config.hover().none() || !snap.config.hover_actions() { + if snap.config.hover().no_actions() || !snap.config.hover_actions() { return Vec::new(); } -- cgit v1.2.3 From 9043c5db864ef9bffb4e5e403cf091b073133b40 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 14 Jun 2021 15:31:14 +0200 Subject: Don't ignore hover documentation setting for keyword hovers --- crates/ide/src/hover.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 23f2b48b4..7b9336d38 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -181,7 +181,8 @@ pub(crate) fn hover( } } - if let res @ Some(_) = hover_for_keyword(&sema, links_in_hover, markdown, &token) { + if let res @ Some(_) = hover_for_keyword(&sema, links_in_hover, markdown, documentation, &token) + { return res; } @@ -504,9 +505,10 @@ fn hover_for_keyword( sema: &hir::Semantics, links_in_hover: bool, markdown: bool, + documentation: bool, token: &SyntaxToken, ) -> Option> { - if !token.kind().is_keyword() { + if !token.kind().is_keyword() || documentation { return None; } let famous_defs = FamousDefs(sema, sema.scope(&token.parent()?).krate()); -- cgit v1.2.3 From 178b5ffba316164fba86b86a67e9402b226fbc48 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 14 Jun 2021 15:44:32 +0200 Subject: Add configuration deprecation --- crates/rust-analyzer/src/config.rs | 49 ++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'crates') 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! { /// 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", @@ -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 @@ -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, )* @@ -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) },)* ]) } @@ -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) },)* ]) } @@ -891,7 +899,9 @@ fn get_field( .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() @@ -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::>(); 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!( @@ -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"), @@ -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::() } -- cgit v1.2.3 From c7c2eb8b0885198f9b1a5e44ca49c2289128d27d Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 14 Jun 2021 18:01:38 +0200 Subject: typo --- crates/ide/src/hover.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 7b9336d38..4e1ab534b 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -508,7 +508,7 @@ fn hover_for_keyword( documentation: bool, token: &SyntaxToken, ) -> Option> { - if !token.kind().is_keyword() || documentation { + if !token.kind().is_keyword() || !documentation { return None; } let famous_defs = FamousDefs(sema, sema.scope(&token.parent()?).krate()); -- cgit v1.2.3 From 43098d99ae9ee3d102ce54510d7885bae58e5ac7 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 21 Jun 2021 16:01:03 +0200 Subject: Remove deprecation support in config --- crates/rust-analyzer/src/config.rs | 52 ++++++++++---------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) (limited to 'crates') diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 2adf95185..fa72a9bfb 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -142,9 +142,10 @@ config_data! { highlighting_strings: bool = "true", /// Whether to show documentation on hover. - hover_documentation: bool = "true", + hover_documentation: bool = "true", /// Use markdown syntax for links in hover. - hover_linksInHover: bool = "true", + hover_linksInHover | + hoverActions_linksInHover: bool = "true", /// Whether to show `Debug` action. Only applies when /// `#rust-analyzer.hoverActions.enable#` is set. @@ -163,9 +164,6 @@ 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", @@ -732,7 +730,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.hoverActions_linksInHover || self.data.hover_linksInHover, + links_in_hover: self.data.hover_linksInHover, markdown: try_or!( self.caps .text_document @@ -829,7 +827,6 @@ enum WorskpaceSymbolSearchKindDef { macro_rules! _config_data { (struct $name:ident { $( - $(#[deprecated=$deprecation_msg:literal])? $(#[doc=$doc:literal])* $field:ident $(| $alias:ident)*: $ty:ty = $default:expr, )* @@ -854,9 +851,8 @@ macro_rules! _config_data { $({ let field = stringify!($field); let ty = stringify!($ty); - let deprecation_msg = None $( .or(Some($deprecation_msg)) )?; - (field, ty, &[$($doc),*], $default, deprecation_msg) + (field, ty, &[$($doc),*], $default) },)* ]) } @@ -867,9 +863,8 @@ macro_rules! _config_data { $({ let field = stringify!($field); let ty = stringify!($ty); - let deprecation_msg = None $( .or(Some($deprecation_msg)) )?; - (field, ty, &[$($doc),*], $default, deprecation_msg) + (field, ty, &[$($doc),*], $default) },)* ]) } @@ -899,9 +894,7 @@ fn get_field( .unwrap_or(default) } -fn schema( - fields: &[(&'static str, &'static str, &[&str], &str, Option<&str>)], -) -> serde_json::Value { +fn schema(fields: &[(&'static str, &'static str, &[&str], &str)]) -> serde_json::Value { for ((f1, ..), (f2, ..)) in fields.iter().zip(&fields[1..]) { fn key(f: &str) -> &str { f.splitn(2, '_').next().unwrap() @@ -911,23 +904,17 @@ fn schema( let map = fields .iter() - .map(|(field, ty, doc, default, deprecation_msg)| { + .map(|(field, ty, doc, default)| { let name = field.replace("_", "."); let name = format!("rust-analyzer.{}", name); - let props = field_props(field, ty, doc, default, deprecation_msg.as_deref()); + let props = field_props(field, ty, doc, default); (name, props) }) .collect::>(); map.into() } -fn field_props( - field: &str, - ty: &str, - doc: &[&str], - default: &str, - deprecation_msg: Option<&str>, -) -> serde_json::Value { +fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json::Value { let doc = doc_comment_to_string(doc); let doc = doc.trim_end_matches('\n'); assert!( @@ -946,9 +933,6 @@ fn field_props( } set!("markdownDescription": doc); set!("default": default); - if let Some(deprecation_msg) = deprecation_msg { - set!("deprecationMessage": deprecation_msg); - } match ty { "bool" => set!("type": "boolean"), @@ -1045,23 +1029,13 @@ fn field_props( } #[cfg(test)] -fn manual(fields: &[(&'static str, &'static str, &[&str], &str, Option<&str>)]) -> String { +fn manual(fields: &[(&'static str, &'static str, &[&str], &str)]) -> String { fields .iter() - .map(|(field, _ty, doc, default, deprecation_msg)| { + .map(|(field, _ty, doc, default)| { let name = format!("rust-analyzer.{}", field.replace("_", ".")); let doc = doc_comment_to_string(*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) - } - } + format!("[[{}]]{} (default: `{}`)::\n+\n--\n{}--\n", name, name, default, doc) }) .collect::() } -- cgit v1.2.3