mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Simplify
This commit is contained in:
parent
9cb13b6efb
commit
634d588fd7
13 changed files with 137 additions and 176 deletions
|
@ -1,4 +1,4 @@
|
|||
use hir::{DescendPreference, HirFileIdExt, InFile, Semantics};
|
||||
use hir::{DescendPreference, InFile, MacroFileIdExt, Semantics};
|
||||
use ide_db::{
|
||||
base_db::FileId, helpers::pick_best_token,
|
||||
syntax_helpers::insert_whitespace_into_node::insert_ws_into, RootDatabase,
|
||||
|
@ -44,15 +44,15 @@ pub(crate) fn expand_macro(db: &RootDatabase, position: FilePosition) -> Option<
|
|||
.descend_into_macros(DescendPreference::None, tok.clone())
|
||||
.into_iter()
|
||||
.find_map(|descended| {
|
||||
let hir_file = sema.hir_file_for(&descended.parent()?);
|
||||
if !hir_file.is_derive_attr_pseudo_expansion(db) {
|
||||
let macro_file = sema.hir_file_for(&descended.parent()?).macro_file()?;
|
||||
if !macro_file.is_derive_attr_pseudo_expansion(db) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let name = descended.parent_ancestors().filter_map(ast::Path::cast).last()?.to_string();
|
||||
// up map out of the #[derive] expansion
|
||||
let InFile { file_id, value: tokens } =
|
||||
hir::InFile::new(hir_file, descended).upmap_once(db)?;
|
||||
hir::InMacroFile::new(macro_file, descended).upmap_once(db);
|
||||
let token = sema.parse_or_expand(file_id).covering_element(tokens[0]).into_token()?;
|
||||
let attr = token.parent_ancestors().find_map(ast::Attr::cast)?;
|
||||
let expansions = sema.expand_derive_macro(&attr)?;
|
||||
|
|
|
@ -142,7 +142,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
|
|||
Definition::Function(it) => it.source(db).map(|src| src.file_id),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(file_id) = file_id.filter(|file| file.call_node(db).is_some()) {
|
||||
if let Some(file_id) = file_id.filter(|file| file.macro_file().is_some()) {
|
||||
in_macro_expansion.entry(file_id).or_default().push(runnable);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Computes color for a single element.
|
||||
|
||||
use hir::{AsAssocItem, HasVisibility, HirFileIdExt, Semantics};
|
||||
use hir::{AsAssocItem, HasVisibility, MacroFileIdExt, Semantics};
|
||||
use ide_db::{
|
||||
defs::{Definition, IdentClass, NameClass, NameRefClass},
|
||||
FxHashMap, RootDatabase, SymbolKind,
|
||||
|
@ -218,7 +218,10 @@ fn highlight_name_ref(
|
|||
// We can fix this for derive attributes since derive helpers are recorded, but not for
|
||||
// general attributes.
|
||||
None if name_ref.syntax().ancestors().any(|it| it.kind() == ATTR)
|
||||
&& !sema.hir_file_for(name_ref.syntax()).is_derive_attr_pseudo_expansion(sema.db) =>
|
||||
&& !sema
|
||||
.hir_file_for(name_ref.syntax())
|
||||
.macro_file()
|
||||
.map_or(false, |it| it.is_derive_attr_pseudo_expansion(sema.db)) =>
|
||||
{
|
||||
return HlTag::Symbol(SymbolKind::Attribute).into();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue