Skip to content

Commit 579de32

Browse files
authored
Merge pull request #4002 from dotty-staging/harden-ide-7
Harden IDE: Catch NoSuchFileException
2 parents 4bb79d0 + 86c7620 commit 579de32

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ object Interactive {
344344
if (tree.pos.contains(pos)) {
345345
// FIXME: We shouldn't need a cast. Change NavigateAST.pathTo to return a List of Tree?
346346
val path = NavigateAST.pathTo(pos, tree, skipZeroExtent = true).asInstanceOf[List[untpd.Tree]]
347-
path.dropWhile(!_.hasType).asInstanceOf[List[tpd.Tree]]
347+
path.dropWhile(!_.hasType) collect { case t: tpd.Tree @unchecked => t }
348348
}
349349
else Nil
350350

@@ -365,7 +365,7 @@ object Interactive {
365365
case nested :: encl :: rest =>
366366
import typer.Typer._
367367
val outer = contextOfPath(encl :: rest)
368-
encl match {
368+
try encl match {
369369
case tree @ PackageDef(pkg, stats) =>
370370
assert(tree.symbol.exists)
371371
if (nested `eq` pkg) outer
@@ -401,6 +401,9 @@ object Interactive {
401401
case _ =>
402402
outer
403403
}
404+
catch {
405+
case ex: CyclicReference => outer
406+
}
404407
}
405408

406409
/** The first tree in the path that is a definition. */

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,24 @@ class InteractiveDriver(settings: List[String]) extends Driver {
148148
val names = new mutable.ListBuffer[String]
149149
dirClassPaths.foreach { dirCp =>
150150
val root = dirCp.dir.toPath
151-
Files.walkFileTree(root, new SimpleFileVisitor[Path] {
152-
override def visitFile(path: Path, attrs: BasicFileAttributes) = {
153-
if (!attrs.isDirectory) {
154-
val name = path.getFileName.toString
155-
for {
156-
tastySuffix <- tastySuffixes
157-
if name.endsWith(tastySuffix)
158-
} {
159-
names += root.relativize(path).toString.replace("/", ".").stripSuffix(tastySuffix)
151+
try
152+
Files.walkFileTree(root, new SimpleFileVisitor[Path] {
153+
override def visitFile(path: Path, attrs: BasicFileAttributes) = {
154+
if (!attrs.isDirectory) {
155+
val name = path.getFileName.toString
156+
for {
157+
tastySuffix <- tastySuffixes
158+
if name.endsWith(tastySuffix)
159+
} {
160+
names += root.relativize(path).toString.replace("/", ".").stripSuffix(tastySuffix)
161+
}
160162
}
163+
FileVisitResult.CONTINUE
161164
}
162-
FileVisitResult.CONTINUE
163-
}
164-
})
165+
})
166+
catch {
167+
case _: NoSuchFileException =>
168+
}
165169
}
166170
names.toList
167171
}

0 commit comments

Comments
 (0)