@@ -29,6 +29,11 @@ import transform.SymUtils._
2929import scala .util .matching .Regex
3030import java .util .regex .Matcher .quoteReplacement
3131import cc .CaptureSet .IdentityCaptRefMap
32+ import dotty .tools .dotc .rewrites .Rewrites .ActionPatch
33+ import dotty .tools .dotc .util .Spans .Span
34+ import dotty .tools .dotc .util .SourcePosition
35+ import scala .jdk .CollectionConverters .*
36+ import dotty .tools .dotc .util .SourceFile
3237
3338/** Messages
3439 * ========
@@ -493,7 +498,7 @@ extends SyntaxMsg(ObjectMayNotHaveSelfTypeID) {
493498 }
494499}
495500
496- class RepeatedModifier (modifier : String )(implicit ctx: Context )
501+ class RepeatedModifier (modifier : String , source : SourceFile , span : Span )(implicit ctx: Context )
497502extends SyntaxMsg (RepeatedModifierID ) {
498503 def msg (using Context ) = i """ Repeated modifier $modifier"""
499504
@@ -512,6 +517,17 @@ extends SyntaxMsg(RepeatedModifierID) {
512517 |
513518 | """
514519 }
520+
521+ override def actions (using Context ) =
522+ import scala .language .unsafeNulls
523+ List (
524+ CodeAction (title = s """ Remove repeated modifier: " $modifier" """ ,
525+ description = None ,
526+ patches = List (
527+ ActionPatch (SourcePosition (source, span), " " )
528+ )
529+ )
530+ )
515531}
516532
517533class InterpolatedStringError ()(implicit ctx: Context )
@@ -1846,15 +1862,28 @@ class FailureToEliminateExistential(tp: Type, tp1: Type, tp2: Type, boundSyms: L
18461862 |are only approximated in a best-effort way. """
18471863}
18481864
1849- class OnlyFunctionsCanBeFollowedByUnderscore (tp : Type )(using Context )
1865+ class OnlyFunctionsCanBeFollowedByUnderscore (tp : Type , tree : untpd. PostfixOp )(using Context )
18501866 extends SyntaxMsg (OnlyFunctionsCanBeFollowedByUnderscoreID ) {
18511867 def msg (using Context ) = i " Only function types can be followed by ${hl(" _" )} but the current expression has type $tp"
18521868 def explain (using Context ) =
18531869 i """ The syntax ${hl(" x _" )} is no longer supported if ${hl(" x" )} is not a function.
18541870 |To convert to a function value, you need to explicitly write ${hl(" () => x" )}"""
1871+
1872+ override def actions (using Context ) =
1873+ import scala .language .unsafeNulls
1874+ val untpd .PostfixOp (qual, Ident (nme.WILDCARD )) = tree : @ unchecked
1875+ List (
1876+ CodeAction (title = " Rewrite to function value" ,
1877+ description = None ,
1878+ patches = List (
1879+ ActionPatch (SourcePosition (tree.source, Span (tree.span.start)), " (() => " ),
1880+ ActionPatch (SourcePosition (tree.source, Span (qual.span.end, tree.span.end)), " )" )
1881+ )
1882+ )
1883+ )
18551884}
18561885
1857- class MissingEmptyArgumentList (method : String )(using Context )
1886+ class MissingEmptyArgumentList (method : String , tree : tpd. Tree )(using Context )
18581887 extends SyntaxMsg (MissingEmptyArgumentListID ) {
18591888 def msg (using Context ) = i " $method must be called with ${hl(" ()" )} argument "
18601889 def explain (using Context ) = {
@@ -1869,6 +1898,17 @@ class MissingEmptyArgumentList(method: String)(using Context)
18691898 |In Dotty, this idiom is an error. The application syntax has to follow exactly the parameter syntax.
18701899 |Excluded from this rule are methods that are defined in Java or that override methods defined in Java. """
18711900 }
1901+
1902+ override def actions (using Context ) =
1903+ import scala .language .unsafeNulls
1904+ List (
1905+ CodeAction (title = " Insert ()" ,
1906+ description = None ,
1907+ patches = List (
1908+ ActionPatch (SourcePosition (tree.source, tree.span.endPos), " ()" ),
1909+ )
1910+ )
1911+ )
18721912}
18731913
18741914class DuplicateNamedTypeParameter (name : Name )(using Context )
0 commit comments