File tree 3 files changed +27
-6
lines changed
compiler/src/dotty/tools/dotc/interactive
language-server/src/dotty/tools/languageserver
3 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -475,7 +475,7 @@ object Interactive {
475
475
Include .definitions | Include .overriding | Include .overridden)
476
476
else sym.topLevelClass match {
477
477
case cls : ClassSymbol =>
478
- val trees = Option (cls.sourceFile).map (InteractiveDriver .toUri ) match {
478
+ val trees = Option (cls.sourceFile).flatMap (InteractiveDriver .toUriOption ) match {
479
479
case Some (uri) if driver.openedTrees.contains(uri) =>
480
480
driver.openedTrees(uri)
481
481
case _ => // Symbol comes from the classpath
Original file line number Diff line number Diff line change @@ -265,7 +265,24 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
265
265
}
266
266
267
267
object InteractiveDriver {
268
- def toUri (file : AbstractFile ): URI = Paths .get(file.path).toUri
269
- def toUri (source : SourceFile ): URI = toUri(source.file)
268
+ def toUriOption (file : AbstractFile ): Option [URI ] =
269
+ if (! file.exists)
270
+ None
271
+ else
272
+ try {
273
+ // We don't use file.file here since it'll be null
274
+ // for the VirtualFiles created by InteractiveDriver#toSource
275
+ // TODO: To avoid these round trip conversions, we could add an
276
+ // AbstractFile#toUri method and implement it by returning a constant
277
+ // passed as a parameter to a constructor of VirtualFile
278
+ Some (Paths .get(file.path).toUri)
279
+ } catch {
280
+ case e : InvalidPathException =>
281
+ None
282
+ }
283
+ def toUriOption (source : SourceFile ): Option [URI ] =
284
+ if (! source.exists)
285
+ None
286
+ else
287
+ toUriOption(source.file)
270
288
}
271
-
Original file line number Diff line number Diff line change @@ -315,7 +315,8 @@ class DottyLanguageServer extends LanguageServer
315
315
Include .references | Include .definitions | Include .linkedClass | Include .overriding
316
316
val refs = Interactive .findTreesMatching(trees, includes, sym)
317
317
318
- val changes = refs.groupBy(ref => toUri(ref.source).toString)
318
+ val changes = refs.groupBy(ref => toUriOption(ref.source))
319
+ .flatMap((uriOpt, ref) => uriOpt.map(uri => (uri.toString, ref)))
319
320
.mapValues(refs =>
320
321
refs.flatMap(ref =>
321
322
range(ref.namePos, positionMapperFor(ref.source)).map(nameRange => new TextEdit (nameRange, newName))).asJava)
@@ -433,7 +434,10 @@ object DottyLanguageServer {
433
434
434
435
/** Convert a SourcePosition to an lsp4.Location */
435
436
def location (p : SourcePosition , positionMapper : Option [SourcePosition => SourcePosition ] = None ): Option [lsp4j.Location ] =
436
- range(p, positionMapper).map(r => new lsp4j.Location (toUri(p.source).toString, r))
437
+ for {
438
+ uri <- toUriOption(p.source)
439
+ r <- range(p, positionMapper)
440
+ } yield new lsp4j.Location (uri.toString, r)
437
441
438
442
/**
439
443
* Convert a MessageContainer to an lsp4j.Diagnostic. The positions are transformed vy
You can’t perform that action at this time.
0 commit comments