aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/assists/src/handlers/merge_imports.rs14
-rw-r--r--crates/assists/src/handlers/replace_qualified_name_with_use.rs19
-rw-r--r--crates/assists/src/utils/insert_use.rs59
-rw-r--r--crates/base_db/Cargo.toml2
-rw-r--r--crates/flycheck/Cargo.toml2
-rw-r--r--crates/ide/Cargo.toml4
-rw-r--r--crates/ide/src/doc_links.rs25
-rw-r--r--crates/proc_macro_api/Cargo.toml2
-rw-r--r--crates/rust-analyzer/Cargo.toml4
-rw-r--r--crates/syntax/Cargo.toml2
-rw-r--r--crates/vfs-notify/Cargo.toml2
11 files changed, 109 insertions, 26 deletions
diff --git a/crates/assists/src/handlers/merge_imports.rs b/crates/assists/src/handlers/merge_imports.rs
index fe33cee53..fd9c9e03c 100644
--- a/crates/assists/src/handlers/merge_imports.rs
+++ b/crates/assists/src/handlers/merge_imports.rs
@@ -73,6 +73,20 @@ mod tests {
73 use super::*; 73 use super::*;
74 74
75 #[test] 75 #[test]
76 fn test_merge_equal() {
77 check_assist(
78 merge_imports,
79 r"
80use std::fmt<|>::{Display, Debug};
81use std::fmt::{Display, Debug};
82",
83 r"
84use std::fmt::{Debug, Display};
85",
86 )
87 }
88
89 #[test]
76 fn test_merge_first() { 90 fn test_merge_first() {
77 check_assist( 91 check_assist(
78 merge_imports, 92 merge_imports,
diff --git a/crates/assists/src/handlers/replace_qualified_name_with_use.rs b/crates/assists/src/handlers/replace_qualified_name_with_use.rs
index 74afc123b..c50bc7604 100644
--- a/crates/assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/crates/assists/src/handlers/replace_qualified_name_with_use.rs
@@ -124,6 +124,23 @@ mod tests {
124 use super::*; 124 use super::*;
125 125
126 #[test] 126 #[test]
127 fn test_replace_already_imported() {
128 check_assist(
129 replace_qualified_name_with_use,
130 r"use std::fs;
131
132fn main() {
133 std::f<|>s::Path
134}",
135 r"use std::fs;
136
137fn main() {
138 fs::Path
139}",
140 )
141 }
142
143 #[test]
127 fn test_replace_add_use_no_anchor() { 144 fn test_replace_add_use_no_anchor() {
128 check_assist( 145 check_assist(
129 replace_qualified_name_with_use, 146 replace_qualified_name_with_use,
@@ -393,7 +410,7 @@ impl std::fmt::Display<|> for Foo {
393} 410}
394", 411",
395 r" 412 r"
396use std::fmt::{Display, nested::Debug}; 413use std::fmt::{nested::Debug, Display};
397 414
398impl Display for Foo { 415impl Display for Foo {
399} 416}
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs
index f6025c99a..409985b3b 100644
--- a/crates/assists/src/utils/insert_use.rs
+++ b/crates/assists/src/utils/insert_use.rs
@@ -173,8 +173,15 @@ pub(crate) fn try_merge_trees(
173 let rhs_path = rhs.path()?; 173 let rhs_path = rhs.path()?;
174 174
175 let (lhs_prefix, rhs_prefix) = common_prefix(&lhs_path, &rhs_path)?; 175 let (lhs_prefix, rhs_prefix) = common_prefix(&lhs_path, &rhs_path)?;
176 let lhs = lhs.split_prefix(&lhs_prefix); 176 let (lhs, rhs) = if is_simple_path(lhs)
177 let rhs = rhs.split_prefix(&rhs_prefix); 177 && is_simple_path(rhs)
178 && lhs_path == lhs_prefix
179 && rhs_path == rhs_prefix
180 {
181 (lhs.clone(), rhs.clone())
182 } else {
183 (lhs.split_prefix(&lhs_prefix), rhs.split_prefix(&rhs_prefix))
184 };
178 recursive_merge(&lhs, &rhs, merge) 185 recursive_merge(&lhs, &rhs, merge)
179} 186}
180 187
@@ -200,7 +207,18 @@ fn recursive_merge(
200 return None; 207 return None;
201 } 208 }
202 let rhs_path = rhs_t.path(); 209 let rhs_path = rhs_t.path();
203 match use_trees.binary_search_by(|p| path_cmp_bin_search(p.path(), rhs_path.clone())) { 210 match use_trees.binary_search_by(|lhs_t| {
211 let (lhs_t, rhs_t) = match lhs_t
212 .path()
213 .zip(rhs_path.clone())
214 .and_then(|(lhs, rhs)| common_prefix(&lhs, &rhs))
215 {
216 Some((lhs_p, rhs_p)) => (lhs_t.split_prefix(&lhs_p), rhs_t.split_prefix(&rhs_p)),
217 None => (lhs_t.clone(), rhs_t.clone()),
218 };
219
220 path_cmp_bin_search(lhs_t.path(), rhs_t.path())
221 }) {
204 Ok(idx) => { 222 Ok(idx) => {
205 let lhs_t = &mut use_trees[idx]; 223 let lhs_t = &mut use_trees[idx];
206 let lhs_path = lhs_t.path()?; 224 let lhs_path = lhs_t.path()?;
@@ -239,6 +257,10 @@ fn recursive_merge(
239 use_trees.insert(idx, make::glob_use_tree()); 257 use_trees.insert(idx, make::glob_use_tree());
240 continue; 258 continue;
241 } 259 }
260
261 if lhs_t.use_tree_list().is_none() && rhs_t.use_tree_list().is_none() {
262 continue;
263 }
242 } 264 }
243 let lhs = lhs_t.split_prefix(&lhs_prefix); 265 let lhs = lhs_t.split_prefix(&lhs_prefix);
244 let rhs = rhs_t.split_prefix(&rhs_prefix); 266 let rhs = rhs_t.split_prefix(&rhs_prefix);
@@ -284,6 +306,10 @@ fn common_prefix(lhs: &ast::Path, rhs: &ast::Path) -> Option<(ast::Path, ast::Pa
284 } 306 }
285} 307}
286 308
309fn is_simple_path(use_tree: &ast::UseTree) -> bool {
310 use_tree.use_tree_list().is_none() && use_tree.star_token().is_none()
311}
312
287fn path_is_self(path: &ast::Path) -> bool { 313fn path_is_self(path: &ast::Path) -> bool {
288 path.segment().and_then(|seg| seg.self_token()).is_some() && path.qualifier().is_none() 314 path.segment().and_then(|seg| seg.self_token()).is_some() && path.qualifier().is_none()
289} 315}
@@ -327,11 +353,11 @@ fn path_cmp_for_sort(a: Option<ast::Path>, b: Option<ast::Path>) -> Ordering {
327 353
328/// Path comparison func for binary searching for merging. 354/// Path comparison func for binary searching for merging.
329fn path_cmp_bin_search(lhs: Option<ast::Path>, rhs: Option<ast::Path>) -> Ordering { 355fn path_cmp_bin_search(lhs: Option<ast::Path>, rhs: Option<ast::Path>) -> Ordering {
330 match (lhs, rhs) { 356 match (lhs.and_then(|path| path.segment()), rhs.and_then(|path| path.segment())) {
331 (None, None) => Ordering::Equal, 357 (None, None) => Ordering::Equal,
332 (None, Some(_)) => Ordering::Less, 358 (None, Some(_)) => Ordering::Less,
333 (Some(_), None) => Ordering::Greater, 359 (Some(_), None) => Ordering::Greater,
334 (Some(ref a), Some(ref b)) => path_cmp_short(a, b), 360 (Some(ref a), Some(ref b)) => path_segment_cmp(a, b),
335 } 361 }
336} 362}
337 363
@@ -513,6 +539,11 @@ mod tests {
513 use test_utils::assert_eq_text; 539 use test_utils::assert_eq_text;
514 540
515 #[test] 541 #[test]
542 fn insert_existing() {
543 check_full("std::fs", "use std::fs;", "use std::fs;")
544 }
545
546 #[test]
516 fn insert_start() { 547 fn insert_start() {
517 check_none( 548 check_none(
518 "std::bar::AA", 549 "std::bar::AA",
@@ -802,6 +833,24 @@ use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
802 } 833 }
803 834
804 #[test] 835 #[test]
836 fn merge_groups_full_nested_long() {
837 check_full(
838 "std::foo::bar::Baz",
839 r"use std::{foo::bar::Qux};",
840 r"use std::{foo::bar::{Baz, Qux}};",
841 );
842 }
843
844 #[test]
845 fn merge_groups_last_nested_long() {
846 check_full(
847 "std::foo::bar::Baz",
848 r"use std::{foo::bar::Qux};",
849 r"use std::{foo::bar::{Baz, Qux}};",
850 );
851 }
852
853 #[test]
805 fn merge_groups_skip_pub() { 854 fn merge_groups_skip_pub() {
806 check_full( 855 check_full(
807 "std::io", 856 "std::io",
diff --git a/crates/base_db/Cargo.toml b/crates/base_db/Cargo.toml
index f7bfcb0d7..1724d2f85 100644
--- a/crates/base_db/Cargo.toml
+++ b/crates/base_db/Cargo.toml
@@ -10,7 +10,7 @@ edition = "2018"
10doctest = false 10doctest = false
11 11
12[dependencies] 12[dependencies]
13salsa = "0.15.2" 13salsa = "0.16.0"
14rustc-hash = "1.1.0" 14rustc-hash = "1.1.0"
15 15
16syntax = { path = "../syntax", version = "0.0.0" } 16syntax = { path = "../syntax", version = "0.0.0" }
diff --git a/crates/flycheck/Cargo.toml b/crates/flycheck/Cargo.toml
index c230fc1e2..4e2b60b73 100644
--- a/crates/flycheck/Cargo.toml
+++ b/crates/flycheck/Cargo.toml
@@ -10,7 +10,7 @@ edition = "2018"
10doctest = false 10doctest = false
11 11
12[dependencies] 12[dependencies]
13crossbeam-channel = "0.4.0" 13crossbeam-channel = "0.5.0"
14log = "0.4.8" 14log = "0.4.8"
15cargo_metadata = "0.11.1" 15cargo_metadata = "0.11.1"
16serde_json = "1.0.48" 16serde_json = "1.0.48"
diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml
index f0257403d..29dc9a6a8 100644
--- a/crates/ide/Cargo.toml
+++ b/crates/ide/Cargo.toml
@@ -16,8 +16,8 @@ itertools = "0.9.0"
16log = "0.4.8" 16log = "0.4.8"
17rustc-hash = "1.1.0" 17rustc-hash = "1.1.0"
18oorandom = "11.1.2" 18oorandom = "11.1.2"
19pulldown-cmark-to-cmark = "5.0.0" 19pulldown-cmark-to-cmark = "6.0.0"
20pulldown-cmark = {version = "0.7.2", default-features = false} 20pulldown-cmark = { version = "0.8.0", default-features = false }
21url = "2.1.1" 21url = "2.1.1"
22 22
23stdx = { path = "../stdx", version = "0.0.0" } 23stdx = { path = "../stdx", version = "0.0.0" }
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index 06af36b73..db3f911c8 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -1,9 +1,10 @@
1//! Resolves and rewrites links in markdown documentation. 1//! Resolves and rewrites links in markdown documentation.
2 2
3use std::convert::TryFrom;
3use std::iter::once; 4use std::iter::once;
4 5
5use itertools::Itertools; 6use itertools::Itertools;
6use pulldown_cmark::{CowStr, Event, LinkType, Options, Parser, Tag}; 7use pulldown_cmark::{BrokenLink, CowStr, Event, InlineStr, LinkType, Options, Parser, Tag};
7use pulldown_cmark_to_cmark::{cmark_with_options, Options as CmarkOptions}; 8use pulldown_cmark_to_cmark::{cmark_with_options, Options as CmarkOptions};
8use url::Url; 9use url::Url;
9 10
@@ -24,11 +25,13 @@ pub type DocumentationLink = String;
24 25
25/// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs) 26/// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs)
26pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String { 27pub fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String {
27 let doc = Parser::new_with_broken_link_callback( 28 let mut cb = |link: BrokenLink| {
28 markdown, 29 Some((
29 Options::empty(), 30 /*url*/ link.reference.to_owned().into(),
30 Some(&|label, _| Some((/*url*/ label.to_string(), /*title*/ label.to_string()))), 31 /*title*/ link.reference.to_owned().into(),
31 ); 32 ))
33 };
34 let doc = Parser::new_with_broken_link_callback(markdown, Options::empty(), Some(&mut cb));
32 35
33 let doc = map_links(doc, |target, title: &str| { 36 let doc = map_links(doc, |target, title: &str| {
34 // This check is imperfect, there's some overlap between valid intra-doc links 37 // This check is imperfect, there's some overlap between valid intra-doc links
@@ -66,11 +69,11 @@ pub fn remove_links(markdown: &str) -> String {
66 let mut opts = Options::empty(); 69 let mut opts = Options::empty();
67 opts.insert(Options::ENABLE_FOOTNOTES); 70 opts.insert(Options::ENABLE_FOOTNOTES);
68 71
69 let doc = Parser::new_with_broken_link_callback( 72 let mut cb = |_: BrokenLink| {
70 markdown, 73 let empty = InlineStr::try_from("").unwrap();
71 opts, 74 Some((CowStr::Inlined(empty.clone()), CowStr::Inlined(empty)))
72 Some(&|_, _| Some((String::new(), String::new()))), 75 };
73 ); 76 let doc = Parser::new_with_broken_link_callback(markdown, opts, Some(&mut cb));
74 let doc = doc.filter_map(move |evt| match evt { 77 let doc = doc.filter_map(move |evt| match evt {
75 Event::Start(Tag::Link(link_type, ref target, ref title)) => { 78 Event::Start(Tag::Link(link_type, ref target, ref title)) => {
76 if link_type == LinkType::Inline && target.contains("://") { 79 if link_type == LinkType::Inline && target.contains("://") {
diff --git a/crates/proc_macro_api/Cargo.toml b/crates/proc_macro_api/Cargo.toml
index 75f67a22e..3863e5189 100644
--- a/crates/proc_macro_api/Cargo.toml
+++ b/crates/proc_macro_api/Cargo.toml
@@ -13,7 +13,7 @@ doctest = false
13serde = { version = "1.0", features = ["derive"] } 13serde = { version = "1.0", features = ["derive"] }
14serde_json = "1.0" 14serde_json = "1.0"
15log = "0.4.8" 15log = "0.4.8"
16crossbeam-channel = "0.4.0" 16crossbeam-channel = "0.5.0"
17jod-thread = "0.1.1" 17jod-thread = "0.1.1"
18 18
19tt = { path = "../tt", version = "0.0.0" } 19tt = { path = "../tt", version = "0.0.0" }
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index 631ffc4a7..df2ea6f85 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -16,7 +16,7 @@ path = "src/bin/main.rs"
16 16
17[dependencies] 17[dependencies]
18anyhow = "1.0.26" 18anyhow = "1.0.26"
19crossbeam-channel = "0.4.0" 19crossbeam-channel = "0.5.0"
20env_logger = { version = "0.7.1", default-features = false } 20env_logger = { version = "0.7.1", default-features = false }
21itertools = "0.9.0" 21itertools = "0.9.0"
22jod-thread = "0.1.0" 22jod-thread = "0.1.0"
@@ -31,7 +31,7 @@ serde_json = "1.0.48"
31threadpool = "1.7.1" 31threadpool = "1.7.1"
32rayon = "1.3.1" 32rayon = "1.3.1"
33mimalloc = { version = "0.1.19", default-features = false, optional = true } 33mimalloc = { version = "0.1.19", default-features = false, optional = true }
34lsp-server = "0.3.3" 34lsp-server = "0.4.0"
35 35
36stdx = { path = "../stdx", version = "0.0.0" } 36stdx = { path = "../stdx", version = "0.0.0" }
37flycheck = { path = "../flycheck", version = "0.0.0" } 37flycheck = { path = "../flycheck", version = "0.0.0" }
diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml
index 547fe9f47..c343f2f70 100644
--- a/crates/syntax/Cargo.toml
+++ b/crates/syntax/Cargo.toml
@@ -13,7 +13,7 @@ doctest = false
13[dependencies] 13[dependencies]
14itertools = "0.9.0" 14itertools = "0.9.0"
15rowan = "0.10.0" 15rowan = "0.10.0"
16rustc_lexer = { version = "682.0.0", package = "rustc-ap-rustc_lexer" } 16rustc_lexer = { version = "683.0.0", package = "rustc-ap-rustc_lexer" }
17rustc-hash = "1.1.0" 17rustc-hash = "1.1.0"
18arrayvec = "0.5.1" 18arrayvec = "0.5.1"
19once_cell = "1.3.1" 19once_cell = "1.3.1"
diff --git a/crates/vfs-notify/Cargo.toml b/crates/vfs-notify/Cargo.toml
index 54b51faab..5b7c33b01 100644
--- a/crates/vfs-notify/Cargo.toml
+++ b/crates/vfs-notify/Cargo.toml
@@ -14,7 +14,7 @@ log = "0.4.8"
14rustc-hash = "1.0" 14rustc-hash = "1.0"
15jod-thread = "0.1.0" 15jod-thread = "0.1.0"
16walkdir = "2.3.1" 16walkdir = "2.3.1"
17crossbeam-channel = "0.4.0" 17crossbeam-channel = "0.5.0"
18notify = "5.0.0-pre.3" 18notify = "5.0.0-pre.3"
19 19
20vfs = { path = "../vfs", version = "0.0.0" } 20vfs = { path = "../vfs", version = "0.0.0" }