mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
refactor $crate handling
Introduce proper hygiene module, which should grow quite a bit eventually.
This commit is contained in:
parent
e34e71c62d
commit
0bc7d28518
7 changed files with 118 additions and 89 deletions
|
@ -3,7 +3,7 @@
|
|||
use rustc_hash::FxHashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::{attr::Attr, type_ref::TypeRef};
|
||||
use hir_def::{attr::Attr, hygiene::Hygiene, type_ref::TypeRef};
|
||||
use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
|
||||
use ra_cfg::CfgOptions;
|
||||
use ra_syntax::{
|
||||
|
@ -227,10 +227,11 @@ impl ModuleImplBlocks {
|
|||
owner: &dyn ast::ModuleItemOwner,
|
||||
file_id: HirFileId,
|
||||
) {
|
||||
let hygiene = Hygiene::new(db, file_id);
|
||||
for item in owner.items_with_macros() {
|
||||
match item {
|
||||
ast::ItemOrMacro::Item(ast::ModuleItem::ImplBlock(impl_block_ast)) => {
|
||||
let attrs = Attr::from_attrs_owner(file_id, &impl_block_ast, db);
|
||||
let attrs = Attr::from_attrs_owner(&impl_block_ast, &hygiene);
|
||||
if attrs.map_or(false, |attrs| {
|
||||
attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false))
|
||||
}) {
|
||||
|
@ -247,7 +248,7 @@ impl ModuleImplBlocks {
|
|||
}
|
||||
ast::ItemOrMacro::Item(_) => (),
|
||||
ast::ItemOrMacro::Macro(macro_call) => {
|
||||
let attrs = Attr::from_attrs_owner(file_id, ¯o_call, db);
|
||||
let attrs = Attr::from_attrs_owner(¯o_call, &hygiene);
|
||||
if attrs.map_or(false, |attrs| {
|
||||
attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false))
|
||||
}) {
|
||||
|
@ -256,9 +257,8 @@ impl ModuleImplBlocks {
|
|||
|
||||
//FIXME: we should really cut down on the boilerplate required to process a macro
|
||||
let ast_id = AstId::new(file_id, db.ast_id_map(file_id).ast_id(¯o_call));
|
||||
if let Some(path) = macro_call
|
||||
.path()
|
||||
.and_then(|path| Path::from_src(Source { ast: path, file_id }, db))
|
||||
if let Some(path) =
|
||||
macro_call.path().and_then(|path| Path::from_src(path, &hygiene))
|
||||
{
|
||||
if let Some(def) = self.module.resolver(db).resolve_path_as_macro(db, &path)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue