diff options
-rw-r--r-- | Cargo.lock | 14 | ||||
-rw-r--r-- | crates/ra_editor/src/typing.rs | 6 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 7 | ||||
-rw-r--r-- | crates/ra_syntax/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/text_utils.rs | 10 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow/syntax_text.rs | 14 | ||||
-rw-r--r-- | crates/ra_text_edit/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_text_edit/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_text_edit/src/text_edit.rs | 3 | ||||
-rw-r--r-- | crates/ra_text_edit/src/text_utils.rs | 5 |
10 files changed, 20 insertions, 44 deletions
diff --git a/Cargo.lock b/Cargo.lock index c445439b1..f1d8e5462 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -745,7 +745,7 @@ dependencies = [ | |||
745 | "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", | 745 | "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", |
746 | "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", | 746 | "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", |
747 | "test_utils 0.1.0", | 747 | "test_utils 0.1.0", |
748 | "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | 748 | "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", |
749 | "thread_worker 0.1.0", | 749 | "thread_worker 0.1.0", |
750 | "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", | 750 | "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", |
751 | "tools 0.1.0", | 751 | "tools 0.1.0", |
@@ -764,7 +764,7 @@ dependencies = [ | |||
764 | "ra_text_edit 0.1.0", | 764 | "ra_text_edit 0.1.0", |
765 | "rowan 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", | 765 | "rowan 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", |
766 | "test_utils 0.1.0", | 766 | "test_utils 0.1.0", |
767 | "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | 767 | "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", |
768 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 768 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
769 | "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", | 769 | "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", |
770 | ] | 770 | ] |
@@ -775,7 +775,7 @@ version = "0.1.0" | |||
775 | dependencies = [ | 775 | dependencies = [ |
776 | "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", | 776 | "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", |
777 | "test_utils 0.1.0", | 777 | "test_utils 0.1.0", |
778 | "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | 778 | "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", |
779 | ] | 779 | ] |
780 | 780 | ||
781 | [[package]] | 781 | [[package]] |
@@ -972,7 +972,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
972 | dependencies = [ | 972 | dependencies = [ |
973 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", | 973 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", |
974 | "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", | 974 | "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", |
975 | "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | 975 | "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", |
976 | ] | 976 | ] |
977 | 977 | ||
978 | [[package]] | 978 | [[package]] |
@@ -1218,12 +1218,12 @@ dependencies = [ | |||
1218 | "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1218 | "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1219 | "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1219 | "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1220 | "serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", | 1220 | "serde_json 1.0.34 (registry+https://github.com/rust-lang/crates.io-index)", |
1221 | "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", | 1221 | "text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", |
1222 | ] | 1222 | ] |
1223 | 1223 | ||
1224 | [[package]] | 1224 | [[package]] |
1225 | name = "text_unit" | 1225 | name = "text_unit" |
1226 | version = "0.1.5" | 1226 | version = "0.1.6" |
1227 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1227 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1228 | dependencies = [ | 1228 | dependencies = [ |
1229 | "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", | 1229 | "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1597,7 +1597,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1597 | "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" | 1597 | "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" |
1598 | "checksum teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d89ad4617d1dec55331067fadaa041e813479e1779616f3d3ce9308bf46184e" | 1598 | "checksum teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d89ad4617d1dec55331067fadaa041e813479e1779616f3d3ce9308bf46184e" |
1599 | "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" | 1599 | "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" |
1600 | "checksum text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8009d7bdbd896a7e09b595f8f9325a19047fc708653e60d0895202b82135048f" | 1600 | "checksum text_unit 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "158bb1c22b638b1da3c95a8ad9f061ea40d4d39fd0301be3a520f92efeeb189e" |
1601 | "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" | 1601 | "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" |
1602 | "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" | 1602 | "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" |
1603 | "checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" | 1603 | "checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" |
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index 576caf6be..d8177f245 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs | |||
@@ -4,12 +4,10 @@ use itertools::Itertools; | |||
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | algo::{find_node_at_offset, find_covering_node, find_leaf_at_offset, LeafAtOffset}, | 5 | algo::{find_node_at_offset, find_covering_node, find_leaf_at_offset, LeafAtOffset}, |
6 | ast, | 6 | ast, |
7 | text_utils::intersect, | ||
8 | AstNode, Direction, SourceFile, SyntaxKind, | 7 | AstNode, Direction, SourceFile, SyntaxKind, |
9 | SyntaxKind::*, | 8 | SyntaxKind::*, |
10 | SyntaxNode, TextRange, TextUnit, | 9 | SyntaxNode, TextRange, TextUnit, |
11 | }; | 10 | }; |
12 | use ra_text_edit::text_utils::contains_offset_nonstrict; | ||
13 | 11 | ||
14 | use crate::{LocalEdit, TextEditBuilder}; | 12 | use crate::{LocalEdit, TextEditBuilder}; |
15 | 13 | ||
@@ -39,7 +37,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { | |||
39 | Some(text) => text, | 37 | Some(text) => text, |
40 | None => continue, | 38 | None => continue, |
41 | }; | 39 | }; |
42 | let range = match intersect(range, node.range()) { | 40 | let range = match range.intersection(&node.range()) { |
43 | Some(range) => range, | 41 | Some(range) => range, |
44 | None => continue, | 42 | None => continue, |
45 | } - node.range().start(); | 43 | } - node.range().start(); |
@@ -112,7 +110,7 @@ pub fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> { | |||
112 | } | 110 | } |
113 | if let Some(expr) = let_stmt.initializer() { | 111 | if let Some(expr) = let_stmt.initializer() { |
114 | let expr_range = expr.syntax().range(); | 112 | 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() { |
116 | return None; | 114 | return None; |
117 | } | 115 | } |
118 | if file | 116 | if file |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index b9b42f1b3..b7777bfc3 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -11,8 +11,7 @@ use languageserver_types::{ | |||
11 | use ra_analysis::{ | 11 | use ra_analysis::{ |
12 | FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange, | 12 | FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange, |
13 | }; | 13 | }; |
14 | use ra_syntax::{text_utils::intersect, TextUnit, AstNode}; | 14 | use ra_syntax::{TextUnit, AstNode}; |
15 | use ra_text_edit::text_utils::contains_offset_nonstrict; | ||
16 | use rustc_hash::FxHashMap; | 15 | use rustc_hash::FxHashMap; |
17 | use serde_json::to_value; | 16 | use serde_json::to_value; |
18 | use std::io::Write; | 17 | use std::io::Write; |
@@ -248,7 +247,7 @@ pub fn handle_runnables( | |||
248 | let mut res = Vec::new(); | 247 | let mut res = Vec::new(); |
249 | for runnable in world.analysis().runnables(file_id)? { | 248 | for runnable in world.analysis().runnables(file_id)? { |
250 | if let Some(offset) = offset { | 249 | if let Some(offset) = offset { |
251 | if !contains_offset_nonstrict(runnable.range, offset) { | 250 | if !runnable.range.contains_inclusive(offset) { |
252 | continue; | 251 | continue; |
253 | } | 252 | } |
254 | } | 253 | } |
@@ -650,7 +649,7 @@ pub fn handle_code_action( | |||
650 | .diagnostics(file_id)? | 649 | .diagnostics(file_id)? |
651 | .into_iter() | 650 | .into_iter() |
652 | .filter_map(|d| Some((d.range, d.fix?))) | 651 | .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()) |
654 | .map(|(_range, fix)| fix); | 653 | .map(|(_range, fix)| fix); |
655 | 654 | ||
656 | let mut res = Vec::new(); | 655 | let mut res = Vec::new(); |
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index eea0e251a..7c8e5b696 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -14,7 +14,7 @@ itertools = "0.8.0" | |||
14 | drop_bomb = "0.1.4" | 14 | drop_bomb = "0.1.4" |
15 | parking_lot = "0.7.0" | 15 | parking_lot = "0.7.0" |
16 | rowan = "0.2.0" | 16 | rowan = "0.2.0" |
17 | text_unit = "0.1.5" | 17 | text_unit = "0.1.6" |
18 | ra_text_edit = { path = "../ra_text_edit" } | 18 | ra_text_edit = { path = "../ra_text_edit" } |
19 | 19 | ||
20 | [dev-dependencies] | 20 | [dev-dependencies] |
diff --git a/crates/ra_syntax/src/text_utils.rs b/crates/ra_syntax/src/text_utils.rs index 417d43e1b..7aaf4c223 100644 --- a/crates/ra_syntax/src/text_utils.rs +++ b/crates/ra_syntax/src/text_utils.rs | |||
@@ -1,15 +1,5 @@ | |||
1 | use crate::TextRange; | 1 | use crate::TextRange; |
2 | 2 | ||
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 | |||
13 | pub fn replace_range(mut text: String, range: TextRange, replace_with: &str) -> String { | 3 | pub fn replace_range(mut text: String, range: TextRange, replace_with: &str) -> String { |
14 | let start = u32::from(range.start()) as usize; | 4 | let start = u32::from(range.start()) as usize; |
15 | let end = u32::from(range.end()) as usize; | 5 | let end = u32::from(range.end()) as usize; |
diff --git a/crates/ra_syntax/src/yellow/syntax_text.rs b/crates/ra_syntax/src/yellow/syntax_text.rs index 31db0fdab..08dbe57a2 100644 --- a/crates/ra_syntax/src/yellow/syntax_text.rs +++ b/crates/ra_syntax/src/yellow/syntax_text.rs | |||
@@ -1,10 +1,6 @@ | |||
1 | use std::{fmt, ops}; | 1 | use std::{fmt, ops}; |
2 | 2 | ||
3 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 3 | use crate::{SyntaxNode, TextRange, TextUnit}; |
4 | use crate::{ | ||
5 | text_utils::intersect, | ||
6 | SyntaxNode, TextRange, TextUnit, | ||
7 | }; | ||
8 | 4 | ||
9 | #[derive(Clone)] | 5 | #[derive(Clone)] |
10 | pub struct SyntaxText<'a> { | 6 | pub struct SyntaxText<'a> { |
@@ -23,7 +19,7 @@ impl<'a> SyntaxText<'a> { | |||
23 | let range = self.range; | 19 | let range = self.range; |
24 | self.node.descendants().filter_map(move |node| { | 20 | self.node.descendants().filter_map(move |node| { |
25 | let text = node.leaf_text()?; | 21 | let text = node.leaf_text()?; |
26 | let range = intersect(range, node.range())?; | 22 | let range = range.intersection(&node.range())?; |
27 | let range = range - node.range().start(); | 23 | let range = range - node.range().start(); |
28 | Some(&text[range]) | 24 | Some(&text[range]) |
29 | }) | 25 | }) |
@@ -92,13 +88,13 @@ pub trait SyntaxTextSlice: fmt::Debug { | |||
92 | 88 | ||
93 | impl SyntaxTextSlice for TextRange { | 89 | impl SyntaxTextSlice for TextRange { |
94 | fn restrict(&self, range: TextRange) -> Option<TextRange> { | 90 | fn restrict(&self, range: TextRange) -> Option<TextRange> { |
95 | intersect(*self, range) | 91 | self.intersection(&range) |
96 | } | 92 | } |
97 | } | 93 | } |
98 | 94 | ||
99 | impl SyntaxTextSlice for ops::RangeTo<TextUnit> { | 95 | impl SyntaxTextSlice for ops::RangeTo<TextUnit> { |
100 | fn restrict(&self, range: TextRange) -> Option<TextRange> { | 96 | fn restrict(&self, range: TextRange) -> Option<TextRange> { |
101 | if !contains_offset_nonstrict(range, self.end) { | 97 | if !range.contains_inclusive(self.end) { |
102 | return None; | 98 | return None; |
103 | } | 99 | } |
104 | Some(TextRange::from_to(range.start(), self.end)) | 100 | Some(TextRange::from_to(range.start(), self.end)) |
@@ -107,7 +103,7 @@ impl SyntaxTextSlice for ops::RangeTo<TextUnit> { | |||
107 | 103 | ||
108 | impl SyntaxTextSlice for ops::RangeFrom<TextUnit> { | 104 | impl SyntaxTextSlice for ops::RangeFrom<TextUnit> { |
109 | fn restrict(&self, range: TextRange) -> Option<TextRange> { | 105 | fn restrict(&self, range: TextRange) -> Option<TextRange> { |
110 | if !contains_offset_nonstrict(range, self.start) { | 106 | if !range.contains_inclusive(self.start) { |
111 | return None; | 107 | return None; |
112 | } | 108 | } |
113 | Some(TextRange::from_to(self.start, range.end())) | 109 | Some(TextRange::from_to(self.start, range.end())) |
diff --git a/crates/ra_text_edit/Cargo.toml b/crates/ra_text_edit/Cargo.toml index e0db49688..71f6ce1ad 100644 --- a/crates/ra_text_edit/Cargo.toml +++ b/crates/ra_text_edit/Cargo.toml | |||
@@ -6,7 +6,7 @@ authors = ["Aleksey Kladov <[email protected]>"] | |||
6 | publish = false | 6 | publish = false |
7 | 7 | ||
8 | [dependencies] | 8 | [dependencies] |
9 | text_unit = "0.1.5" | 9 | text_unit = "0.1.6" |
10 | proptest = "0.8.7" | 10 | proptest = "0.8.7" |
11 | 11 | ||
12 | [dev-dependencies] | 12 | [dev-dependencies] |
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs index 8acf10448..22f3fdc0c 100644 --- a/crates/ra_text_edit/src/lib.rs +++ b/crates/ra_text_edit/src/lib.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | mod text_edit; | 1 | mod text_edit; |
2 | pub mod text_utils; | ||
3 | pub mod test_utils; | 2 | pub mod test_utils; |
4 | 3 | ||
5 | pub use crate::text_edit::{TextEdit, TextEditBuilder}; | 4 | pub use crate::text_edit::{TextEdit, TextEditBuilder}; |
diff --git a/crates/ra_text_edit/src/text_edit.rs b/crates/ra_text_edit/src/text_edit.rs index a288a990d..363b3d8c0 100644 --- a/crates/ra_text_edit/src/text_edit.rs +++ b/crates/ra_text_edit/src/text_edit.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | use crate::AtomTextEdit; | 1 | use crate::AtomTextEdit; |
2 | use crate::text_utils::contains_offset_nonstrict; | ||
3 | use text_unit::{TextRange, TextUnit}; | 2 | use text_unit::{TextRange, TextUnit}; |
4 | 3 | ||
5 | #[derive(Debug, Clone)] | 4 | #[derive(Debug, Clone)] |
@@ -28,7 +27,7 @@ impl TextEditBuilder { | |||
28 | pub fn invalidates_offset(&self, offset: TextUnit) -> bool { | 27 | pub fn invalidates_offset(&self, offset: TextUnit) -> bool { |
29 | self.atoms | 28 | self.atoms |
30 | .iter() | 29 | .iter() |
31 | .any(|atom| contains_offset_nonstrict(atom.delete, offset)) | 30 | .any(|atom| atom.delete.contains_inclusive(offset)) |
32 | } | 31 | } |
33 | } | 32 | } |
34 | 33 | ||
diff --git a/crates/ra_text_edit/src/text_utils.rs b/crates/ra_text_edit/src/text_utils.rs deleted file mode 100644 index e3b4dc4fe..000000000 --- a/crates/ra_text_edit/src/text_utils.rs +++ /dev/null | |||
@@ -1,5 +0,0 @@ | |||
1 | use text_unit::{TextRange, TextUnit}; | ||
2 | |||
3 | pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool { | ||
4 | range.start() <= offset && offset <= range.end() | ||
5 | } | ||