mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
one macro def should be enough
This commit is contained in:
parent
2c28f5245d
commit
1b783e33e9
6 changed files with 25 additions and 33 deletions
|
@ -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),
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue