diff options
author | thinca <thinca@gmail.com> | 2021-06-19 20:45:20 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-06-19 20:45:20 +0200 |
commit | 6864efa59636ccede2af24e3f5f92d78d210d77b (patch) | |
tree | 0d17b8f331e5db8e69554a8cd60e0e3acee0c888 /src/quickfix.c | |
parent | ad52f96a2d3169cb1b915c1d4a6ba26ba6e5bd0a (diff) | |
download | vim-git-6864efa59636ccede2af24e3f5f92d78d210d77b.tar.gz |
patch 8.2.3019: location list only has the start position.v8.2.3019
Problem: Location list only has the start position.
Solution: Make it possible to add an end position. (Shane-XB-Qian,
closes #8393)
Diffstat (limited to 'src/quickfix.c')
-rw-r--r-- | src/quickfix.c | 91 |
1 files changed, 70 insertions, 21 deletions
diff --git a/src/quickfix.c b/src/quickfix.c index 4974cb479..36574b80f 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -30,13 +30,16 @@ 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 + 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 is screen column + 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 @@ -165,7 +168,7 @@ static efm_T *fmt_start = NULL; // cached across qf_parse_line() calls static callback_T qftf_cb; static void qf_new_list(qf_info_T *qi, char_u *qf_title); -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, int vis_col, char_u *pattern, int nr, int type, int valid); +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, long end_lnum, int col, int end_col, int vis_col, char_u *pattern, int nr, int type, int valid); static void qf_free(qf_list_T *qfl); static char_u *qf_types(int, int); static int qf_get_fnum(qf_list_T *qfl, char_u *, char_u *); @@ -174,6 +177,7 @@ static char_u *qf_pop_dir(struct dir_stack_T **); static char_u *qf_guess_filepath(qf_list_T *qfl, char_u *); static void qf_jump_newwin(qf_info_T *qi, int dir, int errornr, int forceit, int newwin); static void qf_fmt_text(char_u *text, char_u *buf, int bufsize); +static void qf_range_text(qfline_T *qfp, char_u *buf, int bufsize); static int qf_win_pos_update(qf_info_T *qi, int old_qf_index); static win_T *qf_find_win(qf_info_T *qi); static buf_T *qf_find_buf(qf_info_T *qi); @@ -899,7 +903,9 @@ typedef struct { char_u *errmsg; int errmsglen; long lnum; + long end_lnum; int col; + int end_col; char_u use_viscol; char_u *pattern; int enr; @@ -1235,7 +1241,9 @@ qf_parse_get_fields( if (!qf_multiscan) 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; @@ -1630,7 +1638,9 @@ qf_init_process_nextline( 0, fields->errmsg, fields->lnum, + fields->end_lnum, fields->col, + fields->end_col, fields->use_viscol, fields->pattern, fields->enr, @@ -2053,7 +2063,9 @@ qf_add_entry( int bufnum, // buffer number or zero char_u *mesg, // message long lnum, // line number + long end_lnum, // line number for end int col, // column + int end_col, // column for end int vis_col, // using visual column char_u *pattern, // search pattern int nr, // error number @@ -2082,7 +2094,9 @@ qf_add_entry( return QF_FAIL; } 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; @@ -2239,7 +2253,9 @@ copy_loclist_entries(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, @@ -3555,11 +3571,8 @@ qf_list_entry(qfline_T *qfp, int qf_idx, int cursel) msg_puts_attr(":", qfSepAttr); if (qfp->qf_lnum == 0) IObuff[0] = NUL; - else if (qfp->qf_col == 0) - sprintf((char *)IObuff, "%ld", qfp->qf_lnum); else - sprintf((char *)IObuff, "%ld col %d", - qfp->qf_lnum, qfp->qf_col); + qf_range_text(qfp, IObuff, IOSIZE); sprintf((char *)IObuff + STRLEN(IObuff), "%s", (char *)qf_types(qfp->qf_type, qfp->qf_nr)); msg_puts_attr((char *)IObuff, qfLineAttr); @@ -3686,6 +3699,37 @@ qf_fmt_text(char_u *text, char_u *buf, int bufsize) } /* + * Range information from lnum, col, end_lnum, and end_col. + * Put the result in "buf[bufsize]". + */ + static void +qf_range_text(qfline_T *qfp, char_u *buf, int bufsize) +{ + int len; + vim_snprintf((char *)buf, bufsize, "%ld", qfp->qf_lnum); + len = (int)STRLEN(buf); + + if (qfp->qf_end_lnum > 0 && qfp->qf_lnum != qfp->qf_end_lnum) + { + vim_snprintf((char *)buf + len, bufsize - len, + "-%ld", qfp->qf_end_lnum); + len += (int)STRLEN(buf + len); + } + if (qfp->qf_col > 0) + { + vim_snprintf((char *)buf + len, 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, 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. */ @@ -4565,17 +4609,9 @@ qf_buf_add_line( if (qfp->qf_lnum > 0) { - vim_snprintf((char *)IObuff + len, IOSIZE - len, "%ld", - qfp->qf_lnum); + qf_range_text(qfp, IObuff + len, IOSIZE - len); len += (int)STRLEN(IObuff + len); - if (qfp->qf_col > 0) - { - vim_snprintf((char *)IObuff + len, IOSIZE - len, - " col %d", qfp->qf_col); - len += (int)STRLEN(IObuff + len); - } - vim_snprintf((char *)IObuff + len, IOSIZE - len, "%s", (char *)qf_types(qfp->qf_type, qfp->qf_nr)); len += (int)STRLEN(IObuff + len); @@ -5953,7 +5989,9 @@ vgr_match_buflines( 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 @@ -5996,7 +6034,9 @@ vgr_match_buflines( duplicate_name ? 0 : buf->b_fnum, str, lnum, + 0, matches[0] + col + 1, + 0, FALSE, // vis_col NULL, // search pattern 0, // nr @@ -6626,10 +6666,12 @@ get_qfline_items(qfline_T *qfp, list_T *list) buf[0] = qfp->qf_type; buf[1] = NUL; if (dict_add_number(dict, "bufnr", (long)bufnum) == FAIL - || dict_add_number(dict, "lnum", (long)qfp->qf_lnum) == FAIL - || dict_add_number(dict, "col", (long)qfp->qf_col) == FAIL - || dict_add_number(dict, "vcol", (long)qfp->qf_viscol) == FAIL - || dict_add_number(dict, "nr", (long)qfp->qf_nr) == FAIL + || dict_add_number(dict, "lnum", (long)qfp->qf_lnum) == FAIL + || dict_add_number(dict, "end_lnum", (long)qfp->qf_end_lnum) == FAIL + || dict_add_number(dict, "col", (long)qfp->qf_col) == FAIL + || dict_add_number(dict, "end_col", (long)qfp->qf_end_col) == FAIL + || dict_add_number(dict, "vcol", (long)qfp->qf_viscol) == FAIL + || dict_add_number(dict, "nr", (long)qfp->qf_nr) == FAIL || dict_add_string(dict, "module", qfp->qf_module) == FAIL || dict_add_string(dict, "pattern", qfp->qf_pattern) == FAIL || dict_add_string(dict, "text", qfp->qf_text) == FAIL @@ -7143,8 +7185,8 @@ qf_add_entry_from_dict( { static int did_bufnr_emsg; char_u *filename, *module, *pattern, *text, *type; - int bufnum, valid, status, col, vcol, nr; - long lnum; + int bufnum, valid, status, col, end_col, vcol, nr; + long lnum, end_lnum; if (first_entry) did_bufnr_emsg = FALSE; @@ -7153,7 +7195,9 @@ qf_add_entry_from_dict( module = dict_get_string(d, (char_u *)"module", TRUE); bufnum = (int)dict_get_number(d, (char_u *)"bufnr"); lnum = (int)dict_get_number(d, (char_u *)"lnum"); + end_lnum = (int)dict_get_number(d, (char_u *)"end_lnum"); col = (int)dict_get_number(d, (char_u *)"col"); + end_col = (int)dict_get_number(d, (char_u *)"end_col"); vcol = (int)dict_get_number(d, (char_u *)"vcol"); nr = (int)dict_get_number(d, (char_u *)"nr"); type = dict_get_string(d, (char_u *)"type", TRUE); @@ -7190,7 +7234,9 @@ qf_add_entry_from_dict( bufnum, text, lnum, + end_lnum, col, + end_col, vcol, // vis_col pattern, // search pattern nr, @@ -8058,8 +8104,11 @@ 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 |