mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +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,
|
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 {
|
pub enum Container {
|
||||||
Trait(Trait),
|
Trait(Trait),
|
||||||
ImplBlock(ImplBlock),
|
ImplBlock(ImplBlock),
|
||||||
|
|
|
@ -4,7 +4,7 @@ use ra_syntax::ast;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
HirDatabase, DefDatabase, AstDatabase,
|
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)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
|
@ -20,6 +20,7 @@ pub enum DocDef {
|
||||||
Union(Union),
|
Union(Union),
|
||||||
Trait(Trait),
|
Trait(Trait),
|
||||||
TypeAlias(TypeAlias),
|
TypeAlias(TypeAlias),
|
||||||
|
MacroDef(MacroDef),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_froms!(
|
impl_froms!(
|
||||||
|
@ -33,7 +34,8 @@ impl_froms!(
|
||||||
Function,
|
Function,
|
||||||
Union,
|
Union,
|
||||||
Trait,
|
Trait,
|
||||||
TypeAlias
|
TypeAlias,
|
||||||
|
MacroDef
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Holds documentation
|
/// Holds documentation
|
||||||
|
@ -83,6 +85,7 @@ pub(crate) fn documentation_query(
|
||||||
DocDef::Union(it) => docs_from_ast(&*it.source(db).1),
|
DocDef::Union(it) => docs_from_ast(&*it.source(db).1),
|
||||||
DocDef::Trait(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::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,
|
expr::ExprScopes,
|
||||||
resolve::Resolution,
|
resolve::Resolution,
|
||||||
generics::{GenericParams, GenericParam, HasGenericParams},
|
generics::{GenericParams, GenericParam, HasGenericParams},
|
||||||
source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax,MacroByExampleDef},
|
source_binder::{SourceAnalyzer, PathResolution, ScopeEntryWithSyntax},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::code_model::{
|
pub use self::code_model::{
|
||||||
|
|
|
@ -10,7 +10,7 @@ use std::sync::Arc;
|
||||||
use rustc_hash::{FxHashSet, FxHashMap};
|
use rustc_hash::{FxHashSet, FxHashMap};
|
||||||
use ra_db::{FileId, FilePosition};
|
use ra_db::{FileId, FilePosition};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange,TreeArc,
|
SyntaxNode, AstPtr, TextUnit, SyntaxNodePtr, TextRange,
|
||||||
ast::{self, AstNode, NameOwner},
|
ast::{self, AstNode, NameOwner},
|
||||||
algo::find_node_at_offset,
|
algo::find_node_at_offset,
|
||||||
SyntaxKind::*,
|
SyntaxKind::*,
|
||||||
|
@ -18,10 +18,9 @@ use ra_syntax::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
HirDatabase, Function, Struct, Enum, Const, Static, Either, DefWithBody, PerNs, Name,
|
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}},
|
expr::{BodySourceMap, scope::{ScopeId, ExprScopes}},
|
||||||
ids::{LocationCtx, MacroDefId},
|
ids::LocationCtx,
|
||||||
docs::{docs_from_ast,Documentation},
|
|
||||||
expr, AstId,
|
expr, AstId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -182,27 +181,10 @@ pub enum PathResolution {
|
||||||
/// A generic parameter
|
/// A generic parameter
|
||||||
GenericParam(u32),
|
GenericParam(u32),
|
||||||
SelfType(crate::ImplBlock),
|
SelfType(crate::ImplBlock),
|
||||||
Macro(MacroByExampleDef),
|
Macro(MacroDef),
|
||||||
AssocItem(crate::ImplItem),
|
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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ScopeEntryWithSyntax {
|
pub struct ScopeEntryWithSyntax {
|
||||||
pub(crate) name: Name,
|
pub(crate) name: Name,
|
||||||
|
@ -284,10 +266,10 @@ impl SourceAnalyzer {
|
||||||
&self,
|
&self,
|
||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
macro_call: &ast::MacroCall,
|
macro_call: &ast::MacroCall,
|
||||||
) -> Option<MacroByExampleDef> {
|
) -> Option<MacroDef> {
|
||||||
let id =
|
let id =
|
||||||
self.resolver.resolve_macro_call(db, macro_call.path().and_then(Path::from_ast))?;
|
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(
|
pub fn resolve_hir_path(
|
||||||
|
|
|
@ -238,10 +238,7 @@ impl NavigationTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_macro_def(
|
pub(crate) fn from_macro_def(db: &RootDatabase, macro_call: hir::MacroDef) -> NavigationTarget {
|
||||||
db: &RootDatabase,
|
|
||||||
macro_call: hir::MacroByExampleDef,
|
|
||||||
) -> NavigationTarget {
|
|
||||||
let (file_id, node) = macro_call.source(db);
|
let (file_id, node) = macro_call.source(db);
|
||||||
log::debug!("nav target {}", node.syntax().debug_dump());
|
log::debug!("nav target {}", node.syntax().debug_dump());
|
||||||
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
NavigationTarget::from_named(file_id.original_file(db), &*node)
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
use ra_syntax::{AstNode, AstPtr, ast};
|
use ra_syntax::{AstNode, AstPtr, ast};
|
||||||
use hir::Either;
|
use hir::Either;
|
||||||
use crate::db::RootDatabase;
|
|
||||||
use test_utils::tested_by;
|
use test_utils::tested_by;
|
||||||
|
|
||||||
|
use crate::db::RootDatabase;
|
||||||
|
|
||||||
pub enum NameRefKind {
|
pub enum NameRefKind {
|
||||||
Method(hir::Function),
|
Method(hir::Function),
|
||||||
Macro(hir::MacroByExampleDef),
|
Macro(hir::MacroDef),
|
||||||
FieldAccess(hir::StructField),
|
FieldAccess(hir::StructField),
|
||||||
AssocItem(hir::ImplItem),
|
AssocItem(hir::ImplItem),
|
||||||
Def(hir::ModuleDef),
|
Def(hir::ModuleDef),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue