aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/yellow
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <[email protected]>2019-01-10 12:54:58 +0000
committerMarcus Klaas de Vries <[email protected]>2019-01-14 12:52:55 +0000
commita6146d35b1615cf5fb908b29f34e58bfde3bf96d (patch)
tree70613ee98eee67c1df6aff1e663be75a33c348f4 /crates/ra_syntax/src/yellow
parent8caff4e03475c20392f13e8c6ad469bd01a4b4ce (diff)
Implement type inference for literals (WIP)
Diffstat (limited to 'crates/ra_syntax/src/yellow')
-rw-r--r--crates/ra_syntax/src/yellow/syntax_text.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/yellow/syntax_text.rs b/crates/ra_syntax/src/yellow/syntax_text.rs
index 08dbe57a2..378cd1b2e 100644
--- a/crates/ra_syntax/src/yellow/syntax_text.rs
+++ b/crates/ra_syntax/src/yellow/syntax_text.rs
@@ -15,6 +15,7 @@ impl<'a> SyntaxText<'a> {
15 range: node.range(), 15 range: node.range(),
16 } 16 }
17 } 17 }
18
18 pub fn chunks(&self) -> impl Iterator<Item = &'a str> { 19 pub fn chunks(&self) -> impl Iterator<Item = &'a str> {
19 let range = self.range; 20 let range = self.range;
20 self.node.descendants().filter_map(move |node| { 21 self.node.descendants().filter_map(move |node| {
@@ -24,15 +25,19 @@ impl<'a> SyntaxText<'a> {
24 Some(&text[range]) 25 Some(&text[range])
25 }) 26 })
26 } 27 }
28
27 pub fn push_to(&self, buf: &mut String) { 29 pub fn push_to(&self, buf: &mut String) {
28 self.chunks().for_each(|it| buf.push_str(it)); 30 self.chunks().for_each(|it| buf.push_str(it));
29 } 31 }
32
30 pub fn to_string(&self) -> String { 33 pub fn to_string(&self) -> String {
31 self.chunks().collect() 34 self.chunks().collect()
32 } 35 }
36
33 pub fn contains(&self, c: char) -> bool { 37 pub fn contains(&self, c: char) -> bool {
34 self.chunks().any(|it| it.contains(c)) 38 self.chunks().any(|it| it.contains(c))
35 } 39 }
40
36 pub fn find(&self, c: char) -> Option<TextUnit> { 41 pub fn find(&self, c: char) -> Option<TextUnit> {
37 let mut acc: TextUnit = 0.into(); 42 let mut acc: TextUnit = 0.into();
38 for chunk in self.chunks() { 43 for chunk in self.chunks() {
@@ -44,9 +49,11 @@ impl<'a> SyntaxText<'a> {
44 } 49 }
45 None 50 None
46 } 51 }
52
47 pub fn len(&self) -> TextUnit { 53 pub fn len(&self) -> TextUnit {
48 self.range.len() 54 self.range.len()
49 } 55 }
56
50 pub fn slice(&self, range: impl SyntaxTextSlice) -> SyntaxText<'a> { 57 pub fn slice(&self, range: impl SyntaxTextSlice) -> SyntaxText<'a> {
51 let range = range.restrict(self.range).unwrap_or_else(|| { 58 let range = range.restrict(self.range).unwrap_or_else(|| {
52 panic!("invalid slice, range: {:?}, slice: {:?}", self.range, range) 59 panic!("invalid slice, range: {:?}, slice: {:?}", self.range, range)
@@ -56,8 +63,10 @@ impl<'a> SyntaxText<'a> {
56 range, 63 range,
57 } 64 }
58 } 65 }
59 pub fn char_at(&self, offset: TextUnit) -> Option<char> { 66
67 pub fn char_at(&self, offset: impl Into<TextUnit>) -> Option<char> {
60 let mut start: TextUnit = 0.into(); 68 let mut start: TextUnit = 0.into();
69 let offset = offset.into();
61 for chunk in self.chunks() { 70 for chunk in self.chunks() {
62 let end = start + TextUnit::of_str(chunk); 71 let end = start + TextUnit::of_str(chunk);
63 if start <= offset && offset < end { 72 if start <= offset && offset < end {