aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/handlers/auto_import.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-09-25 15:57:15 +0100
committerGitHub <[email protected]>2020-09-25 15:57:15 +0100
commit662ed41ebcb1cd221b32be95d08b5bf5f10ae525 (patch)
tree943ef1bbcd95d9854975da1d2d9c6a3aa24e11ba /crates/assists/src/handlers/auto_import.rs
parentdc09f1597fea78900a6b67d4871edfbb6fafbcdc (diff)
parent747f6f64d7f8fae3a40be6ffacc9640bca068bd0 (diff)
Merge #6073
6073: Dont unnecessarily unnest imports r=matklad a=Veykril Fixes #6071 This has the side effect that paths that refer to items inside of the current module get prefixed with `self`. Changing this behavior is unfortunately not straightforward should it be unwanted, though I don't see a problem with this as prefixing imports like this with `self` is what I do personally anyways 😅. You can see what I mean with this in one of the tests which had to be changed in `crates/ssr/src/tests.rs`. There is one test that i still have to look at though, ~~which I by accident pushed with `#[ignore]` on it~~, which is `different_crate_renamed`, for some reason this now doesn't use the crate alias. This also makes me believe that aliases in general will break with this. So maybe this is not as straight forwards as I'd hoped for, but I don't really know how aliases work here. Edit: The failing test should work now Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/assists/src/handlers/auto_import.rs')
-rw-r--r--crates/assists/src/handlers/auto_import.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/crates/assists/src/handlers/auto_import.rs b/crates/assists/src/handlers/auto_import.rs
index b5eb2c722..ee7277c04 100644
--- a/crates/assists/src/handlers/auto_import.rs
+++ b/crates/assists/src/handlers/auto_import.rs
@@ -196,10 +196,10 @@ impl AutoImportAssets {
196 }) 196 })
197 .filter_map(|candidate| match candidate { 197 .filter_map(|candidate| match candidate {
198 Either::Left(module_def) => { 198 Either::Left(module_def) => {
199 self.module_with_name_to_import.find_use_path(db, module_def) 199 self.module_with_name_to_import.find_use_path_prefixed(db, module_def)
200 } 200 }
201 Either::Right(macro_def) => { 201 Either::Right(macro_def) => {
202 self.module_with_name_to_import.find_use_path(db, macro_def) 202 self.module_with_name_to_import.find_use_path_prefixed(db, macro_def)
203 } 203 }
204 }) 204 })
205 .filter(|use_path| !use_path.segments.is_empty()) 205 .filter(|use_path| !use_path.segments.is_empty())
@@ -291,6 +291,35 @@ mod tests {
291 use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; 291 use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
292 292
293 #[test] 293 #[test]
294 fn applicable_when_found_an_import_partial() {
295 check_assist(
296 auto_import,
297 r"
298 mod std {
299 pub mod fmt {
300 pub struct Formatter;
301 }
302 }
303
304 use std::fmt;
305
306 <|>Formatter
307 ",
308 r"
309 mod std {
310 pub mod fmt {
311 pub struct Formatter;
312 }
313 }
314
315 use std::fmt::{self, Formatter};
316
317 Formatter
318 ",
319 );
320 }
321
322 #[test]
294 fn applicable_when_found_an_import() { 323 fn applicable_when_found_an_import() {
295 check_assist( 324 check_assist(
296 auto_import, 325 auto_import,