aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src
diff options
context:
space:
mode:
authoroxalica <[email protected]>2021-03-15 16:05:03 +0000
committeroxalica <[email protected]>2021-03-15 17:04:33 +0000
commit87171238c6c528c421f06de8cd7e41ed3b6ff57a (patch)
treeb7abccc6adf5df6baae0d97146b9e9b6c5ef7c32 /crates/ide/src
parentef416e0154767619fcbfa0d1682b28bd338a8ce9 (diff)
Use hir formatter more
Diffstat (limited to 'crates/ide/src')
-rw-r--r--crates/ide/src/hover.rs59
1 files changed, 17 insertions, 42 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 1e4c247c0..7328f410a 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -1,7 +1,7 @@
1use either::Either; 1use either::Either;
2use hir::{ 2use hir::{
3 Adt, AsAssocItem, AssocItemContainer, FieldSource, GenericParam, HasAttrs, HasSource, 3 Adt, AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, Module,
4 HirDisplay, Module, ModuleDef, ModuleSource, Semantics, 4 ModuleDef, Semantics,
5}; 5};
6use ide_db::{ 6use ide_db::{
7 base_db::SourceDatabase, 7 base_db::SourceDatabase,
@@ -14,7 +14,7 @@ use stdx::format_to;
14use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T}; 14use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
15 15
16use crate::{ 16use crate::{
17 display::{macro_label, ShortLabel, TryToNav}, 17 display::{macro_label, TryToNav},
18 doc_links::{remove_links, rewrite_links}, 18 doc_links::{remove_links, rewrite_links},
19 markdown_remove::remove_markdown, 19 markdown_remove::remove_markdown,
20 markup::Markup, 20 markup::Markup,
@@ -335,34 +335,18 @@ fn hover_for_definition(
335 let label = macro_label(&it.source(db)?.value); 335 let label = macro_label(&it.source(db)?.value);
336 from_def_source_labeled(db, it, Some(label), mod_path) 336 from_def_source_labeled(db, it, Some(label), mod_path)
337 } 337 }
338 Definition::Field(def) => { 338 Definition::Field(def) => from_hir_fmt(db, def, mod_path),
339 let src = def.source(db)?.value;
340 if let FieldSource::Named(it) = src {
341 from_def_source_labeled(db, def, it.short_label(), mod_path)
342 } else {
343 None
344 }
345 }
346 Definition::ModuleDef(it) => match it { 339 Definition::ModuleDef(it) => match it {
347 ModuleDef::Module(it) => from_def_source_labeled( 340 ModuleDef::Module(it) => from_hir_fmt(db, it, mod_path),
348 db,
349 it,
350 match it.definition_source(db).value {
351 ModuleSource::Module(it) => it.short_label(),
352 ModuleSource::SourceFile(it) => it.short_label(),
353 ModuleSource::BlockExpr(it) => it.short_label(),
354 },
355 mod_path,
356 ),
357 ModuleDef::Function(it) => from_hir_fmt(db, it, mod_path), 341 ModuleDef::Function(it) => from_hir_fmt(db, it, mod_path),
358 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path), 342 ModuleDef::Adt(Adt::Struct(it)) => from_hir_fmt(db, it, mod_path),
359 ModuleDef::Adt(Adt::Union(it)) => from_def_source(db, it, mod_path), 343 ModuleDef::Adt(Adt::Union(it)) => from_hir_fmt(db, it, mod_path),
360 ModuleDef::Adt(Adt::Enum(it)) => from_def_source(db, it, mod_path), 344 ModuleDef::Adt(Adt::Enum(it)) => from_hir_fmt(db, it, mod_path),
361 ModuleDef::Variant(it) => from_def_source(db, it, mod_path), 345 ModuleDef::Variant(it) => from_hir_fmt(db, it, mod_path),
362 ModuleDef::Const(it) => from_def_source(db, it, mod_path), 346 ModuleDef::Const(it) => from_hir_fmt(db, it, mod_path),
363 ModuleDef::Static(it) => from_def_source(db, it, mod_path), 347 ModuleDef::Static(it) => from_hir_fmt(db, it, mod_path),
364 ModuleDef::Trait(it) => from_def_source(db, it, mod_path), 348 ModuleDef::Trait(it) => from_hir_fmt(db, it, mod_path),
365 ModuleDef::TypeAlias(it) => from_def_source(db, it, mod_path), 349 ModuleDef::TypeAlias(it) => from_hir_fmt(db, it, mod_path),
366 ModuleDef::BuiltinType(it) => famous_defs 350 ModuleDef::BuiltinType(it) => famous_defs
367 .and_then(|fd| hover_for_builtin(fd, it)) 351 .and_then(|fd| hover_for_builtin(fd, it))
368 .or_else(|| Some(Markup::fenced_block(&it.name()))), 352 .or_else(|| Some(Markup::fenced_block(&it.name()))),
@@ -370,16 +354,16 @@ fn hover_for_definition(
370 Definition::Local(it) => hover_for_local(it, db), 354 Definition::Local(it) => hover_for_local(it, db),
371 Definition::SelfType(impl_def) => { 355 Definition::SelfType(impl_def) => {
372 impl_def.target_ty(db).as_adt().and_then(|adt| match adt { 356 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
373 Adt::Struct(it) => from_def_source(db, it, mod_path), 357 Adt::Struct(it) => from_hir_fmt(db, it, mod_path),
374 Adt::Union(it) => from_def_source(db, it, mod_path), 358 Adt::Union(it) => from_hir_fmt(db, it, mod_path),
375 Adt::Enum(it) => from_def_source(db, it, mod_path), 359 Adt::Enum(it) => from_hir_fmt(db, it, mod_path),
376 }) 360 })
377 } 361 }
378 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), 362 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
379 Definition::GenericParam(it) => match it { 363 Definition::GenericParam(it) => match it {
380 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))), 364 GenericParam::TypeParam(it) => Some(Markup::fenced_block(&it.display(db))),
381 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))), 365 GenericParam::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
382 GenericParam::ConstParam(it) => from_def_source(db, it, None), 366 GenericParam::ConstParam(it) => Some(Markup::fenced_block(&it.display(db))),
383 }, 367 },
384 }; 368 };
385 369
@@ -391,15 +375,6 @@ fn hover_for_definition(
391 from_def_source_labeled(db, def, Some(label), mod_path) 375 from_def_source_labeled(db, def, Some(label), mod_path)
392 } 376 }
393 377
394 fn from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) -> Option<Markup>
395 where
396 D: HasSource<Ast = A> + HasAttrs + Copy,
397 A: ShortLabel,
398 {
399 let short_label = def.source(db)?.value.short_label();
400 from_def_source_labeled(db, def, short_label, mod_path)
401 }
402
403 fn from_def_source_labeled<D>( 378 fn from_def_source_labeled<D>(
404 db: &RootDatabase, 379 db: &RootDatabase,
405 def: D, 380 def: D,