Skip to content

Commit

Permalink
Backport "Backport pc changes from metals" to LTS (#20883)
Browse files Browse the repository at this point in the history
Backports #19617 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jul 1, 2024
2 parents a7fda9e + 0ab789c commit 629b8d5
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,29 @@ 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 @@ -6,6 +6,7 @@ import scala.meta.internal.pc.CompletionItemData
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Denotations.Denotation
import dotty.tools.dotc.core.Flags.*
import dotty.tools.dotc.core.StdNames.nme
import dotty.tools.dotc.core.Symbols.Symbol
import dotty.tools.dotc.core.Types.Type
import dotty.tools.pc.printer.ShortenedTypePrinter
Expand Down Expand Up @@ -108,7 +109,7 @@ object CompletionValue:
s"${label}${description(printer)}"
else s"$label: ${description(printer)}"

private def labelWithSuffix(printer: ShortenedTypePrinter)(using Context): String =
protected def labelWithSuffix(printer: ShortenedTypePrinter)(using Context): String =
if snippetSuffix.addLabelSnippet
then
val printedParams = symbol.info.typeParams.map(p =>
Expand Down Expand Up @@ -145,6 +146,11 @@ object CompletionValue:
override def isFromWorkspace: Boolean = true
override def completionItemDataKind: Integer = CompletionSource.WorkspaceKind.ordinal

override def labelWithDescription(printer: ShortenedTypePrinter)(using Context): String =
if symbol.is(Method) && symbol.name != nme.apply then
s"${labelWithSuffix(printer)} - ${printer.fullNameString(symbol.effectiveOwner)}"
else super.labelWithDescription(printer)

/**
* CompletionValue for old implicit classes methods via SymbolSearch
*/
Expand Down Expand Up @@ -268,6 +274,7 @@ object CompletionValue:
)(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 @@ -635,7 +635,7 @@ class CompletionInterpolatorSuite extends BaseCompletionSuite:
|""".stripMargin,
"""|class Paths
|object Main {
| s"this is an interesting {java.nio.file.Paths}"
| s"this is an interesting ${java.nio.file.Paths}"
|}
|""".stripMargin,
assertSingleItem = false,
Expand Down Expand Up @@ -710,6 +710,26 @@ class CompletionInterpolatorSuite extends BaseCompletionSuite:
filterText = "aaa.plus"
)


@Test def `extension3` =
checkEdit(
"""|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
)

@Test def `filter-by-type` =
check(
"""|package example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,29 @@ class CompletionWorkspaceSuite extends BaseCompletionSuite:
| def main: Unit = incre@@
|""".stripMargin,
"""|increment3: Int
|increment: Int
|increment2: Int
|increment - a: Int
|increment2 - a.c: Int
|""".stripMargin
)

@Test def `indent-method` =
check(
"""|package a:
| val y = 123
| given intGiven: Int = 123
| type Alpha = String
| class Foo(x: Int)
| object X:
| val x = 123
| def fooBar(x: Int) = x + 1
| package b:
| def fooBar(x: String) = x.length
|
|package c:
| def main() = foo@@
|""".stripMargin,
"""|fooBar - a(x: Int): Int
|fooBar - a.b(x: String): Int
|""".stripMargin
)

Expand Down Expand Up @@ -848,5 +869,21 @@ class CompletionWorkspaceSuite extends BaseCompletionSuite:
| }
|}
|""".stripMargin,
filter = _.contains("mmmm(x: Int)")
filter = _.contains("mmmm - demo.O")
)

@Test def `method-label` =
check(
"""|package demo
|
|object O {
| def method(i: Int): Int = i + 1
|}
|
|object Main {
| val x = meth@@
|}
|""".stripMargin,
"""|method - demo.O(i: Int): Int
|""".stripMargin
)

0 comments on commit 629b8d5

Please sign in to comment.