File tree Expand file tree Collapse file tree 1 file changed +99
-0
lines changed
crates/ide-assists/src/handlers Expand file tree Collapse file tree 1 file changed +99
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,14 @@ fn add_missing_impl_members_inner(
107107) -> Option < ( ) > {
108108 let _p = profile:: span ( "add_missing_impl_members_inner" ) ;
109109 let impl_def = ctx. find_node_at_offset :: < ast:: Impl > ( ) ?;
110+
111+ if ctx. token_at_offset ( ) . all ( |t| {
112+ t. parent_ancestors ( )
113+ . any ( |s| ast:: BlockExpr :: can_cast ( s. kind ( ) ) || ast:: ParamList :: can_cast ( s. kind ( ) ) )
114+ } ) {
115+ return None ;
116+ }
117+
110118 let target_scope = ctx. sema . scope ( impl_def. syntax ( ) ) ?;
111119 let trait_ = resolve_target_trait ( & ctx. sema , & impl_def) ?;
112120
@@ -1337,4 +1345,95 @@ impl PartialEq for SomeStruct {
13371345"# ,
13381346 ) ;
13391347 }
1348+
1349+ #[ test]
1350+ fn test_ignore_function_body ( ) {
1351+ check_assist_not_applicable (
1352+ add_missing_default_members,
1353+ r#"
1354+ trait Trait {
1355+ type X;
1356+ fn foo(&self);
1357+ fn bar(&self) {}
1358+ }
1359+
1360+ impl Trait for () {
1361+ type X = u8;
1362+ fn foo(&self) {$0
1363+ let x = 5;
1364+ }
1365+ }"# ,
1366+ )
1367+ }
1368+
1369+ #[ test]
1370+ fn test_ignore_param_list ( ) {
1371+ check_assist_not_applicable (
1372+ add_missing_impl_members,
1373+ r#"
1374+ trait Trait {
1375+ type X;
1376+ fn foo(&self);
1377+ fn bar(&self);
1378+ }
1379+
1380+ impl Trait for () {
1381+ type X = u8;
1382+ fn foo(&self$0) {
1383+ let x = 5;
1384+ }
1385+ }"# ,
1386+ )
1387+ }
1388+
1389+ #[ test]
1390+ fn test_ignore_scope_inside_function ( ) {
1391+ check_assist_not_applicable (
1392+ add_missing_impl_members,
1393+ r#"
1394+ trait Trait {
1395+ type X;
1396+ fn foo(&self);
1397+ fn bar(&self);
1398+ }
1399+
1400+ impl Trait for () {
1401+ type X = u8;
1402+ fn foo(&self) {
1403+ let x = async {$0 5 };
1404+ }
1405+ }"# ,
1406+ )
1407+ }
1408+
1409+ #[ test]
1410+ fn test_apply_outside_function ( ) {
1411+ check_assist (
1412+ add_missing_default_members,
1413+ r#"
1414+ trait Trait {
1415+ type X;
1416+ fn foo(&self);
1417+ fn bar(&self) {}
1418+ }
1419+
1420+ impl Trait for () {
1421+ type X = u8;
1422+ fn foo(&self)$0 {}
1423+ }"# ,
1424+ r#"
1425+ trait Trait {
1426+ type X;
1427+ fn foo(&self);
1428+ fn bar(&self) {}
1429+ }
1430+
1431+ impl Trait for () {
1432+ type X = u8;
1433+ fn foo(&self) {}
1434+
1435+ $0fn bar(&self) {}
1436+ }"# ,
1437+ )
1438+ }
13401439}
You can’t perform that action at this time.
0 commit comments