aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-09-25 14:19:22 +0100
committerLukas Wirth <[email protected]>2020-09-25 14:19:22 +0100
commite1d6981f90ba7852e949141dad0add855b57184a (patch)
treeb999ae8577aee299cb6d3592fcf8532f1b6abf75 /crates/assists/src
parent9d3483a74dba6b0a338230fd003d91a0447c5398 (diff)
Don't unnecessarily unnest imports for import insertion
Diffstat (limited to 'crates/assists/src')
-rw-r--r--crates/assists/src/handlers/add_missing_impl_members.rs35
-rw-r--r--crates/assists/src/handlers/auto_import.rs33
2 files changed, 66 insertions, 2 deletions
diff --git a/crates/assists/src/handlers/add_missing_impl_members.rs b/crates/assists/src/handlers/add_missing_impl_members.rs
index 8df1d786b..1ac5fefd6 100644
--- a/crates/assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/assists/src/handlers/add_missing_impl_members.rs
@@ -415,6 +415,41 @@ impl foo::Foo for S {
415 } 415 }
416 416
417 #[test] 417 #[test]
418 fn test_qualify_path_2() {
419 check_assist(
420 add_missing_impl_members,
421 r#"
422mod foo {
423 pub mod bar {
424 pub struct Bar;
425 pub trait Foo { fn foo(&self, bar: Bar); }
426 }
427}
428
429use foo::bar;
430
431struct S;
432impl bar::Foo for S { <|> }"#,
433 r#"
434mod foo {
435 pub mod bar {
436 pub struct Bar;
437 pub trait Foo { fn foo(&self, bar: Bar); }
438 }
439}
440
441use foo::bar;
442
443struct S;
444impl bar::Foo for S {
445 fn foo(&self, bar: bar::Bar) {
446 ${0:todo!()}
447 }
448}"#,
449 );
450 }
451
452 #[test]
418 fn test_qualify_path_generic() { 453 fn test_qualify_path_generic() {
419 check_assist( 454 check_assist(
420 add_missing_impl_members, 455 add_missing_impl_members,
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,