File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -29,17 +29,28 @@ case class Collectionstrawman_v0(index: SemanticdbIndex)
2929 )
3030
3131 def replaceExtensionMethods (ctx : RuleCtx ): Patch = {
32+ val visited = collection.mutable.Set .empty[String ]
3233 val toImport = for {
3334 r <- ctx.index.names
3435 in = r.symbol.normalized
3536 out <- unimports.get(in).toList
37+ if ! visited(out.name)
3638 } yield {
39+ visited += out.name
3740 val name = in.name
38- val names = name :: additionalUnimports.get(name)
39- .fold(List .empty[String ])(_ :: Nil )
40- ctx.addGlobalImport(out) +
41- ctx.addGlobalImport(
42- Importer (q " scala.Predef " , names.map(n => Importee .Unimport (Name (n)))))
41+ def visiting (s : String ): List [String ] =
42+ if (! visited(s)) {
43+ visited += s
44+ s :: Nil
45+ } else Nil
46+ val names = visiting(name) ::: additionalUnimports.get(name)
47+ .fold(List .empty[String ])(visiting)
48+ if (names.isEmpty) ctx.addGlobalImport(out)
49+ else {
50+ ctx.addGlobalImport(out) +
51+ ctx.addGlobalImport(
52+ Importer (q " scala.Predef " , names.map(n => Importee .Unimport (Name (n)))))
53+ }
4354 }
4455 val predefUnderscore =
4556 if (toImport.isEmpty) Patch .empty
You can’t perform that action at this time.
0 commit comments