mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
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 <lukastw97@gmail.com>
This commit is contained in:
commit
4227246948
@ -23,7 +23,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Holds documentation
|
/// Holds documentation
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct Documentation(String);
|
pub struct Documentation(String);
|
||||||
|
|
||||||
impl Documentation {
|
impl Documentation {
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{AssocItem, FieldSource, HasSource, InFile, ModuleSource};
|
use hir::{
|
||||||
|
AssocItem, Documentation, FieldSource, HasAttrs, HasSource, HirFileId, InFile, ModuleSource,
|
||||||
|
};
|
||||||
use ide_db::base_db::{FileId, SourceDatabase};
|
use ide_db::base_db::{FileId, SourceDatabase};
|
||||||
use ide_db::{defs::Definition, RootDatabase};
|
use ide_db::{defs::Definition, RootDatabase};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, DocCommentsOwner, NameOwner},
|
ast::{self, NameOwner},
|
||||||
match_ast, AstNode, SmolStr,
|
match_ast, AstNode, SmolStr,
|
||||||
SyntaxKind::{self, IDENT_PAT, TYPE_PARAM},
|
SyntaxKind::{self, IDENT_PAT, TYPE_PARAM},
|
||||||
TextRange,
|
TextRange,
|
||||||
@ -43,7 +45,7 @@ pub struct NavigationTarget {
|
|||||||
pub kind: SyntaxKind,
|
pub kind: SyntaxKind,
|
||||||
pub container_name: Option<SmolStr>,
|
pub container_name: Option<SmolStr>,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub docs: Option<String>,
|
pub docs: Option<Documentation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait ToNav {
|
pub(crate) trait ToNav {
|
||||||
@ -71,7 +73,7 @@ impl NavigationTarget {
|
|||||||
frange.range,
|
frange.range,
|
||||||
src.value.syntax().kind(),
|
src.value.syntax().kind(),
|
||||||
);
|
);
|
||||||
res.docs = src.value.doc_comment_text();
|
res.docs = module.attrs(db).docs();
|
||||||
res.description = src.value.short_label();
|
res.description = src.value.short_label();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -214,14 +216,14 @@ impl ToNavFromAst for hir::Trait {}
|
|||||||
|
|
||||||
impl<D> ToNav for D
|
impl<D> ToNav for D
|
||||||
where
|
where
|
||||||
D: HasSource + ToNavFromAst + Copy,
|
D: HasSource + ToNavFromAst + Copy + HasAttrs,
|
||||||
D::Ast: ast::DocCommentsOwner + ast::NameOwner + ShortLabel,
|
D::Ast: ast::NameOwner + ShortLabel,
|
||||||
{
|
{
|
||||||
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
|
||||||
let src = self.source(db);
|
let src = self.source(db);
|
||||||
let mut res =
|
let mut res =
|
||||||
NavigationTarget::from_named(db, src.as_ref().map(|it| it as &dyn ast::NameOwner));
|
NavigationTarget::from_named(db, src.as_ref().map(|it| it as &dyn ast::NameOwner));
|
||||||
res.docs = src.value.doc_comment_text();
|
res.docs = self.docs(db);
|
||||||
res.description = src.value.short_label();
|
res.description = src.value.short_label();
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
@ -274,7 +276,7 @@ impl ToNav for hir::Field {
|
|||||||
match &src.value {
|
match &src.value {
|
||||||
FieldSource::Named(it) => {
|
FieldSource::Named(it) => {
|
||||||
let mut res = NavigationTarget::from_named(db, src.with_value(it));
|
let mut res = NavigationTarget::from_named(db, src.with_value(it));
|
||||||
res.docs = it.doc_comment_text();
|
res.docs = self.docs(db);
|
||||||
res.description = it.short_label();
|
res.description = it.short_label();
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
@ -298,7 +300,7 @@ impl ToNav for hir::MacroDef {
|
|||||||
log::debug!("nav target {:#?}", src.value.syntax());
|
log::debug!("nav target {:#?}", src.value.syntax());
|
||||||
let mut res =
|
let mut res =
|
||||||
NavigationTarget::from_named(db, src.as_ref().map(|it| it as &dyn ast::NameOwner));
|
NavigationTarget::from_named(db, src.as_ref().map(|it| it as &dyn ast::NameOwner));
|
||||||
res.docs = src.value.doc_comment_text();
|
res.docs = self.docs(db);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -374,26 +376,28 @@ impl ToNav for hir::TypeParam {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> {
|
pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<Documentation> {
|
||||||
let parse = db.parse(symbol.file_id);
|
let parse = db.parse(symbol.file_id);
|
||||||
let node = symbol.ptr.to_node(parse.tree().syntax());
|
let node = symbol.ptr.to_node(parse.tree().syntax());
|
||||||
|
let file_id = HirFileId::from(symbol.file_id);
|
||||||
|
|
||||||
match_ast! {
|
let it = match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::Fn(it) => it.doc_comment_text(),
|
ast::Fn(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::Struct(it) => it.doc_comment_text(),
|
ast::Struct(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::Enum(it) => it.doc_comment_text(),
|
ast::Enum(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::Trait(it) => it.doc_comment_text(),
|
ast::Trait(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::Module(it) => it.doc_comment_text(),
|
ast::Module(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::TypeAlias(it) => it.doc_comment_text(),
|
ast::TypeAlias(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::Const(it) => it.doc_comment_text(),
|
ast::Const(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::Static(it) => it.doc_comment_text(),
|
ast::Static(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::RecordField(it) => it.doc_comment_text(),
|
ast::RecordField(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::Variant(it) => it.doc_comment_text(),
|
ast::Variant(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
ast::MacroCall(it) => it.doc_comment_text(),
|
ast::MacroCall(it) => hir::Attrs::from_attrs_owner(db, InFile::new(file_id, &it)),
|
||||||
_ => None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
it.docs()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a description of a symbol.
|
/// Get a description of a symbol.
|
||||||
|
Loading…
Reference in New Issue
Block a user