From b45dd9ef54c668b714c6fc41bc42d415ed772f32 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 25 Aug 2020 12:13:31 +0200 Subject: Use the same abstraction for attrs and docs Doc comments *are* attributes, so there's no reason to have two crates here. --- crates/hir/src/code_model.rs | 11 +++-------- crates/hir/src/lib.rs | 2 +- crates/ide/src/call_info.rs | 2 +- crates/ide/src/completion/complete_trait_impl.rs | 2 +- crates/ide/src/completion/presentation.rs | 2 +- 5 files changed, 7 insertions(+), 12 deletions(-) (limited to 'crates') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 94dd7f6f5..e553fc7dc 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -1771,6 +1771,7 @@ impl_from!( pub trait HasAttrs { fn attrs(self, db: &dyn HirDatabase) -> Attrs; + fn docs(self, db: &dyn HirDatabase) -> Option; } impl> HasAttrs for T { @@ -1778,14 +1779,8 @@ impl> HasAttrs for T { let def: AttrDef = self.into(); db.attrs(def.into()) } -} - -pub trait Docs { - fn docs(&self, db: &dyn HirDatabase) -> Option; -} -impl + Copy> Docs for T { - fn docs(&self, db: &dyn HirDatabase) -> Option { - let def: AttrDef = (*self).into(); + fn docs(self, db: &dyn HirDatabase) -> Option { + let def: AttrDef = self.into(); db.documentation(def.into()) } } diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index d1f4d7813..2326e3fbb 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -34,7 +34,7 @@ mod has_source; pub use crate::{ code_model::{ Access, Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrDef, Callable, CallableKind, - Const, Crate, CrateDependency, DefWithBody, Docs, Enum, EnumVariant, Field, FieldSource, + Const, Crate, CrateDependency, DefWithBody, Enum, EnumVariant, Field, FieldSource, Function, GenericDef, HasAttrs, HasVisibility, ImplDef, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, Visibility, }, diff --git a/crates/ide/src/call_info.rs b/crates/ide/src/call_info.rs index 7e83a2381..7e99c6b72 100644 --- a/crates/ide/src/call_info.rs +++ b/crates/ide/src/call_info.rs @@ -1,6 +1,6 @@ //! FIXME: write short doc here use either::Either; -use hir::{Docs, HirDisplay, Semantics, Type}; +use hir::{HasAttrs, HirDisplay, Semantics, Type}; use ide_db::RootDatabase; use stdx::format_to; use syntax::{ diff --git a/crates/ide/src/completion/complete_trait_impl.rs b/crates/ide/src/completion/complete_trait_impl.rs index 1a2b1e8a5..26f268bd1 100644 --- a/crates/ide/src/completion/complete_trait_impl.rs +++ b/crates/ide/src/completion/complete_trait_impl.rs @@ -32,7 +32,7 @@ //! ``` use assists::utils::get_missing_assoc_items; -use hir::{self, Docs, HasSource}; +use hir::{self, HasAttrs, HasSource}; use syntax::{ ast::{self, edit, Impl}, AstNode, SyntaxKind, SyntaxNode, TextRange, T, diff --git a/crates/ide/src/completion/presentation.rs b/crates/ide/src/completion/presentation.rs index 3371aed2d..24c507f9b 100644 --- a/crates/ide/src/completion/presentation.rs +++ b/crates/ide/src/completion/presentation.rs @@ -1,7 +1,7 @@ //! This modules takes care of rendering various definitions as completion items. //! It also handles scoring (sorting) completions. -use hir::{Docs, HasAttrs, HasSource, HirDisplay, ModPath, ScopeDef, StructKind, Type}; +use hir::{HasAttrs, HasSource, HirDisplay, ModPath, ScopeDef, StructKind, Type}; use itertools::Itertools; use syntax::ast::NameOwner; use test_utils::mark; -- cgit v1.2.3