From 8da12eb8a77ac8afb4dba78439d93f5af4e7a623 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 6 Apr 2020 23:15:38 +0300 Subject: [PATCH] errors: column index tweaks for emacs/vim --- vlib/v/util/errors.v | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/vlib/v/util/errors.v b/vlib/v/util/errors.v index 16e675c210..7d3abcc088 100644 --- a/vlib/v/util/errors.v +++ b/vlib/v/util/errors.v @@ -54,20 +54,17 @@ pub fn formated_error(kind string /*error or warn*/, emsg string, filepath strin } } // - mut column := 0 mut source_context := '' source := util.read_file(filepath) or { '' } source_lines := source.split_into_lines() - if source.len > pos.pos { - mut p := pos.pos - for ; p>=0; p-- { - if source[p] == `\r` || source[p] == `\n` { - break - } + mut p := util.imax(0, util.imin(source.len -1, pos.pos)) + for ; p>=0; p-- { + if source[p] == `\r` || source[p] == `\n` { + break } - column = util.imax(0, pos.pos - p - 1) } - position := '${path}:${pos.line_nr+1}:$column:' + column := util.imax(0, pos.pos - p - 1) + position := '${path}:${pos.line_nr+1}:${util.imax(1,column+1)}:' // bline := util.imax(0, pos.line_nr - error_context_before) aline := util.imin(source_lines.len-1, pos.line_nr + error_context_after)