diff options
author | Florian Diebold <[email protected]> | 2020-01-03 22:05:58 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-01-11 22:33:04 +0000 |
commit | def124e932f02f5961d26af6cc03f696f389205f (patch) | |
tree | 14e2bb6397dd7ec25ede212090619eb16c4e9a95 /crates/ra_assists | |
parent | 4545f289a991ec3888896aac0e0bcbfac9061e80 (diff) |
Fix file ID when qualifying paths; add another failing test
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/assists/add_missing_impl_members.rs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/assists/add_missing_impl_members.rs index 7b50fb422..22f1157cc 100644 --- a/crates/ra_assists/src/assists/add_missing_impl_members.rs +++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs | |||
@@ -134,8 +134,9 @@ fn add_missing_impl_members_inner( | |||
134 | return None; | 134 | return None; |
135 | } | 135 | } |
136 | 136 | ||
137 | let file_id = ctx.frange.file_id; | ||
138 | let db = ctx.db; | 137 | let db = ctx.db; |
138 | let file_id = ctx.frange.file_id; | ||
139 | let trait_file_id = trait_.source(db).file_id; | ||
139 | 140 | ||
140 | ctx.add_assist(AssistId(assist_id), label, |edit| { | 141 | ctx.add_assist(AssistId(assist_id), label, |edit| { |
141 | let n_existing_items = impl_item_list.impl_items().count(); | 142 | let n_existing_items = impl_item_list.impl_items().count(); |
@@ -157,10 +158,10 @@ fn add_missing_impl_members_inner( | |||
157 | let items = missing_items | 158 | let items = missing_items |
158 | .into_iter() | 159 | .into_iter() |
159 | .map(|it| { | 160 | .map(|it| { |
160 | substitute_type_params(db, hir::InFile::new(file_id.into(), it), &substs_by_param) | 161 | substitute_type_params(db, hir::InFile::new(trait_file_id, it), &substs_by_param) |
161 | }) | 162 | }) |
162 | .map(|it| match module { | 163 | .map(|it| match module { |
163 | Some(module) => qualify_paths(db, hir::InFile::new(file_id.into(), it), module), | 164 | Some(module) => qualify_paths(db, hir::InFile::new(trait_file_id, it), module), |
164 | None => it, | 165 | None => it, |
165 | }) | 166 | }) |
166 | .map(|it| match it { | 167 | .map(|it| match it { |
@@ -259,6 +260,7 @@ fn qualify_paths<N: AstNode>(db: &impl HirDatabase, node: hir::InFile<N>, from: | |||
259 | match resolution { | 260 | match resolution { |
260 | PathResolution::Def(def) => { | 261 | PathResolution::Def(def) => { |
261 | let found_path = from.find_path(db, def)?; | 262 | let found_path = from.find_path(db, def)?; |
263 | // TODO fix type arg replacements being qualified | ||
262 | let args = p | 264 | let args = p |
263 | .segment() | 265 | .segment() |
264 | .and_then(|s| s.type_arg_list()) | 266 | .and_then(|s| s.type_arg_list()) |
@@ -524,6 +526,32 @@ impl foo::Foo<u32> for S { | |||
524 | } | 526 | } |
525 | 527 | ||
526 | #[test] | 528 | #[test] |
529 | fn test_substitute_param_no_qualify() { | ||
530 | // when substituting params, the substituted param should not be qualified! | ||
531 | check_assist( | ||
532 | add_missing_impl_members, | ||
533 | " | ||
534 | mod foo { | ||
535 | trait Foo<T> { fn foo(&self, bar: T); } | ||
536 | pub struct Param; | ||
537 | } | ||
538 | struct Param; | ||
539 | struct S; | ||
540 | impl foo::Foo<Param> for S { <|> }", | ||
541 | " | ||
542 | mod foo { | ||
543 | trait Foo<T> { fn foo(&self, bar: T); } | ||
544 | pub struct Param; | ||
545 | } | ||
546 | struct Param; | ||
547 | struct S; | ||
548 | impl foo::Foo<Param> for S { | ||
549 | <|>fn foo(&self, bar: Param) { unimplemented!() } | ||
550 | }", | ||
551 | ); | ||
552 | } | ||
553 | |||
554 | #[test] | ||
527 | fn test_qualify_path_associated_item() { | 555 | fn test_qualify_path_associated_item() { |
528 | check_assist( | 556 | check_assist( |
529 | add_missing_impl_members, | 557 | add_missing_impl_members, |