diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/OverrideCompletions.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/OverrideCompletions.scala index bdbb17186ef..59ff85adbb5 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/OverrideCompletions.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/OverrideCompletions.scala @@ -131,15 +131,25 @@ object OverrideCompletions: ): ju.List[l.TextEdit] = object FindTypeDef: def unapply(path: List[Tree])(using Context): Option[TypeDef] = path match + // class <> extends ... {} case (td: TypeDef) :: _ => Some(td) // new Iterable[Int] {} case (_: Ident) :: _ :: (_: Template) :: (td: TypeDef) :: _ => Some(td) - // new Context {} + // given Foo with {} case (_: Ident) :: (_: Template) :: (td: TypeDef) :: _ => Some(td) + // <> Foo {} + case (_: Template) :: (td: TypeDef) :: _ => + Some(td) + // abstract class Mutable { ... } + // new <> { } case (_: Ident) :: (_: New) :: (_: Select) :: (_: Apply) :: (_: Template) :: (td: TypeDef) :: _ => Some(td) + // trait Base[T]: + // extension (x: T) + // ... + // class <>[T] extends Base[Int] case (dd: DefDef) :: (_: Template) :: (td: TypeDef) :: _ if dd.symbol.isConstructor => Some(td) @@ -179,6 +189,7 @@ object OverrideCompletions: config, ) path match + // given <> case (_: Ident) :: (dd: DefDef) :: _ => implementAll(dd).asJava case FindTypeDef(td) => diff --git a/tests/slow/src/test/scala/tests/feature/Scala3CodeActionLspSuite.scala b/tests/slow/src/test/scala/tests/feature/Scala3CodeActionLspSuite.scala index 09ddbf51f2b..95e7298c93b 100644 --- a/tests/slow/src/test/scala/tests/feature/Scala3CodeActionLspSuite.scala +++ b/tests/slow/src/test/scala/tests/feature/Scala3CodeActionLspSuite.scala @@ -405,6 +405,38 @@ class Scala3CodeActionLspSuite expectNoDiagnostics = false, ) + check( + "implement-anonymous-class", + """|package anonymous + | + |trait Foo: + | def foo(x: Int): Int + | def bar(x: String): String + | + |def main = + | <> Foo {} + | + |""".stripMargin, + s"""|${ImplementAbstractMembers.title} + |""".stripMargin, + """|package anonymous + | + |trait Foo: + | def foo(x: Int): Int + | def bar(x: String): String + | + |def main = + | new Foo { + | + | override def foo(x: Int): Int = ??? + | + | override def bar(x: String): String = ??? + | + | } + |""".stripMargin, + expectNoDiagnostics = false, + ) + check( "wrong-type", """|package a