use Source for MacroDef

This commit is contained in:
Aleksey Kladov 2019-06-11 17:40:18 +03:00
parent a6e339e822
commit 8b94b429e5
4 changed files with 18 additions and 13 deletions

View file

@ -1003,12 +1003,17 @@ pub struct MacroDef {
pub(crate) id: MacroDefId,
}
impl HasSource for MacroDef {
type Ast = TreeArc<ast::MacroCall>;
fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::MacroCall>> {
(self.id.0.file_id(), self.id.0.to_node(db)).into()
}
}
impl MacroDef {
pub fn source(
&self,
db: &(impl DefDatabase + AstDatabase),
) -> (HirFileId, TreeArc<ast::MacroCall>) {
(self.id.0.file_id(), self.id.0.to_node(db))
pub fn source(&self, db: &(impl DefDatabase + AstDatabase)) -> Source<TreeArc<ast::MacroCall>> {
(self.id.0.file_id(), self.id.0.to_node(db)).into()
}
}

View file

@ -85,7 +85,7 @@ pub(crate) fn documentation_query(
DocDef::Union(it) => docs_from_ast(&*it.source(db).ast),
DocDef::Trait(it) => docs_from_ast(&*it.source(db).ast),
DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).ast),
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1),
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).ast),
}
}

View file

@ -248,12 +248,12 @@ impl NavigationTarget {
}
pub(crate) fn from_macro_def(db: &RootDatabase, macro_call: hir::MacroDef) -> NavigationTarget {
let (file_id, node) = macro_call.source(db);
log::debug!("nav target {}", node.syntax().debug_dump());
let src = macro_call.source(db);
log::debug!("nav target {}", src.ast.syntax().debug_dump());
NavigationTarget::from_named(
file_id.original_file(db),
&*node,
node.doc_comment_text(),
src.file_id.original_file(db),
&*src.ast,
src.ast.doc_comment_text(),
None,
)
}

View file

@ -98,8 +98,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
match classify_name_ref(db, &analyzer, name_ref) {
Some(Method(it)) => res.extend(from_def_source(db, it)),
Some(Macro(it)) => {
let it = it.source(db).1;
res.extend(hover_text(it.doc_comment_text(), None));
let src = it.source(db);
res.extend(hover_text(src.ast.doc_comment_text(), None));
}
Some(FieldAccess(it)) => {
let it = it.source(db).1;