From c6247f74c72857de3619a080698237d58ff9e960 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Feb 2020 16:05:35 +0100 Subject: Basic injections --- crates/ra_syntax/src/ast/tokens.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'crates/ra_syntax') 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 { let inside_str = &text[start_of_inside..end_of_inside]; Some(inside_str.to_string()) } + + pub fn open_quote_text_range(&self) -> Option { + let text = self.text().as_str(); + let usual_string_range = find_usual_string_range(text)?; + + let start = self.syntax().text_range().start(); + let len = usual_string_range.start() + TextUnit::of_char('"'); + Some(TextRange::offset_len(start, len)) + } + + pub fn close_quote_text_range(&self) -> Option { + let text = self.text().as_str(); + let usual_string_range = find_usual_string_range(text)?; + + let end = self.syntax().text_range().end(); + let len = TextUnit::of_str(text) - usual_string_range.end(); + Some(TextRange::from_to(end - len, end)) + } + + pub fn map_range_up(&self, range: TextRange) -> Option { + // FIXME: handle escapes here properly + let text = self.text().as_str(); + let usual_string_range = find_usual_string_range(text)?; + Some( + range + + self.syntax().text_range().start() + + TextUnit::of_char('"') + + usual_string_range.start(), + ) + } } fn find_usual_string_range(s: &str) -> Option { -- cgit v1.2.3