@@ -55,6 +55,14 @@ case class ScalaPresentationCompiler(
55
55
completionItemPriority : CompletionItemPriority = (_ : String ) => 0 ,
56
56
) extends PresentationCompiler :
57
57
58
+ override def supportedCodeActions (): ju.List [String ] = List (
59
+ CodeActionId .ConvertToNamedArguments ,
60
+ CodeActionId .ImplementAbstractMembers ,
61
+ CodeActionId .ExtractMethod ,
62
+ CodeActionId .InlineValue ,
63
+ CodeActionId .InsertInferredType
64
+ ).asJava
65
+
58
66
def this () = this (" " , None , Nil , Nil )
59
67
60
68
val scalaVersion = BuildInfo .scalaVersion
@@ -67,6 +75,42 @@ case class ScalaPresentationCompiler(
67
75
.map(StdReportContext (_, _ => buildTargetName, reportsLevel))
68
76
.getOrElse(EmptyReportContext )
69
77
78
+ override def codeAction [T ](
79
+ params : OffsetParams ,
80
+ codeActionId : String ,
81
+ codeActionPayload : Optional [T ]
82
+ ): CompletableFuture [ju.List [TextEdit ]] = {
83
+ (codeActionId, codeActionPayload.asScala) match {
84
+ case (
85
+ CodeActionId .ConvertToNamedArguments ,
86
+ Some (argIndices : ju.List [_])
87
+ ) =>
88
+ val payload = argIndices.asScala.collect { case i : Integer =>
89
+ i.toInt
90
+ }.toSet
91
+ convertToNamedArguments(params, payload)
92
+ case (CodeActionId .ImplementAbstractMembers , _) =>
93
+ implementAbstractMembers(params)
94
+ case (CodeActionId .InsertInferredType , _) =>
95
+ insertInferredType(params)
96
+ case (CodeActionId .InlineValue , _) =>
97
+ inlineValue(params)
98
+ case (CodeActionId .ExtractMethod , Some (extractionPos : OffsetParams )) =>
99
+ params match {
100
+ case range : RangeParams =>
101
+ extractMethod(range, extractionPos)
102
+ case _ =>
103
+ CompletableFuture .failedFuture(
104
+ new IllegalArgumentException (s " Expected range parameters " )
105
+ )
106
+ }
107
+ case (id, _) =>
108
+ CompletableFuture .failedFuture(
109
+ new IllegalArgumentException (s " Unsupported action id $id" )
110
+ )
111
+ }
112
+ }
113
+
70
114
override def withCompletionItemPriority (
71
115
priority : CompletionItemPriority
72
116
): PresentationCompiler =
@@ -348,14 +392,20 @@ case class ScalaPresentationCompiler(
348
392
override def convertToNamedArguments (
349
393
params : OffsetParams ,
350
394
argIndices : ju.List [Integer ]
395
+ ): CompletableFuture [ju.List [l.TextEdit ]] =
396
+ convertToNamedArguments(params, argIndices.asScala.toSet.map(_.toInt))
397
+
398
+ def convertToNamedArguments (
399
+ params : OffsetParams ,
400
+ argIndices : Set [Int ]
351
401
): CompletableFuture [ju.List [l.TextEdit ]] =
352
402
val empty : Either [String , List [l.TextEdit ]] = Right (List ())
353
403
(compilerAccess
354
404
.withNonInterruptableCompiler(Some (params))(empty, params.token()) { pc =>
355
405
new ConvertToNamedArgumentsProvider (
356
406
pc.compiler(),
357
407
params,
358
- argIndices.asScala.map(_.toInt).toSet
408
+ argIndices
359
409
).convertToNamedArguments
360
410
})
361
411
.thenApplyAsync {
0 commit comments