Skip to content

Commit

Permalink
Handle symbols renamed multiple times better
Browse files Browse the repository at this point in the history
  • Loading branch information
Duhemm committed Nov 28, 2018
1 parent bb6787f commit 7c4b670
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,7 @@ object Completion {
val groupedSymbols = {
val symbols = completions.toListWithNames
val nameToSymbols = symbols.groupBy(_._2.stripModuleClassSuffix.toSimpleName)
nameToSymbols.mapValues { symbols =>
symbols
.map(_._1)
.distinct // Show symbols that have been renamed multiple times only once
}.toList
nameToSymbols.mapValues(_.map(_._1)).toList
}
groupedSymbols.map { case (name, symbols) =>
val typesFirst = symbols.sortWith((s1, s2) => s1.isType && !s2.isType)
Expand Down Expand Up @@ -352,20 +348,20 @@ object Completion {
* in the REPL and the IDE.
*/
private class RenameAwareScope extends Scopes.MutableScope {
private[this] val renames: mutable.Map[Symbol, List[Name]] = mutable.Map.empty
private[this] val nameToSymbols: mutable.Map[Name, List[Symbol]] = mutable.Map.empty

/** Enter the symbol `sym` in this scope, recording a potential renaming. */
def enter[T <: Symbol](sym: T, name: Name)(implicit ctx: Context): T = {
renames += sym -> (name :: renames.getOrElse(sym, Nil))
nameToSymbols += name -> (sym :: nameToSymbols.getOrElse(name, Nil))
newScopeEntry(name, sym)
sym
}

/** Lists the symbols in this scope along with the name associated with them. */
def toListWithNames(implicit ctx: Context): List[(Symbol, Name)] = {
for {
sym <- toList
name <- renames.getOrElse(sym, List(sym.name))
(name, syms) <- nameToSymbols.toList
sym <- syms
} yield (sym, name)
}
}
Expand Down

0 comments on commit 7c4b670

Please sign in to comment.