Skip to content

Commit 0f56dba

Browse files
committed
improvement: Better labels for workspace methods completions
1 parent 4cab332 commit 0f56dba

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import scala.meta.internal.pc.CompletionItemData
66
import dotty.tools.dotc.core.Contexts.Context
77
import dotty.tools.dotc.core.Denotations.Denotation
88
import dotty.tools.dotc.core.Flags.*
9+
import dotty.tools.dotc.core.StdNames.nme
910
import dotty.tools.dotc.core.Symbols.Symbol
1011
import dotty.tools.dotc.core.Types.Type
1112
import dotty.tools.pc.printer.ShortenedTypePrinter
@@ -108,7 +109,7 @@ object CompletionValue:
108109
s"${label}${description(printer)}"
109110
else s"$label: ${description(printer)}"
110111

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

149+
override def labelWithDescription(printer: ShortenedTypePrinter)(using Context): String =
150+
if symbol.is(Method) && symbol.name != nme.apply then
151+
s"${labelWithSuffix(printer)} - ${printer.fullNameString(symbol.effectiveOwner)}"
152+
else super.labelWithDescription(printer)
153+
148154
/**
149155
* CompletionValue for old implicit classes methods via SymbolSearch
150156
*/

Diff for: presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionWorkspaceSuite.scala

+40-3
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,29 @@ class CompletionWorkspaceSuite extends BaseCompletionSuite:
768768
| def main: Unit = incre@@
769769
|""".stripMargin,
770770
"""|increment3: Int
771-
|increment: Int
772-
|increment2: Int
771+
|increment - a: Int
772+
|increment2 - a.c: Int
773+
|""".stripMargin
774+
)
775+
776+
@Test def `indent-method` =
777+
check(
778+
"""|package a:
779+
| val y = 123
780+
| given intGiven: Int = 123
781+
| type Alpha = String
782+
| class Foo(x: Int)
783+
| object X:
784+
| val x = 123
785+
| def fooBar(x: Int) = x + 1
786+
| package b:
787+
| def fooBar(x: String) = x.length
788+
|
789+
|package c:
790+
| def main() = foo@@
791+
|""".stripMargin,
792+
"""|fooBar - a(x: Int): Int
793+
|fooBar - a.b(x: String): Int
773794
|""".stripMargin
774795
)
775796

@@ -848,5 +869,21 @@ class CompletionWorkspaceSuite extends BaseCompletionSuite:
848869
| }
849870
|}
850871
|""".stripMargin,
851-
filter = _.contains("mmmm(x: Int)")
872+
filter = _.contains("mmmm - demo.O")
873+
)
874+
875+
@Test def `method-label` =
876+
check(
877+
"""|package demo
878+
|
879+
|object O {
880+
| def method(i: Int): Int = i + 1
881+
|}
882+
|
883+
|object Main {
884+
| val x = meth@@
885+
|}
886+
|""".stripMargin,
887+
"""|method - demo.O(i: Int): Int
888+
|""".stripMargin
852889
)

0 commit comments

Comments
 (0)