Skip to content

Commit c94cb5c

Browse files
Backport "Draft: additional completions for using clause" to 3.7.4 (#24027)
Backports #23647 to the 3.7.4. PR submitted by the release tooling. [skip ci]
2 parents fbfbb4b + bb7c471 commit c94cb5c

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class Completions(
201201
)
202202
end isAbstractType
203203

204-
private def findSuffix(symbol: Symbol): CompletionAffix =
204+
private def findSuffix(symbol: Symbol, adjustedPath: List[untpd.Tree]): CompletionAffix =
205205
CompletionAffix.empty
206206
.chain { suffix => // for [] suffix
207207
if shouldAddSuffix && symbol.info.typeParams.nonEmpty then
@@ -217,7 +217,6 @@ class Completions(
217217
suffix.withNewPrefix(Affix(PrefixKind.Using))
218218
case _ => suffix
219219
case _ => suffix
220-
221220
}
222221
.chain { suffix => // for () suffix
223222
if shouldAddSuffix && symbol.is(Flags.Method) then
@@ -290,7 +289,7 @@ class Completions(
290289
val existsApply = extraMethodDenots.exists(_.symbol.name == nme.apply)
291290

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

313312
if skipOriginalDenot then extraCompletionValues
314313
else
315-
val suffix = findSuffix(denot.symbol)
314+
val suffix = findSuffix(denot.symbol, adjustedPath)
316315
val name = undoBacktick(label)
317316
val denotCompletionValue = toCompletionValue(name, denot, suffix)
318317
denotCompletionValue :: extraCompletionValues

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,65 @@ class CompletionArgSuite extends BaseCompletionSuite:
238238
""
239239
)
240240

241+
@Test def `using` =
242+
checkEdit(
243+
s"""|def hello(using String): Unit = ???
244+
|@main def main1(): Unit =
245+
| val str = "hello"
246+
| hello(st@@)
247+
|""".stripMargin,
248+
s"""|def hello(using String): Unit = ???
249+
|@main def main1(): Unit =
250+
| val str = "hello"
251+
| hello(using str)
252+
|""".stripMargin,
253+
assertSingleItem = false)
254+
255+
@Test def `using2` =
256+
checkEdit(
257+
s"""|def hello(using String): Unit = ???
258+
|@main def main1(): Unit =
259+
| val str = "hello"
260+
| hello(using st@@)
261+
|""".stripMargin,
262+
s"""|def hello(using String): Unit = ???
263+
|@main def main1(): Unit =
264+
| val str = "hello"
265+
| hello(using str)
266+
|""".stripMargin,
267+
assertSingleItem = false)
268+
269+
@Test def `using3` =
270+
checkEdit(
271+
s"""|def hello(using String, Int): Unit = ???
272+
|@main def main1(): Unit =
273+
| val str = "hello"
274+
| val int = 4
275+
| hello(str, in@@)
276+
|""".stripMargin,
277+
s"""|def hello(using String, Int): Unit = ???
278+
|@main def main1(): Unit =
279+
| val str = "hello"
280+
| val int = 4
281+
| hello(str, int)
282+
|""".stripMargin,
283+
assertSingleItem = false)
284+
285+
@Test def `using4` =
286+
checkEdit(
287+
s"""|def hello(name: String)(using String): Unit = ???
288+
|@main def main1(): Unit =
289+
| val str = "hello"
290+
| hello("name")(str@@)
291+
|""".stripMargin,
292+
s"""|def hello(name: String)(using String): Unit = ???
293+
|@main def main1(): Unit =
294+
| val str = "hello"
295+
| hello("name")(using str)
296+
|""".stripMargin,
297+
assertSingleItem = false
298+
)
299+
241300
@Test def `default-args` =
242301
check(
243302
s"""|object Main {

0 commit comments

Comments
 (0)