mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-27 05:44:12 +00:00
move node at offset to aglo already
This commit is contained in:
parent
1b82084a5f
commit
702bdacb03
11 changed files with 19 additions and 22 deletions
|
@ -2,7 +2,7 @@ pub mod visit;
|
|||
|
||||
use rowan::TransparentNewType;
|
||||
|
||||
use crate::{SyntaxNode, TextRange, TextUnit};
|
||||
use crate::{SyntaxNode, TextRange, TextUnit, AstNode};
|
||||
|
||||
pub use rowan::LeafAtOffset;
|
||||
|
||||
|
@ -16,6 +16,10 @@ pub fn find_leaf_at_offset(node: &SyntaxNode, offset: TextUnit) -> LeafAtOffset<
|
|||
}
|
||||
}
|
||||
|
||||
pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> {
|
||||
find_leaf_at_offset(syntax, offset).find_map(|leaf| leaf.ancestors().find_map(N::cast))
|
||||
}
|
||||
|
||||
pub fn find_covering_node(root: &SyntaxNode, range: TextRange) -> &SyntaxNode {
|
||||
SyntaxNode::from_repr(root.0.covering_node(range))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue