From def124e932f02f5961d26af6cc03f696f389205f Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 3 Jan 2020 23:05:58 +0100 Subject: Fix file ID when qualifying paths; add another failing test --- .../src/assists/add_missing_impl_members.rs | 34 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'crates/ra_assists') 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( return None; } - let file_id = ctx.frange.file_id; let db = ctx.db; + let file_id = ctx.frange.file_id; + let trait_file_id = trait_.source(db).file_id; ctx.add_assist(AssistId(assist_id), label, |edit| { let n_existing_items = impl_item_list.impl_items().count(); @@ -157,10 +158,10 @@ fn add_missing_impl_members_inner( let items = missing_items .into_iter() .map(|it| { - substitute_type_params(db, hir::InFile::new(file_id.into(), it), &substs_by_param) + substitute_type_params(db, hir::InFile::new(trait_file_id, it), &substs_by_param) }) .map(|it| match module { - Some(module) => qualify_paths(db, hir::InFile::new(file_id.into(), it), module), + Some(module) => qualify_paths(db, hir::InFile::new(trait_file_id, it), module), None => it, }) .map(|it| match it { @@ -259,6 +260,7 @@ fn qualify_paths(db: &impl HirDatabase, node: hir::InFile, from: match resolution { PathResolution::Def(def) => { let found_path = from.find_path(db, def)?; + // TODO fix type arg replacements being qualified let args = p .segment() .and_then(|s| s.type_arg_list()) @@ -523,6 +525,32 @@ impl foo::Foo for S { ); } + #[test] + fn test_substitute_param_no_qualify() { + // when substituting params, the substituted param should not be qualified! + check_assist( + add_missing_impl_members, + " +mod foo { + trait Foo { fn foo(&self, bar: T); } + pub struct Param; +} +struct Param; +struct S; +impl foo::Foo for S { <|> }", + " +mod foo { + trait Foo { fn foo(&self, bar: T); } + pub struct Param; +} +struct Param; +struct S; +impl foo::Foo for S { + <|>fn foo(&self, bar: Param) { unimplemented!() } +}", + ); + } + #[test] fn test_qualify_path_associated_item() { check_assist( -- cgit v1.2.3