diff options
author | Aleksey Kladov <[email protected]> | 2020-02-27 15:05:35 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-27 15:16:13 +0000 |
commit | c6247f74c72857de3619a080698237d58ff9e960 (patch) | |
tree | 6c7053d80c08ba65266a86771e965ce572521c1f /crates/ra_syntax | |
parent | 8ed7e751b627791722aa10187894ff6ecc7e5a96 (diff) |
Basic injections
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast/tokens.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index ed8661faf..693b35feb 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs | |||
@@ -171,6 +171,36 @@ impl RawString { | |||
171 | let inside_str = &text[start_of_inside..end_of_inside]; | 171 | let inside_str = &text[start_of_inside..end_of_inside]; |
172 | Some(inside_str.to_string()) | 172 | Some(inside_str.to_string()) |
173 | } | 173 | } |
174 | |||
175 | pub fn open_quote_text_range(&self) -> Option<TextRange> { | ||
176 | let text = self.text().as_str(); | ||
177 | let usual_string_range = find_usual_string_range(text)?; | ||
178 | |||
179 | let start = self.syntax().text_range().start(); | ||
180 | let len = usual_string_range.start() + TextUnit::of_char('"'); | ||
181 | Some(TextRange::offset_len(start, len)) | ||
182 | } | ||
183 | |||
184 | pub fn close_quote_text_range(&self) -> Option<TextRange> { | ||
185 | let text = self.text().as_str(); | ||
186 | let usual_string_range = find_usual_string_range(text)?; | ||
187 | |||
188 | let end = self.syntax().text_range().end(); | ||
189 | let len = TextUnit::of_str(text) - usual_string_range.end(); | ||
190 | Some(TextRange::from_to(end - len, end)) | ||
191 | } | ||
192 | |||
193 | pub fn map_range_up(&self, range: TextRange) -> Option<TextRange> { | ||
194 | // FIXME: handle escapes here properly | ||
195 | let text = self.text().as_str(); | ||
196 | let usual_string_range = find_usual_string_range(text)?; | ||
197 | Some( | ||
198 | range | ||
199 | + self.syntax().text_range().start() | ||
200 | + TextUnit::of_char('"') | ||
201 | + usual_string_range.start(), | ||
202 | ) | ||
203 | } | ||
174 | } | 204 | } |
175 | 205 | ||
176 | fn find_usual_string_range(s: &str) -> Option<TextRange> { | 206 | fn find_usual_string_range(s: &str) -> Option<TextRange> { |