Skip to content

Commit

Permalink
fix: cover additional cases for singleton types (#6541)
Browse files Browse the repository at this point in the history
* fix: cover additional cases for singleton types

* deprecate Scala "3.1.3"
  • Loading branch information
kasiaMarek authored Jun 27, 2024
1 parent 821cbf2 commit 8bebd63
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ object MtagsResolver {
"3.3.2-RC1" -> "1.2.2",
"3.3.2-RC2" -> "1.2.2",
"3.3.2-RC3" -> "1.2.2",
"3.1.3" -> "1.3.2",
)

class Default extends MtagsResolver {
Expand Down
4 changes: 0 additions & 4 deletions mtags/src/main/scala-3.0/scala/meta/internal/pc/Compat.scala

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions mtags/src/main/scala-3.1/scala/meta/internal/pc/Compat.scala

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ import dotty.tools.dotc.core.Constants.Constant
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Flags
import dotty.tools.dotc.core.StdNames
import dotty.tools.dotc.core.Symbols
import dotty.tools.dotc.core.Types.AndType
import dotty.tools.dotc.core.Types.AppliedType
import dotty.tools.dotc.core.Types.ConstantType
import dotty.tools.dotc.core.Types.OrType
import dotty.tools.dotc.core.Types.TermRef
import dotty.tools.dotc.core.Types.Type
import dotty.tools.dotc.core.Types.TypeRef
import dotty.tools.dotc.util.Spans.Span

object SingletonCompletions:
def contribute(
path: List[Tree],
tpe: Type,
tpe0: Type,
completionPos: CompletionPos
)(using ctx: Context): List[CompletionValue] =
for {
Expand All @@ -31,6 +33,11 @@ object SingletonCompletions:
case (l @ Literal(const)) :: _ => List(const.show -> l.span)
case _ => Nil
query = name.replace(Cursor.value, "")
tpe = tpe0 match
// for Tuple 2 we want to suggest first arg completion
case AppliedType(t: TypeRef, args) if t.classSymbol == Symbols.defn.Tuple2 && args.nonEmpty =>
args.head
case t => t
singletonValues = collectSingletons(tpe).map(_.show)
range = completionPos.cursorPos.withStart(span.start).withEnd(span.start + query.length).toLsp
value <- singletonValues.collect {
Expand All @@ -57,15 +64,25 @@ object InterCompletionType:

def inferType(path: List[Tree], span: Span)(using Context): Option[Type] =
path match
// List(@@)
case SeqLiteral(_, tpe) :: _ if !tpe.tpe.isErroneous => Some(tpe.tpe)
case Block(_, expr) :: rest if expr.span.contains(span) =>
inferType(rest, span)
case If(cond, _, _) :: rest if !cond.span.contains(span) =>
inferType(rest, span)
case (defn: ValOrDefDef) :: rest if !defn.tpt.tpe.isErroneous => Some(defn.tpt.tpe)
case CaseDef(_, _, body) :: Match(_, cases) :: rest if body.span.contains(span) && cases.exists(_.span.contains(span)) =>
inferType(rest, span)
case NamedArg(_, arg) :: rest if arg.span.contains(span) => inferType(rest, span)
// x match
// case @@
case CaseDef(pat, _, _) :: Match(sel, cases) :: rest if pat.span.contains(span) && cases.exists(_.span.contains(span)) && !sel.tpe.isErroneous =>
sel.tpe match
case tpe: TermRef => Some(tpe.symbol.info).filterNot(_.isErroneous)
case tpe => Some(tpe)
// List(@@)
case SeqLiteral(_, tpe) :: _ if !tpe.tpe.isErroneous =>
Some(tpe.tpe)
// val _: T = @@
// def _: T = @@
case (defn: ValOrDefDef) :: rest if !defn.tpt.tpe.isErroneous => Some(defn.tpt.tpe)
// f(@@)
case (app: Apply) :: rest =>
val param =
Expand Down
2 changes: 1 addition & 1 deletion project/V.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ object V {

// whenever version is removed please add it to MtagsResolver under last supported Metals version
def deprecatedScala3Versions =
Seq("3.3.2", "3.2.2", "3.1.3")
Seq("3.3.2", "3.2.2")

// NOTE if you had a new Scala Version make sure it's contained in quickPublishScalaVersions
def scala3Versions = nonDeprecatedScala3Versions ++ deprecatedScala3Versions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class SingletonCompletionsSuite extends BaseCompletionSuite {
)

check(
"match-case",
"match-case-result",
"""|val h: "foo" =
| 1 match
| case _ => "@@"
Expand All @@ -254,6 +254,43 @@ class SingletonCompletionsSuite extends BaseCompletionSuite {
|""".stripMargin
)

check(
"match-case",
"""|def h(foo: "foo") =
| foo match
| case "@@" =>
|""".stripMargin,
"""|"foo": "foo"
|""".stripMargin
)

check(
"match-case2",
"""|def h =
| ("foo" : "foo") match
| case "@@" =>
|""".stripMargin,
"""|"foo": "foo"
|""".stripMargin
)

check(
"named-args",
"""|def h(foo: "foo") = ???
|def k = h(foo = "@@")
|""".stripMargin,
"""|"foo": "foo"
|""".stripMargin
)

check(
"map-type",
"""|def m = Map["foo", Int]("@@")
|""".stripMargin,
"""|"foo": "foo"
|""".stripMargin
)

check(
"dont-show-on-select",
"""|val f: "foo" = List(1,2,3).@@
Expand Down

0 comments on commit 8bebd63

Please sign in to comment.