aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/tokens.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-27 15:48:06 +0000
committerGitHub <[email protected]>2020-02-27 15:48:06 +0000
commitde492d439f0cda73fe2d9b25e4d9f028f70eb095 (patch)
tree6c7053d80c08ba65266a86771e965ce572521c1f /crates/ra_syntax/src/ast/tokens.rs
parent062c12e3cdad887d751defa6f448edb5426ebf01 (diff)
parentc6247f74c72857de3619a080698237d58ff9e960 (diff)
Merge pull request #3349 from matklad/yo-dawg
Put syntax highlighting into syntax highlighting
Diffstat (limited to 'crates/ra_syntax/src/ast/tokens.rs')
-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> {