Skip to content

Commit 989de9e

Browse files
bors[bot]Veykril
andauthored
Merge #6172
6172: Add qualify path assist r=matklad a=Veykril This implements a `qualify_path` assist which works quite similar to the `auto_import` assist but instead of adding imports to the file it well, qualifies the path. This PR also moves out the `AutoImportAssets` struct and functions from `auto_import` into a utils submodule as most of this is now shared between `auto_import` and `qualify_path`. Changes made to `AutoImportAssets` are solely in its `search_for_imports` function which now takes a prefixed parameter to discern between using `find_use_path_prefixed` and `find_use_path` as the former is the required behavior by `auto_import` and the latter by this assist. For missing imported traits instead of importing this will qualify the path with a trait cast as in: ```rust test_mod::TestStruct::TEST_CONST<|> ``` becomes ```rust <test_mod::TestStruct as test_mod::TestTrait>::TEST_CONST ``` and for trait methods ideally it would do the following: ```rust let test_struct = test_mod::TestStruct {}; test_struct.test_meth<|>od() ``` becomes ```rust let test_struct = test_mod::TestStruct {}; test_mod::TestTrait::test_method(&test_struct) ``` Fixes #4124. Co-authored-by: Lukas Wirth <[email protected]>
2 parents 20d369a + 1d612a6 commit 989de9e

File tree

6 files changed

+1090
-24
lines changed

6 files changed

+1090
-24
lines changed

crates/assists/src/handlers/auto_import.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
100100
let group = import_group_message(import_assets.import_candidate());
101101
let scope = ImportScope::find_insert_use_container(import_assets.syntax_under_caret(), ctx)?;
102102
let syntax = scope.as_syntax_node();
103-
for import in proposed_imports {
103+
for (import, _) in proposed_imports {
104104
acc.add_group(
105105
&group,
106106
AssistId("auto_import", AssistKind::QuickFix),

0 commit comments

Comments
 (0)