This repository was archived by the owner on May 28, 2025. It is now read-only.
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
@@ -1343,4 +1351,95 @@ impl PartialEq for SomeStruct {
13431351"# ,
13441352 ) ;
13451353 }
1354+
1355+ #[ test]
1356+ fn test_ignore_function_body ( ) {
1357+ check_assist_not_applicable (
1358+ add_missing_default_members,
1359+ r#"
1360+ trait Trait {
1361+ type X;
1362+ fn foo(&self);
1363+ fn bar(&self) {}
1364+ }
1365+
1366+ impl Trait for () {
1367+ type X = u8;
1368+ fn foo(&self) {$0
1369+ let x = 5;
1370+ }
1371+ }"# ,
1372+ )
1373+ }
1374+
1375+ #[ test]
1376+ fn test_ignore_param_list ( ) {
1377+ check_assist_not_applicable (
1378+ add_missing_impl_members,
1379+ r#"
1380+ trait Trait {
1381+ type X;
1382+ fn foo(&self);
1383+ fn bar(&self);
1384+ }
1385+
1386+ impl Trait for () {
1387+ type X = u8;
1388+ fn foo(&self$0) {
1389+ let x = 5;
1390+ }
1391+ }"# ,
1392+ )
1393+ }
1394+
1395+ #[ test]
1396+ fn test_ignore_scope_inside_function ( ) {
1397+ check_assist_not_applicable (
1398+ add_missing_impl_members,
1399+ r#"
1400+ trait Trait {
1401+ type X;
1402+ fn foo(&self);
1403+ fn bar(&self);
1404+ }
1405+
1406+ impl Trait for () {
1407+ type X = u8;
1408+ fn foo(&self) {
1409+ let x = async {$0 5 };
1410+ }
1411+ }"# ,
1412+ )
1413+ }
1414+
1415+ #[ test]
1416+ fn test_apply_outside_function ( ) {
1417+ check_assist (
1418+ add_missing_default_members,
1419+ r#"
1420+ trait Trait {
1421+ type X;
1422+ fn foo(&self);
1423+ fn bar(&self) {}
1424+ }
1425+
1426+ impl Trait for () {
1427+ type X = u8;
1428+ fn foo(&self)$0 {}
1429+ }"# ,
1430+ r#"
1431+ trait Trait {
1432+ type X;
1433+ fn foo(&self);
1434+ fn bar(&self) {}
1435+ }
1436+
1437+ impl Trait for () {
1438+ type X = u8;
1439+ fn foo(&self) {}
1440+
1441+ $0fn bar(&self) {}
1442+ }"# ,
1443+ )
1444+ }
13461445}
You can’t perform that action at this time.
0 commit comments