Skip to content

Commit f553837

Browse files
committed
upstream text-utils to text_unit
1 parent c9e42fc commit f553837

File tree

10 files changed

+20
-44
lines changed

10 files changed

+20
-44
lines changed

Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_editor/src/typing.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ use itertools::Itertools;
44
use ra_syntax::{
55
algo::{find_node_at_offset, find_covering_node, find_leaf_at_offset, LeafAtOffset},
66
ast,
7-
text_utils::intersect,
87
AstNode, Direction, SourceFile, SyntaxKind,
98
SyntaxKind::*,
109
SyntaxNode, TextRange, TextUnit,
1110
};
12-
use ra_text_edit::text_utils::contains_offset_nonstrict;
1311

1412
use crate::{LocalEdit, TextEditBuilder};
1513

@@ -39,7 +37,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit {
3937
Some(text) => text,
4038
None => continue,
4139
};
42-
let range = match intersect(range, node.range()) {
40+
let range = match range.intersection(&node.range()) {
4341
Some(range) => range,
4442
None => continue,
4543
} - node.range().start();
@@ -112,7 +110,7 @@ pub fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> {
112110
}
113111
if let Some(expr) = let_stmt.initializer() {
114112
let expr_range = expr.syntax().range();
115-
if contains_offset_nonstrict(expr_range, offset) && offset != expr_range.start() {
113+
if expr_range.contains(offset) && offset != expr_range.start() {
116114
return None;
117115
}
118116
if file

crates/ra_lsp_server/src/main_loop/handlers.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use languageserver_types::{
1111
use ra_analysis::{
1212
FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange,
1313
};
14-
use ra_syntax::{text_utils::intersect, TextUnit, AstNode};
15-
use ra_text_edit::text_utils::contains_offset_nonstrict;
14+
use ra_syntax::{TextUnit, AstNode};
1615
use rustc_hash::FxHashMap;
1716
use serde_json::to_value;
1817
use std::io::Write;
@@ -248,7 +247,7 @@ pub fn handle_runnables(
248247
let mut res = Vec::new();
249248
for runnable in world.analysis().runnables(file_id)? {
250249
if let Some(offset) = offset {
251-
if !contains_offset_nonstrict(runnable.range, offset) {
250+
if !runnable.range.contains_inclusive(offset) {
252251
continue;
253252
}
254253
}
@@ -650,7 +649,7 @@ pub fn handle_code_action(
650649
.diagnostics(file_id)?
651650
.into_iter()
652651
.filter_map(|d| Some((d.range, d.fix?)))
653-
.filter(|(diag_range, _fix)| intersect(*diag_range, range).is_some())
652+
.filter(|(diag_range, _fix)| diag_range.intersection(&range).is_some())
654653
.map(|(_range, fix)| fix);
655654

656655
let mut res = Vec::new();

crates/ra_syntax/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ itertools = "0.8.0"
1414
drop_bomb = "0.1.4"
1515
parking_lot = "0.7.0"
1616
rowan = "0.2.0"
17-
text_unit = "0.1.5"
17+
text_unit = "0.1.6"
1818
ra_text_edit = { path = "../ra_text_edit" }
1919

2020
[dev-dependencies]

crates/ra_syntax/src/text_utils.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
use crate::TextRange;
22

3-
pub fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> {
4-
let start = r1.start().max(r2.start());
5-
let end = r1.end().min(r2.end());
6-
if start <= end {
7-
Some(TextRange::from_to(start, end))
8-
} else {
9-
None
10-
}
11-
}
12-
133
pub fn replace_range(mut text: String, range: TextRange, replace_with: &str) -> String {
144
let start = u32::from(range.start()) as usize;
155
let end = u32::from(range.end()) as usize;

crates/ra_syntax/src/yellow/syntax_text.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
use std::{fmt, ops};
22

3-
use ra_text_edit::text_utils::contains_offset_nonstrict;
4-
use crate::{
5-
text_utils::intersect,
6-
SyntaxNode, TextRange, TextUnit,
7-
};
3+
use crate::{SyntaxNode, TextRange, TextUnit};
84

95
#[derive(Clone)]
106
pub struct SyntaxText<'a> {
@@ -23,7 +19,7 @@ impl<'a> SyntaxText<'a> {
2319
let range = self.range;
2420
self.node.descendants().filter_map(move |node| {
2521
let text = node.leaf_text()?;
26-
let range = intersect(range, node.range())?;
22+
let range = range.intersection(&node.range())?;
2723
let range = range - node.range().start();
2824
Some(&text[range])
2925
})
@@ -92,13 +88,13 @@ pub trait SyntaxTextSlice: fmt::Debug {
9288

9389
impl SyntaxTextSlice for TextRange {
9490
fn restrict(&self, range: TextRange) -> Option<TextRange> {
95-
intersect(*self, range)
91+
self.intersection(&range)
9692
}
9793
}
9894

9995
impl SyntaxTextSlice for ops::RangeTo<TextUnit> {
10096
fn restrict(&self, range: TextRange) -> Option<TextRange> {
101-
if !contains_offset_nonstrict(range, self.end) {
97+
if !range.contains_inclusive(self.end) {
10298
return None;
10399
}
104100
Some(TextRange::from_to(range.start(), self.end))
@@ -107,7 +103,7 @@ impl SyntaxTextSlice for ops::RangeTo<TextUnit> {
107103

108104
impl SyntaxTextSlice for ops::RangeFrom<TextUnit> {
109105
fn restrict(&self, range: TextRange) -> Option<TextRange> {
110-
if !contains_offset_nonstrict(range, self.start) {
106+
if !range.contains_inclusive(self.start) {
111107
return None;
112108
}
113109
Some(TextRange::from_to(self.start, range.end()))

crates/ra_text_edit/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Aleksey Kladov <[email protected]>"]
66
publish = false
77

88
[dependencies]
9-
text_unit = "0.1.5"
9+
text_unit = "0.1.6"
1010
proptest = "0.8.7"
1111

1212
[dev-dependencies]

crates/ra_text_edit/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod text_edit;
2-
pub mod text_utils;
32
pub mod test_utils;
43

54
pub use crate::text_edit::{TextEdit, TextEditBuilder};

crates/ra_text_edit/src/text_edit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::AtomTextEdit;
2-
use crate::text_utils::contains_offset_nonstrict;
32
use text_unit::{TextRange, TextUnit};
43

54
#[derive(Debug, Clone)]
@@ -28,7 +27,7 @@ impl TextEditBuilder {
2827
pub fn invalidates_offset(&self, offset: TextUnit) -> bool {
2928
self.atoms
3029
.iter()
31-
.any(|atom| contains_offset_nonstrict(atom.delete, offset))
30+
.any(|atom| atom.delete.contains_inclusive(offset))
3231
}
3332
}
3433

crates/ra_text_edit/src/text_utils.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)