File tree 3 files changed +44
-7
lines changed
test/dotty/tools/dotc/reporting
3 files changed +44
-7
lines changed Original file line number Diff line number Diff line change @@ -424,12 +424,17 @@ trait NoDisambiguation extends Message:
424
424
withoutDisambiguation()
425
425
426
426
/** The fallback `Message` containing no explanation and having no `kind` */
427
- final class NoExplanation (msgFn : Context ?=> String )(using Context ) extends Message (ErrorMessageID .NoExplanationID ) {
427
+ final class NoExplanation (msgFn : Context ?=> String , actions : List [ CodeAction ] = List .empty )(using Context ) extends Message (ErrorMessageID .NoExplanationID ) {
428
428
def msg (using Context ): String = msgFn
429
429
def explain (using Context ): String = " "
430
430
val kind : MessageKind = MessageKind .NoKind
431
431
432
+ override def actions (using Context ): List [CodeAction ] = actions
433
+
432
434
override def toString (): String = msg
435
+
436
+ def withActions (actions : List [CodeAction ]): NoExplanation =
437
+ new NoExplanation (msgFn, actions)
433
438
}
434
439
435
440
/** The extractor for `NoExplanation` can be used to check whether any error
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ import NameKinds.ContextBoundParamName
21
21
import rewrites .Rewrites .patch
22
22
import util .Spans .Span
23
23
import rewrites .Rewrites
24
+ import dotty .tools .dotc .rewrites .Rewrites .ActionPatch
25
+ import dotty .tools .dotc .util .SourcePosition
24
26
25
27
/** A utility trait containing source-dependent deprecation messages
26
28
* and migrations.
@@ -139,14 +141,31 @@ trait Migrations:
139
141
val rewriteMsg =
140
142
if hasParentheses then
141
143
Message .rewriteNotice(" This code" , mversion.patchFrom)
142
- else
143
- " "
144
- report.errorOrMigrationWarning(
144
+ else " "
145
+ val message =
145
146
em """ Implicit parameters should be provided with a `using` clause. $rewriteMsg
146
- |To disable the warning, please use the following option:
147
+ |To disable the warning, please use the following option:
147
148
| "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
148
- | """ ,
149
- pt.args.head.srcPos, mversion)
149
+ | """
150
+ val withActions = message.withActions(
151
+ List (
152
+ CodeAction (
153
+ title = " Add `using` clause" ,
154
+ description = None ,
155
+ patches = List (
156
+ ActionPatch (
157
+ pt.args.head.startPos.sourcePos,
158
+ " using "
159
+ )
160
+ )
161
+ )
162
+ )
163
+ )
164
+ report.errorOrMigrationWarning(
165
+ withActions,
166
+ pt.args.head.srcPos,
167
+ mversion
168
+ )
150
169
if hasParentheses && mversion.needsPatch then
151
170
patch(Span (pt.args.head.span.start), " using " )
152
171
end implicitParams
Original file line number Diff line number Diff line change @@ -54,6 +54,19 @@ class CodeActionTest extends DottyTest:
54
54
|""" .stripMargin
55
55
)
56
56
57
+ @ Test def addUsingClause =
58
+ checkCodeAction(
59
+ """ |object Test:
60
+ | def foo(implicit a: Int) = a
61
+ | foo(123)
62
+ |""" .stripMargin,
63
+ " Add `using` clause" ,
64
+ """ |object Test:
65
+ | def foo(implicit a: Int) = a
66
+ | foo(using 123)
67
+ |""" .stripMargin
68
+ )
69
+
57
70
@ Test def insertMissingCases =
58
71
checkCodeAction(
59
72
code =
You can’t perform that action at this time.
0 commit comments