@@ -13,6 +13,7 @@ import dotty.tools.dotc.ast.Trees.*
13
13
import dotty .tools .dotc .ast .tpd
14
14
import dotty .tools .dotc .ast .tpd .DeepFolder
15
15
import dotty .tools .dotc .core .Contexts .*
16
+ import dotty .tools .dotc .core .Flags
16
17
import dotty .tools .dotc .core .Symbols .Symbol
17
18
import dotty .tools .dotc .core .Types .MethodType
18
19
import dotty .tools .dotc .core .Types .PolyType
@@ -116,9 +117,15 @@ final class ExtractMethodProvider(
116
117
typeParams.toList.sortBy(_.decodedName),
117
118
)
118
119
end localRefs
120
+ val optEnclosing =
121
+ path.dropWhile(src => ! src.sourcePos.encloses(range)) match
122
+ case Nil => None
123
+ case _ :: (app @ Apply (fun, args)) :: _ if args.exists(ImplicitParameters .isSyntheticArg(_)) => Some (app)
124
+ case found :: _ => Some (found)
125
+
119
126
val edits =
120
127
for
121
- enclosing <- path.find(src => src.sourcePos.encloses(range))
128
+ enclosing <- optEnclosing
122
129
extracted = extractFromBlock(enclosing)
123
130
head <- extracted.headOption
124
131
expr <- extracted.lastOption
@@ -131,11 +138,14 @@ final class ExtractMethodProvider(
131
138
val exprType = prettyPrint(expr.typeOpt.widen)
132
139
val name =
133
140
genName(indexedCtx.scopeSymbols.map(_.decodedName).toSet, " newMethod" )
134
- val (methodParams , typeParams) =
141
+ val (allMethodParams , typeParams) =
135
142
localRefs(extracted, stat.sourcePos, extractedPos)
136
- val methodParamsText = methodParams
137
- .map(sym => s " ${sym.decodedName}: ${prettyPrint(sym.info)}" )
138
- .mkString(" , " )
143
+ val (methodParams, implicitParams) = allMethodParams.partition(! _.isOneOf(Flags .GivenOrImplicit ))
144
+ def toParamText (params : List [Symbol ]) =
145
+ params.map(sym => s " ${sym.decodedName}: ${prettyPrint(sym.info)}" )
146
+ .mkString(" , " )
147
+ val methodParamsText = toParamText(methodParams)
148
+ val implicitParamsText = if implicitParams.nonEmpty then s " (given ${toParamText(implicitParams)}) " else " "
139
149
val typeParamsText = typeParams
140
150
.map(_.decodedName) match
141
151
case Nil => " "
@@ -155,7 +165,7 @@ final class ExtractMethodProvider(
155
165
if noIndent && extracted.length > 1 then (" {" , s " $newIndent} " )
156
166
else (" " , " " )
157
167
val defText =
158
- s " def $name$typeParamsText( $methodParamsText): $exprType = $obracket\n ${toExtract}\n $cbracket\n $newIndent"
168
+ s " def $name$typeParamsText( $methodParamsText) $implicitParamsText : $exprType = $obracket\n ${toExtract}\n $cbracket\n $newIndent"
159
169
val replacedText = s " $name( $exprParamsText) "
160
170
List (
161
171
new l.TextEdit (
0 commit comments