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)
29
29
)
30
30
31
31
def replaceExtensionMethods (ctx : RuleCtx ): Patch = {
32
+ val visited = collection.mutable.Set .empty[String ]
32
33
val toImport = for {
33
34
r <- ctx.index.names
34
35
in = r.symbol.normalized
35
36
out <- unimports.get(in).toList
37
+ if ! visited(out.name)
36
38
} yield {
39
+ visited += out.name
37
40
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
+ }
43
54
}
44
55
val predefUnderscore =
45
56
if (toImport.isEmpty) Patch .empty
You can’t perform that action at this time.
0 commit comments