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: Don't show default argument values if type is Any #6000

Merged
merged 1 commit into from
Jan 8, 2024
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 @@ -120,7 +120,8 @@ trait ArgCompletions { this: MetalsGlobal =>
}

completions match {
case members: CompletionResult.ScopeMembers =>
case members: CompletionResult.ScopeMembers
if paramType != definitions.AnyTpe =>
members.results
.collect {
case mem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@ class Completions(
val fuzzyCache = mutable.Map.empty[CompletionValue, Int]

def compareLocalSymbols(s1: Symbol, s2: Symbol): Int =
if s1.isLocal && s2.isLocal then
if s1.isLocal && s2.isLocal && s1.sourcePos.exists && s2.sourcePos.exists
then
val firstIsAfter = s1.srcPos.isAfter(s2.srcPos)
if firstIsAfter then -1 else 1
else 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dotty.tools.dotc.core.SymDenotations.NoDenotation
import dotty.tools.dotc.core.Symbols
import dotty.tools.dotc.core.Symbols.NoSymbol
import dotty.tools.dotc.core.Symbols.Symbol
import dotty.tools.dotc.core.Symbols.defn
import dotty.tools.dotc.core.Types.AndType
import dotty.tools.dotc.core.Types.AppliedType
import dotty.tools.dotc.core.Types.MethodType
Expand Down Expand Up @@ -306,15 +307,17 @@ object NamedArgCompletions:

val completionSymbols = indexedContext.scopeSymbols
def matchingTypesInScope(paramType: Type): List[String] =
completionSymbols
.collect {
case sym
if sym.info <:< paramType && sym.isTerm && !sym.info.isErroneous && !sym.info.isNullType && !sym.info.isNothingType && !sym
.is(Flags.Method) && !sym.is(Flags.Synthetic) =>
sym.decodedName
}
.filter(name => name != "Nil" && name != "None")
.sorted
if paramType != defn.AnyType then
completionSymbols
.collect {
case sym
if sym.info <:< paramType && sym.isTerm && !sym.info.isErroneous && !sym.info.isNullType && !sym.info.isNothingType && !sym
.is(Flags.Method) && !sym.is(Flags.Synthetic) =>
sym.decodedName
}
.filter(name => name != "Nil" && name != "None")
.sorted
else Nil

def findDefaultValue(param: ParamSymbol): String =
val matchingType = matchingTypesInScope(param.info)
Expand Down
27 changes: 27 additions & 0 deletions tests/cross/src/test/scala/tests/pc/CompletionIssueSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ class CompletionIssueSuite extends BaseCompletionSuite {
)
}

check(
"comparison".tag(IgnoreForScala3CompilerPC),
"""package a
|object w {
| abstract class T(x: Int) {
| def met(x: Int): Unit = {
| println(x@@)
| }
| }}
|""".stripMargin,
"""|x: Int
|x = : Any""".stripMargin,
topLines = Some(4),
compat = Map(
"2.12" ->
"""|x: Int
|x = : Any
|xml scala
|""".stripMargin,
"2.11" ->
"""|x: Int
|x = : Any
|xml scala
|""".stripMargin
)
)

check(
"mutate".tag(IgnoreScala3),
"""package a
Expand Down