Skip to content

Commit

Permalink
feat(cli): print URI instead of relative path for better IDE integration
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalHonegger committed May 7, 2023
1 parent ce8aee0 commit ecdc5df
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cli/src/main/kotlin/tools/samt/cli/ASTPrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/kotlin/tools/samt/cli/DiagnosticFormatter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ internal class DiagnosticFormatter(

// -----> <file path>:<location>
append(gray(" ---> "))
append(diagnosticController.workingDirectory.relativize(errorSourceFilePath))
append(errorSourceFilePath.toString())
if (message.highlights.isNotEmpty()) {
val firstHighlight = message.highlights.first()
val firstHighlightLocation = firstHighlight.location
Expand Down
2 changes: 1 addition & 1 deletion cli/src/test/kotlin/tools/samt/cli/ASTPrinterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
33 changes: 16 additions & 17 deletions cli/src/test/kotlin/tools/samt/cli/DiagnosticFormatterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -480,8 +479,8 @@ class DiagnosticFormatterTest {
}

private fun parse(source: String): Triple<FileNode, DiagnosticContext, DiagnosticController> {
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)
Expand Down

0 comments on commit ecdc5df

Please sign in to comment.