Skip to content

Commit 4227246

Browse files
bors[bot]Veykril
andauthored
Merge #6836
6836: Use Attrs::docs in NavigationTarget instead of DocCommentsOwner r=kjeremy a=Veykril That should be the last place where the AST comment machinery is referred to. Co-authored-by: Lukas Wirth <[email protected]>
2 parents 91bf15a + 8ed8e4f commit 4227246

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

crates/hir_def/src/attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
};
2424

2525
/// Holds documentation
26-
#[derive(Debug, Clone, PartialEq, Eq)]
26+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2727
pub struct Documentation(String);
2828

2929
impl Documentation {

crates/ide/src/display/navigation_target.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
//! FIXME: write short doc here
22
33
use either::Either;
4-
use hir::{AssocItem, FieldSource, HasSource, InFile, ModuleSource};
4+
use hir::{
5+
AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirFileId, InFile, ModuleSource,
6+
};
57
use ide_db::base_db::{FileId, SourceDatabase};
68
use ide_db::{defs::Definition, RootDatabase};
79
use syntax::{
8-
ast::{self, DocCommentsOwner, NameOwner},
10+
ast::{self, NameOwner},
911
match_ast, AstNode, SmolStr,
1012
SyntaxKind::{self, IDENT_PAT, TYPE_PARAM},
1113
TextRange,
@@ -43,7 +45,7 @@ pub struct NavigationTarget {
4345
pub kind: SyntaxKind,
4446
pub container_name: Option<SmolStr>,
4547
pub description: Option<String>,
46-
pub docs: Option<String>,
48+
pub docs: Option<Documentation>,
4749
}
4850

4951
pub(crate) trait ToNav {
@@ -71,7 +73,7 @@ impl NavigationTarget {
7173
frange.range,
7274
src.value.syntax().kind(),
7375
);
74-
res.docs = src.value.doc_comment_text();
76+
res.docs = module.attrs(db).docs();
7577
res.description = src.value.short_label();
7678
return res;
7779
}
@@ -214,14 +216,14 @@ impl ToNavFromAst for hir::Trait {}
214216

215217
impl<D> ToNav for D
216218
where
217-
D: HasSource + ToNavFromAst + Copy,
218-
D::Ast: ast::DocCommentsOwner + ast::NameOwner + ShortLabel,
219+
D: HasSource + ToNavFromAst + Copy + HasAttrs,
220+
D::Ast: ast::NameOwner + ShortLabel,
219221
{
220222
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
221223
let src = self.source(db);
222224
let mut res =
223225
NavigationTarget::from_named(db, src.as_ref().map(|it| it as &dyn ast::NameOwner));
224-
res.docs = src.value.doc_comment_text();
226+
res.docs = self.docs(db);
225227
res.description = src.value.short_label();
226228
res
227229
}
@@ -274,7 +276,7 @@ impl ToNav for hir::Field {
274276
match &src.value {
275277
FieldSource::Named(it) => {
276278
let mut res = NavigationTarget::from_named(db, src.with_value(it));
277-
res.docs = it.doc_comment_text();
279+
res.docs = self.docs(db);
278280
res.description = it.short_label();
279281
res
280282
}
@@ -298,7 +300,7 @@ impl ToNav for hir::MacroDef {
298300
log::debug!("nav target {:#?}", src.value.syntax());
299301
let mut res =
300302
NavigationTarget::from_named(db, src.as_ref().map(|it| it as &dyn ast::NameOwner));
301-
res.docs = src.value.doc_comment_text();
303+
res.docs = self.docs(db);
302304
res
303305
}
304306
}
@@ -374,26 +376,28 @@ impl ToNav for hir::TypeParam {
374376
}
375377
}
376378

377-
pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> {
379+
pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<Documentation> {
378380
let parse = db.parse(symbol.file_id);
379381
let node = symbol.ptr.to_node(parse.tree().syntax());
382+
let file_id = HirFileId::from(symbol.file_id);
380383

381-
match_ast! {
384+
let it = match_ast! {
382385
match node {
383-
ast::Fn(it) => it.doc_comment_text(),
384-
ast::Struct(it) => it.doc_comment_text(),
385-
ast::Enum(it) => it.doc_comment_text(),
386-
ast::Trait(it) => it.doc_comment_text(),
387-
ast::Module(it) => it.doc_comment_text(),
388-
ast::TypeAlias(it) => it.doc_comment_text(),
389-
ast::Const(it) => it.doc_comment_text(),
390-
ast::Static(it) => it.doc_comment_text(),
391-
ast::RecordField(it) => it.doc_comment_text(),
392-
ast::Variant(it) => it.doc_comment_text(),
393-
ast::MacroCall(it) => it.doc_comment_text(),
394-
_ => None,
386+
ast::Fn(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
387+
ast::Struct(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
388+
ast::Enum(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
389+
ast::Trait(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
390+
ast::Module(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
391+
ast::TypeAlias(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
392+
ast::Const(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
393+
ast::Static(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
394+
ast::RecordField(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
395+
ast::Variant(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
396+
ast::MacroCall(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
397+
_ => return None,
395398
}
396-
}
399+
};
400+
it.docs()
397401
}
398402

399403
/// Get a description of a symbol.

0 commit comments

Comments
 (0)