aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/assists/src/handlers/raw_string.rs5
-rw-r--r--crates/assists/src/handlers/replace_string_with_char.rs6
-rw-r--r--crates/hir_expand/src/builtin_macro.rs2
-rw-r--r--crates/ide/src/syntax_highlighting/injection.rs1
-rw-r--r--crates/syntax/src/ast/node_ext.rs2
-rw-r--r--crates/syntax/src/ast/token_ext.rs54
6 files changed, 25 insertions, 45 deletions
diff --git a/crates/assists/src/handlers/raw_string.rs b/crates/assists/src/handlers/raw_string.rs
index 7f9f01c9c..4c759cc25 100644
--- a/crates/assists/src/handlers/raw_string.rs
+++ b/crates/assists/src/handlers/raw_string.rs
@@ -1,9 +1,6 @@
1use std::borrow::Cow; 1use std::borrow::Cow;
2 2
3use syntax::{ 3use syntax::{ast, AstToken, TextRange, TextSize};
4 ast::{self, HasQuotes, HasStringValue},
5 AstToken, TextRange, TextSize,
6};
7use test_utils::mark; 4use test_utils::mark;
8 5
9use crate::{AssistContext, AssistId, AssistKind, Assists}; 6use crate::{AssistContext, AssistId, AssistKind, Assists};
diff --git a/crates/assists/src/handlers/replace_string_with_char.rs b/crates/assists/src/handlers/replace_string_with_char.rs
index 6d227e883..b4b898846 100644
--- a/crates/assists/src/handlers/replace_string_with_char.rs
+++ b/crates/assists/src/handlers/replace_string_with_char.rs
@@ -1,8 +1,4 @@
1use syntax::{ 1use syntax::{ast, AstToken, SyntaxKind::STRING};
2 ast::{self, HasStringValue},
3 AstToken,
4 SyntaxKind::STRING,
5};
6 2
7use crate::{AssistContext, AssistId, AssistKind, Assists}; 3use crate::{AssistContext, AssistId, AssistKind, Assists};
8 4
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index 86918b626..aebbfc4df 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -8,7 +8,7 @@ use base_db::FileId;
8use either::Either; 8use either::Either;
9use mbe::parse_to_token_tree; 9use mbe::parse_to_token_tree;
10use parser::FragmentKind; 10use parser::FragmentKind;
11use syntax::ast::{self, AstToken, HasStringValue}; 11use syntax::ast::{self, AstToken};
12 12
13macro_rules! register_builtin { 13macro_rules! register_builtin {
14 ( LAZY: $(($name:ident, $kind: ident) => $expand:ident),* , EAGER: $(($e_name:ident, $e_kind: ident) => $e_expand:ident),* ) => { 14 ( LAZY: $(($name:ident, $kind: ident) => $expand:ident),* , EAGER: $(($e_name:ident, $e_kind: ident) => $e_expand:ident),* ) => {
diff --git a/crates/ide/src/syntax_highlighting/injection.rs b/crates/ide/src/syntax_highlighting/injection.rs
index 79f6b5359..e97d1be1a 100644
--- a/crates/ide/src/syntax_highlighting/injection.rs
+++ b/crates/ide/src/syntax_highlighting/injection.rs
@@ -2,7 +2,6 @@
2 2
3use std::{collections::BTreeMap, convert::TryFrom}; 3use std::{collections::BTreeMap, convert::TryFrom};
4 4
5use ast::{HasQuotes, HasStringValue};
6use hir::Semantics; 5use hir::Semantics;
7use ide_db::call_info::ActiveParameter; 6use ide_db::call_info::ActiveParameter;
8use itertools::Itertools; 7use itertools::Itertools;
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 5579f72b9..ce35ac01a 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -7,7 +7,7 @@ use itertools::Itertools;
7use parser::SyntaxKind; 7use parser::SyntaxKind;
8 8
9use crate::{ 9use crate::{
10 ast::{self, support, token_ext::HasStringValue, AstNode, AstToken, NameOwner, SyntaxNode}, 10 ast::{self, support, AstNode, AstToken, NameOwner, SyntaxNode},
11 SmolStr, SyntaxElement, SyntaxToken, T, 11 SmolStr, SyntaxElement, SyntaxToken, T,
12}; 12};
13 13
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs
index 6cd20b6a6..bf0035986 100644
--- a/crates/syntax/src/ast/token_ext.rs
+++ b/crates/syntax/src/ast/token_ext.rs
@@ -114,36 +114,6 @@ impl QuoteOffsets {
114 } 114 }
115} 115}
116 116
117pub trait HasQuotes: AstToken {
118 fn quote_offsets(&self) -> Option<QuoteOffsets> {
119 let text = self.text().as_str();
120 let offsets = QuoteOffsets::new(text)?;
121 let o = self.syntax().text_range().start();
122 let offsets = QuoteOffsets {
123 quotes: (offsets.quotes.0 + o, offsets.quotes.1 + o),
124 contents: offsets.contents + o,
125 };
126 Some(offsets)
127 }
128 fn open_quote_text_range(&self) -> Option<TextRange> {
129 self.quote_offsets().map(|it| it.quotes.0)
130 }
131
132 fn close_quote_text_range(&self) -> Option<TextRange> {
133 self.quote_offsets().map(|it| it.quotes.1)
134 }
135
136 fn text_range_between_quotes(&self) -> Option<TextRange> {
137 self.quote_offsets().map(|it| it.contents)
138 }
139}
140
141impl HasQuotes for ast::String {}
142
143pub trait HasStringValue: HasQuotes {
144 fn value(&self) -> Option<Cow<'_, str>>;
145}
146
147impl ast::String { 117impl ast::String {
148 pub fn is_raw(&self) -> bool { 118 pub fn is_raw(&self) -> bool {
149 self.text().starts_with('r') 119 self.text().starts_with('r')
@@ -153,10 +123,8 @@ impl ast::String {
153 assert!(TextRange::up_to(contents_range.len()).contains_range(range)); 123 assert!(TextRange::up_to(contents_range.len()).contains_range(range));
154 Some(range + contents_range.start()) 124 Some(range + contents_range.start())
155 } 125 }
156}
157 126
158impl HasStringValue for ast::String { 127 pub fn value(&self) -> Option<Cow<'_, str>> {
159 fn value(&self) -> Option<Cow<'_, str>> {
160 if self.is_raw() { 128 if self.is_raw() {
161 let text = self.text().as_str(); 129 let text = self.text().as_str();
162 let text = 130 let text =
@@ -181,6 +149,26 @@ impl HasStringValue for ast::String {
181 let res = if buf == text { Cow::Borrowed(text) } else { Cow::Owned(buf) }; 149 let res = if buf == text { Cow::Borrowed(text) } else { Cow::Owned(buf) };
182 Some(res) 150 Some(res)
183 } 151 }
152
153 pub fn quote_offsets(&self) -> Option<QuoteOffsets> {
154 let text = self.text().as_str();
155 let offsets = QuoteOffsets::new(text)?;
156 let o = self.syntax().text_range().start();
157 let offsets = QuoteOffsets {
158 quotes: (offsets.quotes.0 + o, offsets.quotes.1 + o),
159 contents: offsets.contents + o,
160 };
161 Some(offsets)
162 }
163 pub fn text_range_between_quotes(&self) -> Option<TextRange> {
164 self.quote_offsets().map(|it| it.contents)
165 }
166 pub fn open_quote_text_range(&self) -> Option<TextRange> {
167 self.quote_offsets().map(|it| it.quotes.0)
168 }
169 pub fn close_quote_text_range(&self) -> Option<TextRange> {
170 self.quote_offsets().map(|it| it.quotes.1)
171 }
184} 172}
185 173
186impl ast::ByteString { 174impl ast::ByteString {