@@ -548,7 +548,12 @@ func refactorRewriteRemoveUnusedParam(ctx context.Context, req *codeActionsReque
548548}
549549
550550func refactorRewriteMoveParamLeft (ctx context.Context , req * codeActionsRequest ) error {
551- if info := findParam (req .pgf , req .loc .Range ); info != nil && info .paramIndex > 0 {
551+ if info := findParam (req .pgf , req .loc .Range ); info != nil &&
552+ info .paramIndex > 0 &&
553+ ! is [* ast.Ellipsis ](info .field .Type ) {
554+
555+ // ^^ we can't currently handle moving a variadic param.
556+ // TODO(rfindley): implement.
552557
553558 transform := identityTransform (info .decl .Type .Params )
554559 transform [info .paramIndex ] = command.ChangeSignatureParam {OldIndex : info .paramIndex - 1 }
@@ -566,19 +571,27 @@ func refactorRewriteMoveParamLeft(ctx context.Context, req *codeActionsRequest)
566571}
567572
568573func refactorRewriteMoveParamRight (ctx context.Context , req * codeActionsRequest ) error {
569- if info := findParam (req .pgf , req .loc .Range ); info != nil && info .paramIndex >= 0 && // found a param
570- info .paramIndex < info .decl .Type .Params .NumFields ()- 1 { // not the last param
574+ if info := findParam (req .pgf , req .loc .Range ); info != nil && info .paramIndex >= 0 {
575+ params := info .decl .Type .Params
576+ nparams := params .NumFields ()
577+ if info .paramIndex < nparams - 1 { // not the last param
578+ if info .paramIndex == nparams - 2 && is [* ast.Ellipsis ](params .List [len (params .List )- 1 ].Type ) {
579+ // We can't currently handle moving a variadic param.
580+ // TODO(rfindley): implement.
581+ return nil
582+ }
571583
572- transform := identityTransform (info .decl .Type .Params )
573- transform [info .paramIndex ] = command.ChangeSignatureParam {OldIndex : info .paramIndex + 1 }
574- transform [info .paramIndex + 1 ] = command.ChangeSignatureParam {OldIndex : info .paramIndex }
575- cmd := command .NewChangeSignatureCommand ("Move parameter right" , command.ChangeSignatureArgs {
576- Location : req .loc ,
577- NewParams : transform ,
578- NewResults : identityTransform (info .decl .Type .Results ),
579- ResolveEdits : req .resolveEdits (),
580- })
581- req .addCommandAction (cmd , true )
584+ transform := identityTransform (info .decl .Type .Params )
585+ transform [info .paramIndex ] = command.ChangeSignatureParam {OldIndex : info .paramIndex + 1 }
586+ transform [info .paramIndex + 1 ] = command.ChangeSignatureParam {OldIndex : info .paramIndex }
587+ cmd := command .NewChangeSignatureCommand ("Move parameter right" , command.ChangeSignatureArgs {
588+ Location : req .loc ,
589+ NewParams : transform ,
590+ NewResults : identityTransform (info .decl .Type .Results ),
591+ ResolveEdits : req .resolveEdits (),
592+ })
593+ req .addCommandAction (cmd , true )
594+ }
582595 }
583596 return nil
584597}
0 commit comments