Skip to content

Commit 6158304

Browse files
committed
Simplify
1 parent 5ba4f94 commit 6158304

File tree

6 files changed

+25
-45
lines changed

6 files changed

+25
-45
lines changed

crates/assists/src/handlers/raw_string.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use std::borrow::Cow;
22

3-
use syntax::{
4-
ast::{self, HasQuotes, HasStringValue},
5-
AstToken, TextRange, TextSize,
6-
};
3+
use syntax::{ast, AstToken, TextRange, TextSize};
74
use test_utils::mark;
85

96
use crate::{AssistContext, AssistId, AssistKind, Assists};

crates/assists/src/handlers/replace_string_with_char.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
use syntax::{
2-
ast::{self, HasStringValue},
3-
AstToken,
4-
SyntaxKind::STRING,
5-
};
1+
use syntax::{ast, AstToken, SyntaxKind::STRING};
62

73
use crate::{AssistContext, AssistId, AssistKind, Assists};
84

crates/hir_expand/src/builtin_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use base_db::FileId;
88
use either::Either;
99
use mbe::parse_to_token_tree;
1010
use parser::FragmentKind;
11-
use syntax::ast::{self, AstToken, HasStringValue};
11+
use syntax::ast::{self, AstToken};
1212

1313
macro_rules! register_builtin {
1414
( LAZY: $(($name:ident, $kind: ident) => $expand:ident),* , EAGER: $(($e_name:ident, $e_kind: ident) => $e_expand:ident),* ) => {

crates/ide/src/syntax_highlighting/injection.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use std::{collections::BTreeMap, convert::TryFrom};
44

5-
use ast::{HasQuotes, HasStringValue};
65
use hir::Semantics;
76
use ide_db::call_info::ActiveParameter;
87
use itertools::Itertools;

crates/syntax/src/ast/node_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use itertools::Itertools;
77
use parser::SyntaxKind;
88

99
use crate::{
10-
ast::{self, support, token_ext::HasStringValue, AstNode, AstToken, NameOwner, SyntaxNode},
10+
ast::{self, support, AstNode, AstToken, NameOwner, SyntaxNode},
1111
SmolStr, SyntaxElement, SyntaxToken, T,
1212
};
1313

crates/syntax/src/ast/token_ext.rs

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -114,36 +114,6 @@ impl QuoteOffsets {
114114
}
115115
}
116116

117-
pub 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-
141-
impl HasQuotes for ast::String {}
142-
143-
pub trait HasStringValue: HasQuotes {
144-
fn value(&self) -> Option<Cow<'_, str>>;
145-
}
146-
147117
impl ast::String {
148118
pub fn is_raw(&self) -> bool {
149119
self.text().starts_with('r')
@@ -153,10 +123,8 @@ impl ast::String {
153123
assert!(TextRange::up_to(contents_range.len()).contains_range(range));
154124
Some(range + contents_range.start())
155125
}
156-
}
157126

158-
impl HasStringValue for ast::String {
159-
fn value(&self) -> Option<Cow<'_, str>> {
127+
pub fn value(&self) -> Option<Cow<'_, str>> {
160128
if self.is_raw() {
161129
let text = self.text().as_str();
162130
let text =
@@ -181,6 +149,26 @@ impl HasStringValue for ast::String {
181149
let res = if buf == text { Cow::Borrowed(text) } else { Cow::Owned(buf) };
182150
Some(res)
183151
}
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+
}
184172
}
185173

186174
impl ast::ByteString {

0 commit comments

Comments
 (0)