Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ object Completion:
Some(qual)
case _ => None

private object NamedTupleSelection:
def unapply(path: List[tpd.Tree])(using Context): Option[tpd.Tree] =
path match
case (tpd.Apply(tpd.Apply(tpd.TypeApply(fun, _), List(qual)), _)) :: _
if fun.symbol.exists && fun.symbol.name == nme.apply &&
fun.symbol.owner.exists && fun.symbol.owner == defn.NamedTupleModule.moduleClass =>
Some(qual)
case _ => None


/** Inspect `path` to determine the offset where the completion result should be inserted. */
def completionOffset(untpdPath: List[untpd.Tree]): Int =
Expand All @@ -195,7 +204,7 @@ object Completion:
case _ => 0

/** Handle case when cursor position is inside extension method construct.
* The extension method construct is then desugared into methods, and consturct parameters
* The extension method construct is then desugared into methods, and construct parameters
* are no longer a part of a typed tree, but instead are prepended to method parameters.
*
* @param untpdPath The typed or untyped path to the tree that is being completed
Expand Down Expand Up @@ -242,6 +251,7 @@ object Completion:
completer.scopeCompletions.names ++ completer.selectionCompletions(qual)
case tpd.Select(qual, _) :: _ => completer.selectionCompletions(qual)
case (tree: tpd.ImportOrExport) :: _ => completer.directMemberCompletions(tree.expr)
case NamedTupleSelection(qual) => completer.selectionCompletions(qual)
case _ => completer.scopeCompletions.names

interactiv.println(i"""completion info with pos = $pos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,28 @@ class CompletionSuite extends BaseCompletionSuite:
""".stripMargin,
)

@Test def `namedTuple completions-3` =
check(
"""|import scala.NamedTuple.*
|
|val person = (name = "Jakub", city = "Wrocław")
|
|val n = person.@@name""".stripMargin,
"name: String",
filter = _ == "name: String"
)

@Test def `namedTuple completions-4` =
check(
"""|import scala.NamedTuple.*
|
|val person = (name = "Jakub", city = "Wrocław")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My legacy will live on 😆

|
|val n = person.n@@ame""".stripMargin,
"name: String",
filter = _ == "name: String"
)

@Test def `Selectable with namedTuple Fields member` =
check(
"""|import scala.NamedTuple.*
Expand Down Expand Up @@ -2285,7 +2307,7 @@ class CompletionSuite extends BaseCompletionSuite:
|""".stripMargin,
"asTerm: Term"
)

@Test def `derives-no-square-brackets` =
check(
"""
Expand Down
Loading