fix problematic path handling on windows in error messages

This commit is contained in:
Irmen de Jong 2022-06-05 11:54:19 +02:00
parent af2ca7a67e
commit 926fdecd13

View File

@ -1,13 +1,19 @@
package prog8.code.core package prog8.code.core
import java.nio.file.InvalidPathException
import kotlin.io.path.Path import kotlin.io.path.Path
import kotlin.io.path.absolute import kotlin.io.path.absolute
data class Position(val file: String, val line: Int, val startCol: Int, val endCol: Int) { data class Position(val file: String, val line: Int, val startCol: Int, val endCol: Int) {
override fun toString(): String = "[$file: line $line col ${startCol+1}-${endCol+1}]" override fun toString(): String = "[$file: line $line col ${startCol+1}-${endCol+1}]"
fun toClickableStr(): String { fun toClickableStr(): String {
val path = Path(file).absolute().normalize() return try {
return "file://$path:$line:$startCol:" val path = Path(file).absolute().normalize().toString()
"file://$path:$line:$startCol:"
} catch(x: InvalidPathException) {
// this can occur on Windows when the source origin contains "invalid" characters such as ':'
"file://$file:$line:$startCol:"
}
} }
companion object { companion object {