Skip to content

Commit

Permalink
bugfix: Extension completions in interpolated strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jkciesluk committed Feb 1, 2024
1 parent 0ea507c commit ef51880
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,31 @@ class CompletionProvider(
r match
case IndexedContext.Result.InScope =>
mkItem(
ident.backticked(backtickSoftKeyword) + completionTextSuffix
v.insertText.getOrElse(
ident.backticked(
backtickSoftKeyword
) + completionTextSuffix
),
range = v.range,
)
case _ if isInStringInterpolation =>
mkItem(
"{" + sym.fullNameBackticked + completionTextSuffix + "}"
"{" + sym.fullNameBackticked + completionTextSuffix + "}",
range = v.range,
)
case _ if v.isExtensionMethod =>
mkItem(
ident.backticked(backtickSoftKeyword) + completionTextSuffix
ident.backticked(
backtickSoftKeyword
) + completionTextSuffix,
range = v.range,
)
case _ =>
mkItem(
sym.fullNameBackticked(
backtickSoftKeyword
) + completionTextSuffix
) + completionTextSuffix,
range = v.range,
)
end match
end match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ object CompletionValue:
override def description(printer: MetalsPrinter)(using Context): String =
if isExtension then s"${printer.completionSymbol(symbol)} (extension)"
else super.description(printer)
override def isExtensionMethod: Boolean = isExtension
end Interpolator

case class MatchCompletion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ class CompletionInterpolatorSuite extends BaseCompletionSuite {
)

checkEdit(
"auto-imports-prefix",
"auto-imports-prefix".tag(IgnoreForScala3CompilerPC),
"""|
|class Paths
|object Main {
Expand All @@ -682,7 +682,7 @@ class CompletionInterpolatorSuite extends BaseCompletionSuite {
"3" ->
"""|class Paths
|object Main {
| s"this is an interesting {java.nio.file.Paths}"
| s"this is an interesting ${java.nio.file.Paths}"
|}
|""".stripMargin
)
Expand Down Expand Up @@ -770,6 +770,29 @@ class CompletionInterpolatorSuite extends BaseCompletionSuite {
filterText = "aaa.plus"
)

checkEdit(
"extension3".tag(
IgnoreScala2
.and(IgnoreScalaVersion.for3LessThan("3.2.2"))
.and(IgnoreForScala3CompilerPC)
),
"""|trait Cursor
|
|extension (c: Cursor) def spelling: String = "hello"
|object Main {
| val c = new Cursor {}
| val x = s"$c.spelli@@"
|}
|""".stripMargin,
"""|trait Cursor
|
|extension (c: Cursor) def spelling: String = "hello"
|object Main {
| val c = new Cursor {}
| val x = s"${c.spelling$0}"
|}""".stripMargin
)

check(
"filter-by-type".tag(IgnoreScala2),
"""|package example
Expand Down

0 comments on commit ef51880

Please sign in to comment.