diff options
-rw-r--r-- | runtime/doc/eval.txt | 3 | ||||
-rw-r--r-- | src/nvim/quickfix.c | 101 | ||||
-rw-r--r-- | src/nvim/testdir/test_quickfix.vim | 37 | ||||
-rw-r--r-- | src/nvim/testdir/test_tagjump.vim | 13 |
4 files changed, 115 insertions, 39 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 83e10d649d..9f63f79535 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -4759,7 +4759,10 @@ getqflist([{what}]) *getqflist()* bufname() to get the name module module name lnum line number in the buffer (first line is 1) + end_lnum + end of line number if the item is multiline col column number (first column is 1) + end_col end of column number if the item has range vcol |TRUE|: "col" is visual column |FALSE|: "col" is byte index nr error number diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 7c7b790d5c..d09dfac840 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -54,20 +54,23 @@ struct dir_stack_T { // For each error the next struct is allocated and linked in a list. typedef struct qfline_S qfline_T; struct qfline_S { - qfline_T *qf_next; ///< pointer to next error in the list - qfline_T *qf_prev; ///< pointer to previous error in the list - linenr_T qf_lnum; ///< line number where the error occurred - int qf_fnum; ///< file number for the line - int qf_col; ///< column where the error occurred - int qf_nr; ///< error number - char_u *qf_module; ///< module name for this error - char_u *qf_pattern; ///< search pattern for the error - char_u *qf_text; ///< description of the error - char_u qf_viscol; ///< set to TRUE if qf_col is screen column - char_u qf_cleared; ///< set to TRUE if line has been deleted - char_u qf_type; ///< type of the error (mostly 'E'); 1 for - // :helpgrep - char_u qf_valid; ///< valid error message detected + qfline_T *qf_next; ///< pointer to next error in the list + qfline_T *qf_prev; ///< pointer to previous error in the list + linenr_T qf_lnum; ///< line number where the error occurred + linenr_T qf_end_lnum; ///< line number when the error has range or zero + + int qf_fnum; ///< file number for the line + int qf_col; ///< column where the error occurred + int qf_end_col; ///< column when the error has range or zero + int qf_nr; ///< error number + char_u *qf_module; ///< module name for this error + char_u *qf_pattern; ///< search pattern for the error + char_u *qf_text; ///< description of the error + char_u qf_viscol; ///< set to TRUE if qf_col and qf_end_col is + // screen column + char_u qf_cleared; ///< set to TRUE if line has been deleted + char_u qf_type; ///< type of the error (mostly 'E'); 1 for :helpgrep + char_u qf_valid; ///< valid error message detected }; // There is a stack of error lists. @@ -197,7 +200,9 @@ typedef struct { char_u *errmsg; size_t errmsglen; long lnum; + long end_lnum; int col; + int end_col; bool use_viscol; char_u *pattern; int enr; @@ -282,7 +287,9 @@ static int qf_init_process_nextline(qf_list_T *qfl, 0, fields->errmsg, fields->lnum, + fields->end_lnum, fields->col, + fields->end_col, fields->use_viscol, fields->pattern, fields->enr, @@ -1561,7 +1568,9 @@ static int qf_parse_get_fields(char_u *linebuf, size_t linelen, efm_T *fmt_ptr, fields->errmsg[0] = NUL; } fields->lnum = 0; + fields->end_lnum = 0; fields->col = 0; + fields->end_col = 0; fields->use_viscol = false; fields->enr = -1; fields->type = 0; @@ -1799,7 +1808,9 @@ void check_quickfix_busy(void) /// @param bufnum buffer number or zero /// @param mesg message /// @param lnum line number +/// @param end_lnum line number for end /// @param col column +/// @param end_col column for end /// @param vis_col using visual column /// @param pattern search pattern /// @param nr error number @@ -1808,8 +1819,9 @@ void check_quickfix_busy(void) /// /// @returns QF_OK or QF_FAIL. static int qf_add_entry(qf_list_T *qfl, char_u *dir, char_u *fname, - char_u *module, int bufnum, char_u *mesg, long lnum, - int col, char_u vis_col, char_u *pattern, int nr, + char_u *module, int bufnum, char_u *mesg, + long lnum, long end_lnum, int col, int end_col, + char_u vis_col, char_u *pattern, int nr, char_u type, char_u valid) { qfline_T *qfp = xmalloc(sizeof(qfline_T)); @@ -1828,7 +1840,9 @@ static int qf_add_entry(qf_list_T *qfl, char_u *dir, char_u *fname, } qfp->qf_text = vim_strsave(mesg); qfp->qf_lnum = lnum; + qfp->qf_end_lnum = end_lnum; qfp->qf_col = col; + qfp->qf_end_col = end_col; qfp->qf_viscol = vis_col; if (pattern == NULL || *pattern == NUL) { qfp->qf_pattern = NULL; @@ -1957,7 +1971,9 @@ static int copy_loclist_entries(const qf_list_T *from_qfl, qf_list_T *to_qfl) 0, from_qfp->qf_text, from_qfp->qf_lnum, + from_qfp->qf_end_lnum, from_qfp->qf_col, + from_qfp->qf_end_col, from_qfp->qf_viscol, from_qfp->qf_pattern, from_qfp->qf_nr, @@ -3108,11 +3124,8 @@ static void qf_list_entry(qfline_T *qfp, int qf_idx, bool cursel) } if (qfp->qf_lnum == 0) { IObuff[0] = NUL; - } else if (qfp->qf_col == 0) { - vim_snprintf((char *)IObuff, IOSIZE, "%" PRIdLINENR, qfp->qf_lnum); } else { - vim_snprintf((char *)IObuff, IOSIZE, "%" PRIdLINENR " col %d", - qfp->qf_lnum, qfp->qf_col); + qf_range_text(qfp, IObuff, IOSIZE); } vim_snprintf((char *)IObuff + STRLEN(IObuff), IOSIZE, "%s", (char *)qf_types(qfp->qf_type, qfp->qf_nr)); @@ -3232,6 +3245,32 @@ static void qf_fmt_text(const char_u *restrict text, char_u *restrict buf, buf[i] = NUL; } +// Range information from lnum, col, end_lnum, and end_col. +// Put the result in "buf[bufsize]". +static void qf_range_text(const qfline_T *qfp, char_u *buf, int bufsize) +{ + vim_snprintf((char *)buf, (size_t)bufsize, "%" PRIdLINENR, qfp->qf_lnum); + int len = (int)STRLEN(buf); + + if (qfp->qf_end_lnum > 0 && qfp->qf_lnum != qfp->qf_end_lnum) { + vim_snprintf((char *)buf + len, (size_t)(bufsize - len), + "-%" PRIdLINENR, qfp->qf_end_lnum); + len += (int)STRLEN(buf + len); + } + if (qfp->qf_col > 0) { + vim_snprintf((char *)buf + len, (size_t)(bufsize - len), + " col %d", qfp->qf_col); + len += (int)STRLEN(buf + len); + if (qfp->qf_end_col > 0 && qfp->qf_col != qfp->qf_end_col) { + vim_snprintf((char *)buf + len, (size_t)(bufsize - len), + "-%d", qfp->qf_end_col); + len += (int)STRLEN(buf + len); + } + } + buf[len] = NUL; +} + + /// Display information (list number, list size and the title) about a /// quickfix/location list. static void qf_msg(qf_info_T *qi, int which, char *lead) @@ -4005,16 +4044,9 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum, IObuff[len++] = '|'; } if (qfp->qf_lnum > 0) { - snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), "%" PRId64, - (int64_t)qfp->qf_lnum); + qf_range_text(qfp, IObuff + len, IOSIZE - len); len += (int)STRLEN(IObuff + len); - if (qfp->qf_col > 0) { - snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), " col %d", - qfp->qf_col); - len += (int)STRLEN(IObuff + len); - } - snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), "%s", (char *)qf_types(qfp->qf_type, qfp->qf_nr)); len += (int)STRLEN(IObuff + len); @@ -5263,7 +5295,9 @@ static bool vgr_match_buflines(qf_list_T *qfl, char_u *fname, buf_T *buf, ml_get_buf(buf, regmatch->startpos[0].lnum + lnum, false), regmatch->startpos[0].lnum + lnum, + regmatch->endpos[0].lnum + lnum, regmatch->startpos[0].col + 1, + regmatch->endpos[0].col + 1, false, // vis_col NULL, // search pattern 0, // nr @@ -5765,7 +5799,11 @@ static int get_qfline_items(qfline_T *qfp, list_T *list) if (tv_dict_add_nr(dict, S_LEN("bufnr"), (varnumber_T)bufnum) == FAIL || (tv_dict_add_nr(dict, S_LEN("lnum"), (varnumber_T)qfp->qf_lnum) == FAIL) + || (tv_dict_add_nr(dict, S_LEN("end_lnum"), (varnumber_T)qfp->qf_end_lnum) + == FAIL) || (tv_dict_add_nr(dict, S_LEN("col"), (varnumber_T)qfp->qf_col) == FAIL) + || (tv_dict_add_nr(dict, S_LEN("end_col"), (varnumber_T)qfp->qf_end_col) + == FAIL) || (tv_dict_add_nr(dict, S_LEN("vcol"), (varnumber_T)qfp->qf_viscol) == FAIL) || (tv_dict_add_nr(dict, S_LEN("nr"), (varnumber_T)qfp->qf_nr) == FAIL) @@ -6263,7 +6301,9 @@ static int qf_add_entry_from_dict( char *const module = tv_dict_get_string(d, "module", true); int bufnum = (int)tv_dict_get_number(d, "bufnr"); const long lnum = (long)tv_dict_get_number(d, "lnum"); + const long end_lnum = (long)tv_dict_get_number(d, "end_lnum"); const int col = (int)tv_dict_get_number(d, "col"); + const int end_col = (int)tv_dict_get_number(d, "end_col"); const char_u vcol = (char_u)tv_dict_get_number(d, "vcol"); const int nr = (int)tv_dict_get_number(d, "nr"); const char *const type = tv_dict_get_string(d, "type", false); @@ -6301,7 +6341,9 @@ static int qf_add_entry_from_dict( bufnum, (char_u *)text, lnum, + end_lnum, col, + end_col, vcol, // vis_col (char_u *)pattern, // search pattern nr, @@ -7035,7 +7077,10 @@ static void hgr_search_file( 0, line, lnum, + 0, (int)(p_regmatch->startp[0] - line) + 1, // col + (int)(p_regmatch->endp[0] - line) + + 1, // end_col false, // vis_col NULL, // search pattern 0, // nr diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index c0b9dd7696..3c5ef201f9 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -134,6 +134,21 @@ func XlistTests(cchar) call assert_equal([' 2 Xtestfile1:1 col 3: Line1', \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) + " Ranged entries + call g:Xsetlist([{'lnum':10,'text':'Line1'}, + \ {'lnum':20,'col':10,'text':'Line2'}, + \ {'lnum':30,'col':15,'end_col':20,'text':'Line3'}, + \ {'lnum':40,'end_lnum':45,'text':'Line4'}, + \ {'lnum':50,'end_lnum':55,'col':15,'text':'Line5'}, + \ {'lnum':60,'end_lnum':65,'col':25,'end_col':35,'text':'Line6'}]) + let l = split(execute('Xlist', ""), "\n") + call assert_equal([' 1:10: Line1', + \ ' 2:20 col 10: Line2', + \ ' 3:30 col 15-20: Line3', + \ ' 4:40-45: Line4', + \ ' 5:50-55 col 15: Line5', + \ ' 6:60-65 col 25-35: Line6'], l) + " Different types of errors call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11}, \ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22}, @@ -599,6 +614,7 @@ func s:test_xhelpgrep(cchar) call assert_true(&buftype == 'help') call assert_true(winnr() == 1) call assert_true(winnr('$') == 2) + call assert_match('|\d\+ col \d\+-\d\+|', getbufline(winbufnr(2), 1)[0]) " This wipes out the buffer, make sure that doesn't cause trouble. Xclose @@ -1437,10 +1453,13 @@ func SetXlistTests(cchar, bnum) call s:setup_commands(a:cchar) call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1}, - \ {'bufnr': a:bnum, 'lnum': 2}]) + \ {'bufnr': a:bnum, 'lnum': 2, 'end_lnum': 3, 'col': 4, 'end_col': 5}]) let l = g:Xgetlist() call assert_equal(2, len(l)) call assert_equal(2, l[1].lnum) + call assert_equal(3, l[1].end_lnum) + call assert_equal(4, l[1].col) + call assert_equal(5, l[1].end_col) Xnext call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a') @@ -2743,7 +2762,9 @@ func XvimgrepTests(cchar) let l = g:Xgetlist() call assert_equal(2, len(l)) call assert_equal(8, l[0].col) + call assert_equal(11, l[0].end_col) call assert_equal(12, l[1].col) + call assert_equal(15, l[1].end_col) 1Xvimgrep ?Editor? Xtestfile* let l = g:Xgetlist() @@ -4850,7 +4871,7 @@ func Test_add_invalid_entry_with_qf_window() call setqflist(['bb'], 'a') call assert_equal(1, line('$')) call assert_equal(['Xfile1|10| aa'], getline(1, '$')) - call assert_equal([{'lnum': 10, 'bufnr': bufnr('Xfile1'), 'col': 0, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'module': '', 'text': 'aa'}], getqflist()) + call assert_equal([{'lnum': 10, 'end_lnum': 0, 'bufnr': bufnr('Xfile1'), 'col': 0, 'end_col': 0, 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'module': '', 'text': 'aa'}], getqflist()) cclose endfunc @@ -5001,15 +5022,21 @@ func Xtest_qftextfunc(cchar) call assert_equal('Tqfexpr', &quickfixtextfunc) call assert_equal('', \ g:Xgetlist({'quickfixtextfunc' : 1}).quickfixtextfunc) - Xexpr ['F1:10:2:green', 'F1:20:4:blue'] + call g:Xsetlist([ + \ { 'filename': 'F1', 'lnum': 10, 'col': 2, + \ 'end_col': 7, 'text': 'green'}, + \ { 'filename': 'F1', 'lnum': 20, 'end_lnum': 25, 'col': 4, + \ 'end_col': 8, 'text': 'blue'}, + \ ]) + Xwindow call assert_equal('F1-L10C2-green', getline(1)) call assert_equal('F1-L20C4-blue', getline(2)) Xclose set quickfixtextfunc&vim Xwindow - call assert_equal('F1|10 col 2| green', getline(1)) - call assert_equal('F1|20 col 4| blue', getline(2)) + call assert_equal('F1|10 col 2-7| green', getline(1)) + call assert_equal('F1|20-25 col 4-8| blue', getline(2)) Xclose set efm& set quickfixtextfunc& diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 9f02af7d8e..68dcfb6890 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -771,15 +771,16 @@ func Test_ltag() ltag third call assert_equal('Xfoo', bufname('')) call assert_equal(3, line('.')) - call assert_equal([{'lnum': 3, 'bufnr': bufnr('Xfoo'), 'col': 0, - \ 'pattern': '', 'valid': 1, 'vcol': 0, 'nr': 0, 'type': '', - \ 'module': '', 'text': 'third'}], getloclist(0)) + call assert_equal([{'lnum': 3, 'end_lnum': 0, 'bufnr': bufnr('Xfoo'), + \ 'col': 0, 'end_col': 0, 'pattern': '', 'valid': 1, 'vcol': 0, + \ 'nr': 0, 'type': '', 'module': '', 'text': 'third'}], getloclist(0)) ltag second call assert_equal(2, line('.')) - call assert_equal([{'lnum': 0, 'bufnr': bufnr('Xfoo'), 'col': 0, - \ 'pattern': '^\Vint second() {}\$', 'valid': 1, 'vcol': 0, 'nr': 0, - \ 'type': '', 'module': '', 'text': 'second'}], getloclist(0)) + call assert_equal([{'lnum': 0, 'end_lnum': 0, 'bufnr': bufnr('Xfoo'), + \ 'col': 0, 'end_col': 0, 'pattern': '^\Vint second() {}\$', + \ 'valid': 1, 'vcol': 0, 'nr': 0, 'type': '', 'module': '', + \ 'text': 'second'}], getloclist(0)) call delete('Xtags') call delete('Xfoo') |