From 7c2114e3895bac6f60e641e854906b2139e7ec84 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 2 Oct 2023 09:58:20 +0200 Subject: [PATCH] [BSP] Use consistent file URI format (#2803) Previously we were emitting different URI formats if the sourceFile info was missing or not. Not sure if this is a problem, but `targetId.getUri` is returning files as `file:///foo/bar/file.scala` while our `java.io.File` `toURI` returns `file:/foo/bar/file.scala` Changing it to `.toPath.toUri` for consistency Pull request: https://github.com/com-lihaoyi/mill/pull/2803 Co-authored-by: Tobias Roeser --- .../src/mill/bsp/worker/BspCompileProblemReporter.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bsp/worker/src/mill/bsp/worker/BspCompileProblemReporter.scala b/bsp/worker/src/mill/bsp/worker/BspCompileProblemReporter.scala index 40929bc1326..120ebe0f521 100644 --- a/bsp/worker/src/mill/bsp/worker/BspCompileProblemReporter.scala +++ b/bsp/worker/src/mill/bsp/worker/BspCompileProblemReporter.scala @@ -69,9 +69,11 @@ private class BspCompileProblemReporter( val diagnostic = getSingleDiagnostic(problem) val sourceFile = problem.position.sourceFile val textDocument = new TextDocumentIdentifier( - sourceFile.getOrElse(None) match { + sourceFile match { case None => targetId.getUri - case f: File => f.toURI.toString + case Some(f) => + // The extra step invoking `toPath` results in a nicer URI starting with `file:///` + f.toPath.toUri.toString } ) val params = new bsp.PublishDiagnosticsParams(