From ecdc5dfa0884fde59a8edb8491b2ebd05ea46ec9 Mon Sep 17 00:00:00 2001 From: Pascal Honegger Date: Sun, 7 May 2023 16:14:22 +0200 Subject: [PATCH] feat(cli): print URI instead of relative path for better IDE integration --- .../main/kotlin/tools/samt/cli/ASTPrinter.kt | 2 +- .../tools/samt/cli/DiagnosticFormatter.kt | 2 +- .../kotlin/tools/samt/cli/ASTPrinterTest.kt | 2 +- .../tools/samt/cli/DiagnosticFormatterTest.kt | 33 +++++++++---------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/cli/src/main/kotlin/tools/samt/cli/ASTPrinter.kt b/cli/src/main/kotlin/tools/samt/cli/ASTPrinter.kt index aac32b37..72008581 100644 --- a/cli/src/main/kotlin/tools/samt/cli/ASTPrinter.kt +++ b/cli/src/main/kotlin/tools/samt/cli/ASTPrinter.kt @@ -56,7 +56,7 @@ internal object ASTPrinter { } private fun dumpInfo(node: Node): String? = when (node) { - is FileNode -> gray(node.sourceFile.path.path) + is FileNode -> gray(node.sourceFile.path.toString()) is RequestResponseOperationNode -> if (node.isAsync) red("async") else null is IdentifierNode -> yellow(node.name) is ImportBundleIdentifierNode -> yellow(node.name) + if (node.isWildcard) yellow(".*") else "" diff --git a/cli/src/main/kotlin/tools/samt/cli/DiagnosticFormatter.kt b/cli/src/main/kotlin/tools/samt/cli/DiagnosticFormatter.kt index 57e05bcd..167e11b2 100644 --- a/cli/src/main/kotlin/tools/samt/cli/DiagnosticFormatter.kt +++ b/cli/src/main/kotlin/tools/samt/cli/DiagnosticFormatter.kt @@ -141,7 +141,7 @@ internal class DiagnosticFormatter( // -----> : append(gray(" ---> ")) - append(diagnosticController.workingDirectory.relativize(errorSourceFilePath)) + append(errorSourceFilePath.toString()) if (message.highlights.isNotEmpty()) { val firstHighlight = message.highlights.first() val firstHighlightLocation = firstHighlight.location diff --git a/cli/src/test/kotlin/tools/samt/cli/ASTPrinterTest.kt b/cli/src/test/kotlin/tools/samt/cli/ASTPrinterTest.kt index 11e7d86f..99bcab8e 100644 --- a/cli/src/test/kotlin/tools/samt/cli/ASTPrinterTest.kt +++ b/cli/src/test/kotlin/tools/samt/cli/ASTPrinterTest.kt @@ -36,7 +36,7 @@ class ASTPrinterTest { val dumpWithoutColorCodes = dump.replace(Regex("\u001B\\[[;\\d]*m"), "") assertEquals(""" - FileNode /tmp/ASTPrinterTest.samt <1:1> + FileNode file:///tmp/ASTPrinterTest.samt <1:1> ├─WildcardImportNode <1:1> │ └─ImportBundleIdentifierNode foo.bar.baz.* <1:8> │ ├─IdentifierNode foo <1:8> diff --git a/cli/src/test/kotlin/tools/samt/cli/DiagnosticFormatterTest.kt b/cli/src/test/kotlin/tools/samt/cli/DiagnosticFormatterTest.kt index d3363f45..052054b4 100644 --- a/cli/src/test/kotlin/tools/samt/cli/DiagnosticFormatterTest.kt +++ b/cli/src/test/kotlin/tools/samt/cli/DiagnosticFormatterTest.kt @@ -8,7 +8,6 @@ import tools.samt.parser.EnumDeclarationNode import tools.samt.parser.FileNode import tools.samt.parser.Parser import java.net.URI -import kotlin.io.path.Path import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse @@ -40,8 +39,8 @@ class DiagnosticFormatterTest { @Test fun `file messages with no highlights`() { - val baseDirectory = Path("/tmp").toUri() - val filePath = Path("/tmp", "test.txt").toUri() + val baseDirectory = URI("file:///tmp") + val filePath = URI("file:///tmp/test.txt") val controller = DiagnosticController(baseDirectory) val source = "" val sourceFile = SourceFile(filePath, source) @@ -65,15 +64,15 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> test.txt + ---> file:///tmp/test.txt ──────────────────────────────────────── WARNING: some warning - ---> test.txt + ---> file:///tmp/test.txt ──────────────────────────────────────── INFO: some info - ---> test.txt + ---> file:///tmp/test.txt ──────────────────────────────────────── FAILED in 0ms (1 error(s), 1 warning(s)) @@ -104,7 +103,7 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> DiagnosticFormatterTest.samt:2:1 + ---> file:///tmp/DiagnosticFormatterTest.samt:2:1 1 │ package debug |> 2 │ enum Test { @@ -140,7 +139,7 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> DiagnosticFormatterTest.samt:2:1 + ---> file:///tmp/DiagnosticFormatterTest.samt:2:1 1 │ package debug |> 2 │ enum Test { @@ -183,7 +182,7 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> DiagnosticFormatterTest.samt:3:5 + ---> file:///tmp/DiagnosticFormatterTest.samt:3:5 1 │ package debug 2 │ enum Test { @@ -239,7 +238,7 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> DiagnosticFormatterTest.samt:3:5 + ---> file:///tmp/DiagnosticFormatterTest.samt:3:5 1 │ package debug 2 │ enum Test { @@ -293,7 +292,7 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> DiagnosticFormatterTest.samt:3:5 + ---> file:///tmp/DiagnosticFormatterTest.samt:3:5 1 │ package debug 2 │ enum Test { @@ -339,7 +338,7 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> DiagnosticFormatterTest.samt:3:5 + ---> file:///tmp/DiagnosticFormatterTest.samt:3:5 1 │ package debug 2 │ enum Test { @@ -382,7 +381,7 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> DiagnosticFormatterTest.samt:2:1 + ---> file:///tmp/DiagnosticFormatterTest.samt:2:1 1 │ package debug 2 │ enum Test { @@ -420,7 +419,7 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> DiagnosticFormatterTest.samt:2:1 + ---> file:///tmp/DiagnosticFormatterTest.samt:2:1 1 │ package debug 2 │ enum Test { @@ -461,7 +460,7 @@ class DiagnosticFormatterTest { assertEquals(""" ──────────────────────────────────────── ERROR: some error - ---> DiagnosticFormatterTest.samt:2:1 + ---> file:///tmp/DiagnosticFormatterTest.samt:2:1 1 │ package debug 2 │ enum Test { @@ -480,8 +479,8 @@ class DiagnosticFormatterTest { } private fun parse(source: String): Triple { - val baseDirectory = Path("/tmp").toUri() - val filePath = Path("/tmp", "DiagnosticFormatterTest.samt").toUri() + val baseDirectory = URI("file:///tmp") + val filePath = URI("file:///tmp/DiagnosticFormatterTest.samt") val sourceFile = SourceFile(filePath, source) val diagnosticController = DiagnosticController(baseDirectory) val diagnosticContext = diagnosticController.getOrCreateContext(sourceFile)