Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Extension method completion with name conflict #5913

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ class CompletionProvider(
mkItem(
"{" + sym.fullNameBackticked + completionTextSuffix + "}"
)
case _ if v.isExtensionMethod =>
mkItem(
ident.backticked(backtickSoftKeyword) + completionTextSuffix
)
case _ =>
mkItem(
sym.fullNameBackticked(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object CompletionValue:
def symbol: Symbol
def isFromWorkspace: Boolean = false
def completionItemDataKind = CompletionItemData.None
def isExtensionMethod: Boolean = false

override def completionData(
buildTargetIdentifier: String
Expand Down Expand Up @@ -125,6 +126,7 @@ object CompletionValue:
) extends Symbolic:
override def completionItemKind(using Context): CompletionItemKind =
CompletionItemKind.Method
override def isExtensionMethod: Boolean = true
override def description(printer: MetalsPrinter)(using Context): String =
s"${printer.completionSymbol(symbol)} (extension)"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,36 @@ class CompletionExtensionMethodSuite extends BaseCompletionSuite {
|""".stripMargin
)

checkEdit(
"name-conflict",
"""|package example
|
|import example.enrichments.*
|
|object enrichments:
| extension (num: Int)
| def plus(other: Int): Int = num + other
|
|def main = {
| val plus = 100.plus(19)
| val y = 19.pl@@
|}
|""".stripMargin,
"""|package example
|
|import example.enrichments.*
|
|object enrichments:
| extension (num: Int)
| def plus(other: Int): Int = num + other
|
|def main = {
| val plus = 100.plus(19)
| val y = 19.plus($0)
|}
|""".stripMargin
)

// NOTE: In 3.1.3, package object name includes the whole path to file
// eg. in 3.2.2 we get `A$package`, but in 3.1.3 `/some/path/to/file/A$package`
check(
Expand Down
25 changes: 25 additions & 0 deletions tests/cross/src/test/scala/tests/pc/CompletionWorkspaceSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -988,4 +988,29 @@ class CompletionWorkspaceSuite extends BaseCompletionSuite {
|MyType - demo.other""".stripMargin
)

checkEdit(
"method-name-conflict".tag(IgnoreScala2),
"""|package demo
|
|object O {
| def mmmm(x: Int) = x + 3
| class Test {
| val mmmm = "abc"
| val foo = mmmm@@
| }
|}
|""".stripMargin,
"""|package demo
|
|object O {
| def mmmm(x: Int) = x + 3
| class Test {
| val mmmm = "abc"
| val foo = demo.O.mmmm($0)
| }
|}
|""".stripMargin,
filter = _.contains("mmmm(x: Int)")
)

}