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:
parent
af56719f9d
commit
ef1696b3e1
@ -3,7 +3,6 @@
|
|||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
module eval
|
module eval
|
||||||
|
|
||||||
import os
|
|
||||||
import v.ast
|
import v.ast
|
||||||
import v.pref
|
import v.pref
|
||||||
import v.util
|
import v.util
|
||||||
@ -242,7 +241,7 @@ fn (e Eval) print_backtrace() {
|
|||||||
for i := e.back_trace.len - 1; i >= 0; i-- {
|
for i := e.back_trace.len - 1; i >= 0; i-- {
|
||||||
t := e.back_trace[i]
|
t := e.back_trace[i]
|
||||||
file_path := if path := e.trace_file_paths[t.file_idx] {
|
file_path := if path := e.trace_file_paths[t.file_idx] {
|
||||||
os.real_path(path)
|
util.path_styled_for_error_messages(path)
|
||||||
} else {
|
} else {
|
||||||
t.file_idx.str()
|
t.file_idx.str()
|
||||||
}
|
}
|
||||||
|
@ -75,10 +75,10 @@ fn color(kind string, msg string) string {
|
|||||||
|
|
||||||
const normalised_workdir = os.wd_at_startup.replace('\\', '/') + '/'
|
const normalised_workdir = os.wd_at_startup.replace('\\', '/') + '/'
|
||||||
|
|
||||||
// formatted_error - `kind` may be 'error' or 'warn'
|
// path_styled_for_error_messages returns the modified file path according
|
||||||
pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos) string {
|
// to the user's preference (`VERROR_PATHS` env-var)
|
||||||
emsg := omsg.replace('main.', '')
|
pub fn path_styled_for_error_messages(path_ string) string {
|
||||||
mut path := filepath
|
mut path := path_
|
||||||
verror_paths_override := os.getenv('VERROR_PATHS')
|
verror_paths_override := os.getenv('VERROR_PATHS')
|
||||||
if verror_paths_override == 'absolute' {
|
if verror_paths_override == 'absolute' {
|
||||||
path = os.real_path(path)
|
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, '')
|
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 {
|
position := if filepath.len > 0 {
|
||||||
'$path:${pos.line_nr + 1}:${mu.max(1, pos.col + 1)}:'
|
'$path:${pos.line_nr + 1}:${mu.max(1, pos.col + 1)}:'
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user