aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/algo.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-26 12:04:22 +0000
committerGitHub <[email protected]>2020-02-26 12:04:22 +0000
commit5c64ad27e041bcdb281c0a751720ceb3a6369d04 (patch)
tree12d89798f61b276f8bd640db07276a7d4e92b1c2 /crates/ra_syntax/src/algo.rs
parent04deae3dba7c9b7054f7a1d64e4b93a05aecc132 (diff)
parentc3a4c4429de83450654795534e64e878a774a088 (diff)
Merge pull request #3222 from matklad/identity
Introduce Semantics API
Diffstat (limited to 'crates/ra_syntax/src/algo.rs')
-rw-r--r--crates/ra_syntax/src/algo.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs
index 21fca99a6..f14bcbb35 100644
--- a/crates/ra_syntax/src/algo.rs
+++ b/crates/ra_syntax/src/algo.rs
@@ -4,7 +4,7 @@ use std::ops::RangeInclusive;
4 4
5use itertools::Itertools; 5use itertools::Itertools;
6use ra_text_edit::TextEditBuilder; 6use ra_text_edit::TextEditBuilder;
7use rustc_hash::FxHashMap; 7use rustc_hash::{FxHashMap, FxHashSet};
8 8
9use crate::{ 9use crate::{
10 AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, TextRange, TextUnit, 10 AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxNodePtr, TextRange, TextUnit,
@@ -56,6 +56,11 @@ pub fn find_covering_element(root: &SyntaxNode, range: TextRange) -> SyntaxEleme
56 root.covering_element(range) 56 root.covering_element(range)
57} 57}
58 58
59pub fn least_common_ancestor(u: &SyntaxNode, v: &SyntaxNode) -> Option<SyntaxNode> {
60 let u_ancestors = u.ancestors().collect::<FxHashSet<SyntaxNode>>();
61 v.ancestors().find(|it| u_ancestors.contains(it))
62}
63
59#[derive(Debug, PartialEq, Eq, Clone, Copy)] 64#[derive(Debug, PartialEq, Eq, Clone, Copy)]
60pub enum InsertPosition<T> { 65pub enum InsertPosition<T> {
61 First, 66 First,