| ... | @@ -21,11 +21,32 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) | ... | @@ -21,11 +21,32 @@ static void print_err_msg_type(ErrorMsg *err, ErrColor color, ErrType err_type) |
| 21 | | 21 | |
| 22 | // Show the error location, if available | 22 | // Show the error location, if available |
| 23 | if (err->path != nullptr) { | 23 | if (err->path != nullptr) { |
| | 24 | const char *path = buf_ptr(err->path); |
| | 25 | Slice<const char> pathslice{path, strlen(path)}; |
| | 26 | |
| | 27 | // Cache cwd |
| | 28 | static Buf *cwdbuf{nullptr}; |
| | 29 | static Slice<const char> cwd; |
| | 30 | |
| | 31 | if (cwdbuf == nullptr) { |
| | 32 | cwdbuf = buf_alloc(); |
| | 33 | Error err = os_get_cwd(cwdbuf); |
| | 34 | if (err != ErrorNone) |
| | 35 | zig_panic("get cwd failed"); |
| | 36 | buf_append_char(cwdbuf, ZIG_OS_SEP_CHAR); |
| | 37 | cwd.ptr = buf_ptr(cwdbuf); |
| | 38 | cwd.len = strlen(cwd.ptr); |
| | 39 | } |
| | 40 | |
| 24 | const size_t line = err->line_start + 1; | 41 | const size_t line = err->line_start + 1; |
| 25 | const size_t col = err->column_start + 1; | 42 | const size_t col = err->column_start + 1; |
| 26 | | | |
| 27 | if (use_colors) os_stderr_set_color(TermColorBold); | 43 | if (use_colors) os_stderr_set_color(TermColorBold); |
| 28 | fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", buf_ptr(err->path), line, col); | 44 | |
| | 45 | // Strip cwd from path |
| | 46 | if (memStartsWith(pathslice, cwd)) |
| | 47 | fprintf(stderr, ".%c%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", ZIG_OS_SEP_CHAR, path+cwd.len, line, col); |
| | 48 | else |
| | 49 | fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ": ", path, line, col); |
| 29 | } | 50 | } |
| 30 | | 51 | |
| 31 | // Write out the error type | 52 | // Write out the error type |