From af6f11e47c3b645a9781d472d726c5ba4d1b6523 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 25 Aug 2023 17:02:08 +0200 Subject: [PATCH] bugfix: Catch exception from the compiler when coursier api is on classpath We previously fixed another issue connected to this, when no completions would be available because `isPublic` would throw an exception. Now, it turns out we needed to wrap `toSymbols` methods, otherwise we would not get the duplicated symbols (which are also shadowed) Connected to https://github.com/lampepfl/dotty/issues/16175 --- .../internal/pc/CompilerSearchVisitor.scala | 11 ++++++- .../tests/pc/ShadowingCompletionSuite.scala | 29 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/cross/src/test/scala/tests/pc/ShadowingCompletionSuite.scala diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala index 3f43c5829ed..93e6dfa938a 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala @@ -23,6 +23,9 @@ class CompilerSearchVisitor( private def isAccessible(sym: Symbol): Boolean = try sym != NoSymbol && sym.isPublic && sym.isStatic catch + case err: AssertionError => + logger.log(Level.WARNING, err.getMessage()) + false case NonFatal(e) => reports.incognito.create( Report( @@ -65,8 +68,14 @@ class CompilerSearchVisitor( .stripSuffix("$") .split("\\$") - val added = toSymbols(pkg, innerPath.toList).filter(visitSymbol) + val added = + try toSymbols(pkg, innerPath.toList).filter(visitSymbol) + catch + case NonFatal(e) => + logger.log(Level.WARNING, e.getMessage(), e) + Nil added.size + end visitClassfile def visitWorkspaceSymbol( path: java.nio.file.Path, diff --git a/tests/cross/src/test/scala/tests/pc/ShadowingCompletionSuite.scala b/tests/cross/src/test/scala/tests/pc/ShadowingCompletionSuite.scala new file mode 100644 index 00000000000..7de4c9402de --- /dev/null +++ b/tests/cross/src/test/scala/tests/pc/ShadowingCompletionSuite.scala @@ -0,0 +1,29 @@ +package tests.pc + +import coursierapi.Dependency +import tests.BaseCompletionSuite + +class ShadowingCompletionSuite extends BaseCompletionSuite { + + override protected def extraDependencies( + scalaVersion: String + ): Seq[Dependency] = Seq( + Dependency.of("io.get-coursier", "interface", "1.0.18") + ) + + check( + "buffer".tag(IgnoreForScala3CompilerPC), + """package pkg + |object Main { + | val x = ListBuff@@ + |} + |""".stripMargin, + """|ListBuffer[A](elems: A*): CC[A] + |ListBuffer(i: Int): A + |ListBuffer - scala.collection.mutable + |""".stripMargin, + compat = Map( + "2" -> "ListBuffer - scala.collection.mutable" + ), + ) +}