diff --git a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala index 18e43f5141e7..2810fe728b9a 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/completions/CompletionValue.scala @@ -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 @@ -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 => @@ -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 */ diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionWorkspaceSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionWorkspaceSuite.scala index 706ae5062308..504df812b37f 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionWorkspaceSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionWorkspaceSuite.scala @@ -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 ) @@ -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 )