aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/hover.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-12-07 17:49:03 +0000
committerLukas Wirth <[email protected]>2020-12-07 18:58:17 +0000
commit1caaa201fa55caaedaa124d23934c178bdf15b18 (patch)
tree2b4dcb3c1df22ad3bd05034e314ad0a35ca0d2c0 /crates/ide/src/hover.rs
parentb3652ef2886e01f772559aa90df4c45e7c7fb1fd (diff)
Remove hir_def/docs.rs module
Diffstat (limited to 'crates/ide/src/hover.rs')
-rw-r--r--crates/ide/src/hover.rs64
1 files changed, 36 insertions, 28 deletions
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 @@
1use hir::{ 1use hir::{
2 Adt, AsAssocItem, AssocItemContainer, Documentation, FieldSource, HasSource, HirDisplay, 2 Adt, AsAssocItem, AssocItemContainer, FieldSource, HasAttrs, HasSource, HirDisplay, Module,
3 Module, ModuleDef, ModuleSource, Semantics, 3 ModuleDef, ModuleSource, Semantics,
4}; 4};
5use ide_db::base_db::SourceDatabase; 5use ide_db::base_db::SourceDatabase;
6use ide_db::{ 6use ide_db::{
@@ -319,31 +319,27 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
319 let mod_path = definition_mod_path(db, &def); 319 let mod_path = definition_mod_path(db, &def);
320 return match def { 320 return match def {
321 Definition::Macro(it) => { 321 Definition::Macro(it) => {
322 let src = it.source(db); 322 let label = macro_label(&it.source(db).value);
323 let docs = Documentation::from_ast(&src.value).map(Into::into); 323 from_def_source_labeled(db, it, Some(label), mod_path)
324 hover_markup(docs, Some(macro_label(&src.value)), mod_path)
325 } 324 }
326 Definition::Field(it) => { 325 Definition::Field(def) => {
327 let src = it.source(db); 326 let src = def.source(db).value;
328 match src.value { 327 if let FieldSource::Named(it) = src {
329 FieldSource::Named(it) => { 328 from_def_source_labeled(db, def, it.short_label(), mod_path)
330 let docs = Documentation::from_ast(&it).map(Into::into); 329 } else {
331 hover_markup(docs, it.short_label(), mod_path) 330 None
332 }
333 _ => None,
334 } 331 }
335 } 332 }
336 Definition::ModuleDef(it) => match it { 333 Definition::ModuleDef(it) => match it {
337 ModuleDef::Module(it) => match it.definition_source(db).value { 334 ModuleDef::Module(it) => from_def_source_labeled(
338 ModuleSource::Module(it) => { 335 db,
339 let docs = Documentation::from_ast(&it).map(Into::into); 336 it,
340 hover_markup(docs, it.short_label(), mod_path) 337 match it.definition_source(db).value {
341 } 338 ModuleSource::Module(it) => it.short_label(),
342 ModuleSource::SourceFile(it) => { 339 ModuleSource::SourceFile(it) => it.short_label(),
343 let docs = Documentation::from_ast(&it).map(Into::into); 340 },
344 hover_markup(docs, it.short_label(), mod_path) 341 mod_path,
345 } 342 ),
346 },
347 ModuleDef::Function(it) => from_def_source(db, it, mod_path), 343 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
348 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path), 344 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
349 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path), 345 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<Markup> {
371 367
372 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup> 368 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
373 where 369 where
374 D: HasSource<Ast = A>, 370 D: HasSource<Ast = A> + HasAttrs + Copy,
375 A: ast::DocCommentsOwner + ast::NameOwner + ShortLabel + ast::AttrsOwner, 371 A: ShortLabel,
372 {
373 let short_label = def.source(db).value.short_label();
374 from_def_source_labeled(db, def, short_label, mod_path)
375 }
376
377 fn from_def_source_labeled<D>(
378 db: &RootDatabase,
379 def: D,
380 short_label: Option<String>,
381 mod_path: Option<String>,
382 ) -> Option<Markup>
383 where
384 D: HasAttrs,
376 { 385 {
377 let src = def.source(db); 386 let docs = def.attrs(db).docs().map(Into::into);
378 let docs = Documentation::from_ast(&src.value).map(Into::into); 387 hover_markup(docs, short_label, mod_path)
379 hover_markup(docs, src.value.short_label(), mod_path)
380 } 388 }
381} 389}
382 390