aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/tokens.rs30
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
176fn find_usual_string_range(s: &str) -> Option<TextRange> { 206fn find_usual_string_range(s: &str) -> Option<TextRange> {