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
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class Completions(
)
end isAbstractType

private def findSuffix(symbol: Symbol): CompletionAffix =
private def findSuffix(symbol: Symbol, adjustedPath: List[untpd.Tree]): CompletionAffix =
CompletionAffix.empty
.chain { suffix => // for [] suffix
if shouldAddSuffix && symbol.info.typeParams.nonEmpty then
Expand All @@ -217,7 +217,6 @@ class Completions(
suffix.withNewPrefix(Affix(PrefixKind.Using))
case _ => suffix
case _ => suffix

}
.chain { suffix => // for () suffix
if shouldAddSuffix && symbol.is(Flags.Method) then
Expand Down Expand Up @@ -290,7 +289,7 @@ class Completions(
val existsApply = extraMethodDenots.exists(_.symbol.name == nme.apply)

extraMethodDenots.map { methodDenot =>
val suffix = findSuffix(methodDenot.symbol)
val suffix = findSuffix(methodDenot.symbol, adjustedPath)
val affix = if methodDenot.symbol.isConstructor && existsApply then
adjustedPath match
case (select @ Select(qual, _)) :: _ =>
Expand All @@ -312,7 +311,7 @@ class Completions(

if skipOriginalDenot then extraCompletionValues
else
val suffix = findSuffix(denot.symbol)
val suffix = findSuffix(denot.symbol, adjustedPath)
val name = undoBacktick(label)
val denotCompletionValue = toCompletionValue(name, denot, suffix)
denotCompletionValue :: extraCompletionValues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,65 @@ class CompletionArgSuite extends BaseCompletionSuite:
""
)

@Test def `using` =
checkEdit(
s"""|def hello(using String): Unit = ???
|@main def main1(): Unit =
| val str = "hello"
| hello(st@@)
|""".stripMargin,
s"""|def hello(using String): Unit = ???
|@main def main1(): Unit =
| val str = "hello"
| hello(using str)
|""".stripMargin,
assertSingleItem = false)

@Test def `using2` =
checkEdit(
s"""|def hello(using String): Unit = ???
|@main def main1(): Unit =
| val str = "hello"
| hello(using st@@)
|""".stripMargin,
s"""|def hello(using String): Unit = ???
|@main def main1(): Unit =
| val str = "hello"
| hello(using str)
|""".stripMargin,
assertSingleItem = false)

@Test def `using3` =
checkEdit(
s"""|def hello(using String, Int): Unit = ???
|@main def main1(): Unit =
| val str = "hello"
| val int = 4
| hello(str, in@@)
|""".stripMargin,
s"""|def hello(using String, Int): Unit = ???
|@main def main1(): Unit =
| val str = "hello"
| val int = 4
| hello(str, int)
|""".stripMargin,
assertSingleItem = false)

@Test def `using4` =
checkEdit(
s"""|def hello(name: String)(using String): Unit = ???
|@main def main1(): Unit =
| val str = "hello"
| hello("name")(str@@)
|""".stripMargin,
s"""|def hello(name: String)(using String): Unit = ???
|@main def main1(): Unit =
| val str = "hello"
| hello("name")(using str)
|""".stripMargin,
assertSingleItem = false
)

@Test def `default-args` =
check(
s"""|object Main {
Expand Down