-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
There is some discrepancy between how code completion works with Metals for scala 2 and for scala 3 if a suggested name refers to multiple definitions. Consider the following examples
object Test1 {
object Foo {
def xxxx(i: Int): Int = 123
def xxxx(s: String): String = ""
}
val x = Foo.xx
}
object Test2 {
object Foo {
def xxxx(i: Int): Int = 123
def xxxx(s: String): String = ""
}
import Foo.xx
}
object Test3 {
object Foo {
type xxxx = Int
def xxxx(i: Int): Int = 123
}
import Foo.xx
}
object Test4 {
object Foo {
type xxxx = Int
def xxxx(i: Int): Int = 123
def xxxx(s: String): String = ""
}
import Foo.xx
}
The completions suggested for Foo.xx
are show in the table
test case | scala 2 | scala 3 |
---|---|---|
Test1 | xxxx(i: Int): Int | xxxx(s: String): String |
xxxx(s: String): String | ||
Test2 | xxxx(i: Int): Int | xxxx(s: String): String |
xxxx(s: String): String | ||
Test3 | xxxx(i: Int): Int | type and method xxx |
Test4 | xxxx(i: Int): Int | type and method xxx |
xxxx(s: String): String |
Beside some apparent bugs (completely ignoring some definitions) that will need to be reported separately, we can see here 2 strategies of dealing with overloaded symbols: either displaying them as separate entries or merging them into one. The former approach gives users more information about the meanings of a name in a given context (which is especially useful when dealing with overloaded methods), the latter is more concise (having to go through multiple entries with the same name might get frustrating for TAB completion in REPL).
Was this discrepancy introduced on purpose or would we rather like to preserve consistency between the two versions of the language?
Personally I would go for taking scala 2's behaviour, which seems to work well for IDEs with LSP, and for the REPL this could be later improved by doing what Ammonite does: merging the identically named entries into one for TAB completion but then showing full signatures with alternatives on pressing TAB again.