1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.util: add path_styled_for_error_messages/1 (#16219)

This commit is contained in:
StunxFS 2022-10-28 04:27:00 -04:00 committed by GitHub
parent af56719f9d
commit ef1696b3e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -3,7 +3,6 @@
// that can be found in the LICENSE file.
module eval
import os
import v.ast
import v.pref
import v.util
@ -242,7 +241,7 @@ fn (e Eval) print_backtrace() {
for i := e.back_trace.len - 1; i >= 0; i-- {
t := e.back_trace[i]
file_path := if path := e.trace_file_paths[t.file_idx] {
os.real_path(path)
util.path_styled_for_error_messages(path)
} else {
t.file_idx.str()
}

View File

@ -75,10 +75,10 @@ fn color(kind string, msg string) string {
const normalised_workdir = os.wd_at_startup.replace('\\', '/') + '/'
// formatted_error - `kind` may be 'error' or 'warn'
pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos) string {
emsg := omsg.replace('main.', '')
mut path := filepath
// path_styled_for_error_messages returns the modified file path according
// to the user's preference (`VERROR_PATHS` env-var)
pub fn path_styled_for_error_messages(path_ string) string {
mut path := path_
verror_paths_override := os.getenv('VERROR_PATHS')
if verror_paths_override == 'absolute' {
path = os.real_path(path)
@ -90,7 +90,13 @@ pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos)
path = path.replace_once(util.normalised_workdir, '')
}
}
return path
}
// formatted_error - `kind` may be 'error' or 'warn'
pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos) string {
emsg := omsg.replace('main.', '')
path := path_styled_for_error_messages(filepath)
position := if filepath.len > 0 {
'$path:${pos.line_nr + 1}:${mu.max(1, pos.col + 1)}:'
} else {