diff options
author | Kirill Bulatov <[email protected]> | 2021-02-24 23:06:31 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-03-08 21:59:18 +0000 |
commit | 582cee2cdf5355b681f14bbb33bd5c431c284d87 (patch) | |
tree | 47d25e9c057759b1aa334abf3f584f1d0317d941 /crates/ide_assists | |
parent | 309421c117fc20e58b9f30fb28a01a89f50b0086 (diff) |
Return more data about located imports
Diffstat (limited to 'crates/ide_assists')
-rw-r--r-- | crates/ide_assists/src/handlers/auto_import.rs | 10 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/qualify_path.rs | 17 |
2 files changed, 18 insertions, 9 deletions
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index 5fe3f47fd..7188724be 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs | |||
@@ -92,14 +92,18 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
92 | let range = ctx.sema.original_range(&syntax_under_caret).range; | 92 | let range = ctx.sema.original_range(&syntax_under_caret).range; |
93 | let group = import_group_message(import_assets.import_candidate()); | 93 | let group = import_group_message(import_assets.import_candidate()); |
94 | let scope = ImportScope::find_insert_use_container(&syntax_under_caret, &ctx.sema)?; | 94 | let scope = ImportScope::find_insert_use_container(&syntax_under_caret, &ctx.sema)?; |
95 | for (import, _) in proposed_imports { | 95 | for import in proposed_imports { |
96 | acc.add_group( | 96 | acc.add_group( |
97 | &group, | 97 | &group, |
98 | AssistId("auto_import", AssistKind::QuickFix), | 98 | AssistId("auto_import", AssistKind::QuickFix), |
99 | format!("Import `{}`", &import), | 99 | format!("Import `{}`", import.display_path()), |
100 | range, | 100 | range, |
101 | |builder| { | 101 | |builder| { |
102 | let rewriter = insert_use(&scope, mod_path_to_ast(&import), ctx.config.insert_use); | 102 | let rewriter = insert_use( |
103 | &scope, | ||
104 | mod_path_to_ast(import.import_path()), | ||
105 | ctx.config.insert_use, | ||
106 | ); | ||
103 | builder.rewrite(rewriter); | 107 | builder.rewrite(rewriter); |
104 | }, | 108 | }, |
105 | ); | 109 | ); |
diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs index c0463311e..a40cdd80e 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs | |||
@@ -74,17 +74,17 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
74 | }; | 74 | }; |
75 | 75 | ||
76 | let group_label = group_label(candidate); | 76 | let group_label = group_label(candidate); |
77 | for (import, item) in proposed_imports { | 77 | for import in proposed_imports { |
78 | acc.add_group( | 78 | acc.add_group( |
79 | &group_label, | 79 | &group_label, |
80 | AssistId("qualify_path", AssistKind::QuickFix), | 80 | AssistId("qualify_path", AssistKind::QuickFix), |
81 | label(candidate, &import), | 81 | label(candidate, import.display_path()), |
82 | range, | 82 | range, |
83 | |builder| { | 83 | |builder| { |
84 | qualify_candidate.qualify( | 84 | qualify_candidate.qualify( |
85 | |replace_with: String| builder.replace(range, replace_with), | 85 | |replace_with: String| builder.replace(range, replace_with), |
86 | import, | 86 | import.import_path(), |
87 | item, | 87 | import.item_to_import(), |
88 | ) | 88 | ) |
89 | }, | 89 | }, |
90 | ); | 90 | ); |
@@ -100,8 +100,13 @@ enum QualifyCandidate<'db> { | |||
100 | } | 100 | } |
101 | 101 | ||
102 | impl QualifyCandidate<'_> { | 102 | impl QualifyCandidate<'_> { |
103 | fn qualify(&self, mut replacer: impl FnMut(String), import: hir::ModPath, item: hir::ItemInNs) { | 103 | fn qualify( |
104 | let import = mod_path_to_ast(&import); | 104 | &self, |
105 | mut replacer: impl FnMut(String), | ||
106 | import: &hir::ModPath, | ||
107 | item: hir::ItemInNs, | ||
108 | ) { | ||
109 | let import = mod_path_to_ast(import); | ||
105 | match self { | 110 | match self { |
106 | QualifyCandidate::QualifierStart(segment, generics) => { | 111 | QualifyCandidate::QualifierStart(segment, generics) => { |
107 | let generics = generics.as_ref().map_or_else(String::new, ToString::to_string); | 112 | let generics = generics.as_ref().map_or_else(String::new, ToString::to_string); |