diff options
author | Kirill Bulatov <[email protected]> | 2021-02-28 22:05:22 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-03-08 21:59:20 +0000 |
commit | e74c55bb4adcad001b0f7373ebff795fc2aaeb1b (patch) | |
tree | 89bd5dd5a67183d5f94988f35b5c43b70846f293 /crates/ide_completion/src | |
parent | 89d410cef571f5fa7631b17e2fbe52a8f8f03990 (diff) |
Refactor the import location
Diffstat (limited to 'crates/ide_completion/src')
-rw-r--r-- | crates/ide_completion/src/completions/flyimport.rs | 65 |
1 files changed, 5 insertions, 60 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index d6adf70b1..55439d0e5 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs | |||
@@ -95,20 +95,20 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) | |||
95 | .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) | 95 | .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind) |
96 | .into_iter() | 96 | .into_iter() |
97 | .map(|import| { | 97 | .map(|import| { |
98 | let proposed_def = match import.item_to_display() { | 98 | let def_to_display = match import.item_to_display() { |
99 | ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), | 99 | ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), |
100 | ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), | 100 | ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), |
101 | ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), | 101 | ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), |
102 | }; | 102 | }; |
103 | (import, proposed_def) | 103 | (import, def_to_display) |
104 | }) | 104 | }) |
105 | .collect::<Vec<_>>(); | 105 | .collect::<Vec<_>>(); |
106 | all_mod_paths.sort_by_cached_key(|(import, _)| { | 106 | all_mod_paths.sort_by_cached_key(|(import, _)| { |
107 | compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased) | 107 | compute_fuzzy_completion_order_key(import.display_path(), &user_input_lowercased) |
108 | }); | 108 | }); |
109 | 109 | ||
110 | acc.add_all(all_mod_paths.into_iter().filter_map(|(import, definition)| { | 110 | acc.add_all(all_mod_paths.into_iter().filter_map(|(import, def_to_display)| { |
111 | let import_for_trait_assoc_item = match definition { | 111 | let import_for_trait_assoc_item = match def_to_display { |
112 | ScopeDef::ModuleDef(module_def) => module_def | 112 | ScopeDef::ModuleDef(module_def) => module_def |
113 | .as_assoc_item(ctx.db) | 113 | .as_assoc_item(ctx.db) |
114 | .and_then(|assoc| assoc.containing_trait(ctx.db)) | 114 | .and_then(|assoc| assoc.containing_trait(ctx.db)) |
@@ -117,7 +117,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext) | |||
117 | }; | 117 | }; |
118 | let import_edit = | 118 | let import_edit = |
119 | ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item }; | 119 | ImportEdit { import, import_scope: import_scope.clone(), import_for_trait_assoc_item }; |
120 | render_resolution_with_import(RenderContext::new(ctx), import_edit, &definition) | 120 | render_resolution_with_import(RenderContext::new(ctx), import_edit, &def_to_display) |
121 | })); | 121 | })); |
122 | Some(()) | 122 | Some(()) |
123 | } | 123 | } |
@@ -870,59 +870,4 @@ fn main() { | |||
870 | "#, | 870 | "#, |
871 | ); | 871 | ); |
872 | } | 872 | } |
873 | |||
874 | #[test] | ||
875 | fn unresolved_assoc_item_container_and_trait_with_path() { | ||
876 | check_edit( | ||
877 | "TEST_ASSOC", | ||
878 | r#" | ||
879 | mod foo { | ||
880 | pub mod bar { | ||
881 | pub trait SomeTrait { | ||
882 | const TEST_ASSOC: usize; | ||
883 | } | ||
884 | } | ||
885 | |||
886 | pub mod baz { | ||
887 | use super::bar::SomeTrait; | ||
888 | |||
889 | pub struct Item; | ||
890 | |||
891 | impl SomeTrait for Item { | ||
892 | const TEST_ASSOC: usize = 3; | ||
893 | } | ||
894 | } | ||
895 | } | ||
896 | |||
897 | fn main() { | ||
898 | baz::Item::TEST_A$0 | ||
899 | } | ||
900 | "#, | ||
901 | r#" | ||
902 | use foo::{bar::SomeTrait, baz}; | ||
903 | |||
904 | mod foo { | ||
905 | pub mod bar { | ||
906 | pub trait SomeTrait { | ||
907 | const TEST_ASSOC: usize; | ||
908 | } | ||
909 | } | ||
910 | |||
911 | pub mod baz { | ||
912 | use super::bar::SomeTrait; | ||
913 | |||
914 | pub struct Item; | ||
915 | |||
916 | impl SomeTrait for Item { | ||
917 | const TEST_ASSOC: usize = 3; | ||
918 | } | ||
919 | } | ||
920 | } | ||
921 | |||
922 | fn main() { | ||
923 | baz::Item::TEST_ASSOC | ||
924 | } | ||
925 | "#, | ||
926 | ); | ||
927 | } | ||
928 | } | 873 | } |