one macro def should be enough

This commit is contained in:
Aleksey Kladov 2019-06-08 14:48:56 +03:00
parent 2c28f5245d
commit 1b783e33e9
6 changed files with 25 additions and 33 deletions

View file

@ -939,6 +939,15 @@ pub struct MacroDef {
pub(crate) id: MacroDefId,
}
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 enum Container {
Trait(Trait),
ImplBlock(ImplBlock),

View file

@ -4,7 +4,7 @@ use ra_syntax::ast;
use crate::{
HirDatabase, DefDatabase, AstDatabase,
Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource
Module, StructField, Struct, Enum, EnumVariant, Static, Const, Function, Union, Trait, TypeAlias, FieldSource, MacroDef,
};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@ -20,6 +20,7 @@ pub enum DocDef {
Union(Union),
Trait(Trait),
TypeAlias(TypeAlias),
MacroDef(MacroDef),
}
impl_froms!(
@ -33,7 +34,8 @@ impl_froms!(
Function,
Union,
Trait,
TypeAlias
TypeAlias,
MacroDef
);
/// Holds documentation
@ -83,6 +85,7 @@ pub(crate) fn documentation_query(
DocDef::Union(it) => docs_from_ast(&*it.source(db).1),
DocDef::Trait(it) => docs_from_ast(&*it.source(db).1),
DocDef::TypeAlias(it) => docs_from_ast(&*it.source(db).1),
DocDef::MacroDef(it) => docs_from_ast(&*it.source(db).1),
}
}

View file

@ -69,7 +69,7 @@ pub use self::{
expr::ExprScopes,
resolve::Resolution,
generics::{GenericParams, GenericParam, HasGenericParams},
source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax,MacroByExampleDef},
source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax},
};
pub use self::code_model::{

View file

@ -10,7 +10,7 @@ use std::sync::Arc;
use rustc_hash::{FxHashSet, FxHashMap};
use ra_db::{FileId, FilePosition};
use ra_syntax::{
SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange,TreeArc,
SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange,
ast::{self, AstNode, NameOwner},
algo::find_node_at_offset,
SyntaxKind::*,
@ -18,10 +18,9 @@ use ra_syntax::{
use crate::{
HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name,
AsName, Module, HirFileId, Crate, Trait, Resolver, Ty,Path,
AsName, Module, HirFileId, Crate, Trait, Resolver, Ty, Path, MacroDef,
expr::{BodySourceMap, scope::{ScopeId, ExprScopes}},
ids::{LocationCtx, MacroDefId},
docs::{docs_from_ast,Documentation},
ids::LocationCtx,
expr, AstId,
};
@ -182,27 +181,10 @@ pub enum PathResolution {
/// A generic parameter
GenericParam(u32),
SelfType(crate::ImplBlock),
Macro(MacroByExampleDef),
Macro(MacroDef),
AssocItem(crate::ImplItem),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct MacroByExampleDef {
pub(crate) id: MacroDefId,
}
impl MacroByExampleDef {
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::MacroCall>) {
(self.id.0.file_id(), self.id.0.to_node(db))
}
}
impl crate::Docs for MacroByExampleDef {
fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
docs_from_ast(&*self.source(db).1)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ScopeEntryWithSyntax {
pub(crate) name: Name,
@ -284,10 +266,10 @@ impl SourceAnalyzer {
&self,
db: &impl HirDatabase,
macro_call: &ast::MacroCall,
) -> Option<MacroByExampleDef> {
) -> Option<MacroDef> {
let id =
self.resolver.resolve_macro_call(db, macro_call.path().and_then(Path::from_ast))?;
Some(MacroByExampleDef { id })
Some(MacroDef { id })
}
pub fn resolve_hir_path(

View file

@ -238,10 +238,7 @@ impl NavigationTarget {
}
}
pub(crate) fn from_macro_def(
db: &RootDatabase,
macro_call: hir::MacroByExampleDef,
) -> 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());
NavigationTarget::from_named(file_id.original_file(db), &*node)

View file

@ -1,11 +1,12 @@
use ra_syntax::{AstNode, AstPtr, ast};
use hir::Either;
use crate::db::RootDatabase;
use test_utils::tested_by;
use crate::db::RootDatabase;
pub enum NameRefKind {
Method(hir::Function),
Macro(hir::MacroByExampleDef),
Macro(hir::MacroDef),
FieldAccess(hir::StructField),
AssocItem(hir::ImplItem),
Def(hir::ModuleDef),