mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Record FileAstId
s for block expressiosn
Every block expression may contain inner items, so we need to be able to refer to any block expression and use it as a salsa key.
This commit is contained in:
parent
02edb4b31b
commit
52fe50a97b
1 changed files with 14 additions and 6 deletions
|
@ -13,7 +13,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use la_arena::{Arena, Idx};
|
use la_arena::{Arena, Idx};
|
||||||
use syntax::{ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
|
use syntax::{ast, match_ast, AstNode, AstPtr, SyntaxNode, SyntaxNodePtr};
|
||||||
|
|
||||||
/// `AstId` points to an AST node in a specific file.
|
/// `AstId` points to an AST node in a specific file.
|
||||||
pub struct FileAstId<N: AstNode> {
|
pub struct FileAstId<N: AstNode> {
|
||||||
|
@ -72,12 +72,20 @@ impl AstIdMap {
|
||||||
// get lower ids then children. That is, adding a new child does not
|
// get lower ids then children. That is, adding a new child does not
|
||||||
// change parent's id. This means that, say, adding a new function to a
|
// change parent's id. This means that, say, adding a new function to a
|
||||||
// trait does not change ids of top-level items, which helps caching.
|
// trait does not change ids of top-level items, which helps caching.
|
||||||
bdfs(node, |it| match ast::Item::cast(it) {
|
bdfs(node, |it| {
|
||||||
Some(module_item) => {
|
match_ast! {
|
||||||
|
match it {
|
||||||
|
ast::Item(module_item) => {
|
||||||
res.alloc(module_item.syntax());
|
res.alloc(module_item.syntax());
|
||||||
true
|
true
|
||||||
|
},
|
||||||
|
ast::BlockExpr(block) => {
|
||||||
|
res.alloc(block.syntax());
|
||||||
|
true
|
||||||
|
},
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => false,
|
|
||||||
});
|
});
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue