Skip to content

Commit 4cab332

Browse files
committed
bugfix: Extension completions in interpolated strings
1 parent f14d0a2 commit 4cab332

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,29 @@ class CompletionProvider(
243243
r match
244244
case IndexedContext.Result.InScope =>
245245
mkItem(
246-
ident.backticked(backtickSoftKeyword) + completionTextSuffix
246+
v.insertText.getOrElse(
247+
ident.backticked(
248+
backtickSoftKeyword
249+
) + completionTextSuffix
250+
),
251+
range = v.range,
247252
)
248253
case _ if isInStringInterpolation =>
249254
mkItem(
250-
"{" + sym.fullNameBackticked + completionTextSuffix + "}"
255+
"{" + sym.fullNameBackticked + completionTextSuffix + "}",
256+
range = v.range
251257
)
252258
case _ if v.isExtensionMethod =>
253259
mkItem(
254-
ident.backticked(backtickSoftKeyword) + completionTextSuffix
260+
ident.backticked(backtickSoftKeyword) + completionTextSuffix,
261+
range = v.range
255262
)
256263
case _ =>
257264
mkItem(
258265
sym.fullNameBackticked(
259266
backtickSoftKeyword
260-
) + completionTextSuffix
267+
) + completionTextSuffix,
268+
range = v.range
261269
)
262270
end match
263271
end match

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ object CompletionValue:
268268
)(using Context): String =
269269
if isExtension then s"${printer.completionSymbol(symbol)} (extension)"
270270
else super.description(printer)
271+
override def isExtensionMethod: Boolean = isExtension
271272
end Interpolator
272273

273274
case class MatchCompletion(

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ class CompletionInterpolatorSuite extends BaseCompletionSuite:
635635
|""".stripMargin,
636636
"""|class Paths
637637
|object Main {
638-
| s"this is an interesting {java.nio.file.Paths}"
638+
| s"this is an interesting ${java.nio.file.Paths}"
639639
|}
640640
|""".stripMargin,
641641
assertSingleItem = false,
@@ -710,6 +710,26 @@ class CompletionInterpolatorSuite extends BaseCompletionSuite:
710710
filterText = "aaa.plus"
711711
)
712712

713+
714+
@Test def `extension3` =
715+
checkEdit(
716+
"""|trait Cursor
717+
|
718+
|extension (c: Cursor) def spelling: String = "hello"
719+
|object Main {
720+
| val c = new Cursor {}
721+
| val x = s"$c.spelli@@"
722+
|}
723+
|""".stripMargin,
724+
"""|trait Cursor
725+
|
726+
|extension (c: Cursor) def spelling: String = "hello"
727+
|object Main {
728+
| val c = new Cursor {}
729+
| val x = s"${c.spelling$0}"
730+
|}""".stripMargin
731+
)
732+
713733
@Test def `filter-by-type` =
714734
check(
715735
"""|package example

0 commit comments

Comments
 (0)