From 1caaa201fa55caaedaa124d23934c178bdf15b18 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 7 Dec 2020 18:49:03 +0100 Subject: Remove hir_def/docs.rs module --- crates/ide/src/hover.rs | 64 +++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'crates/ide/src/hover.rs') diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index dc9621f46..1b6ff6d21 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -1,6 +1,6 @@ use hir::{ - Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, - Module, ModuleDef, ModuleSource, Semantics, + Adt, AsAssocItem, AssocItemContainer, FieldSource, HasAttrs, HasSource, HirDisplay, Module, + ModuleDef, ModuleSource, Semantics, }; use ide_db::base_db::SourceDatabase; use ide_db::{ @@ -319,31 +319,27 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option { let mod_path = definition_mod_path(db, &def); return match def { Definition::Macro(it) => { - let src = it.source(db); - let docs = Documentation::from_ast(&src.value).map(Into::into); - hover_markup(docs, Some(macro_label(&src.value)), mod_path) + let label = macro_label(&it.source(db).value); + from_def_source_labeled(db, it, Some(label), mod_path) } - Definition::Field(it) => { - let src = it.source(db); - match src.value { - FieldSource::Named(it) => { - let docs = Documentation::from_ast(&it).map(Into::into); - hover_markup(docs, it.short_label(), mod_path) - } - _ => None, + Definition::Field(def) => { + let src = def.source(db).value; + if let FieldSource::Named(it) = src { + from_def_source_labeled(db, def, it.short_label(), mod_path) + } else { + None } } Definition::ModuleDef(it) => match it { - ModuleDef::Module(it) => match it.definition_source(db).value { - ModuleSource::Module(it) => { - let docs = Documentation::from_ast(&it).map(Into::into); - hover_markup(docs, it.short_label(), mod_path) - } - ModuleSource::SourceFile(it) => { - let docs = Documentation::from_ast(&it).map(Into::into); - hover_markup(docs, it.short_label(), mod_path) - } - }, + ModuleDef::Module(it) => from_def_source_labeled( + db, + it, + match it.definition_source(db).value { + ModuleSource::Module(it) => it.short_label(), + ModuleSource::SourceFile(it) => it.short_label(), + }, + mod_path, + ), ModuleDef::Function(it) => from_def_source(db, it, mod_path), ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path), ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path), @@ -371,12 +367,24 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option { fn from_def_source(db: &RootDatabase, def: D, mod_path: Option) -> Option where - D: HasSource, - A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel + ast::AttrsOwner, + D: HasSource + HasAttrs + Copy, + A: ShortLabel, + { + let short_label = def.source(db).value.short_label(); + from_def_source_labeled(db, def, short_label, mod_path) + } + + fn from_def_source_labeled( + db: &RootDatabase, + def: D, + short_label: Option, + mod_path: Option, + ) -> Option + where + D: HasAttrs, { - let src = def.source(db); - let docs = Documentation::from_ast(&src.value).map(Into::into); - hover_markup(docs, src.value.short_label(), mod_path) + let docs = def.attrs(db).docs().map(Into::into); + hover_markup(docs, short_label, mod_path) } } -- cgit v1.2.3