Mercurial > vim
comparison src/quickfix.c @ 24964:f4aa891a5ab8 v8.2.3019
patch 8.2.3019: location list only has the start position.
Commit: https://github.com/vim/vim/commit/6864efa59636ccede2af24e3f5f92d78d210d77b
Author: thinca <thinca@gmail.com>
Date: Sat Jun 19 20:45:20 2021 +0200
patch 8.2.3019: location list only has the start position.
Problem: Location list only has the start position.
Solution: Make it possible to add an end position. (Shane-XB-Qian,
closes #8393)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 19 Jun 2021 21:00:04 +0200 |
parents | 437b8be91993 |
children | 8f2262c72178 |
comparison
equal
deleted
inserted
replaced
24963:1f8e4f3946f2 | 24964:f4aa891a5ab8 |
---|---|
28 struct qfline_S | 28 struct qfline_S |
29 { | 29 { |
30 qfline_T *qf_next; // pointer to next error in the list | 30 qfline_T *qf_next; // pointer to next error in the list |
31 qfline_T *qf_prev; // pointer to previous error in the list | 31 qfline_T *qf_prev; // pointer to previous error in the list |
32 linenr_T qf_lnum; // line number where the error occurred | 32 linenr_T qf_lnum; // line number where the error occurred |
33 linenr_T qf_end_lnum; // line number when the error has range or zero | |
33 int qf_fnum; // file number for the line | 34 int qf_fnum; // file number for the line |
34 int qf_col; // column where the error occurred | 35 int qf_col; // column where the error occurred |
36 int qf_end_col; // column when the error has range or zero | |
35 int qf_nr; // error number | 37 int qf_nr; // error number |
36 char_u *qf_module; // module name for this error | 38 char_u *qf_module; // module name for this error |
37 char_u *qf_pattern; // search pattern for the error | 39 char_u *qf_pattern; // search pattern for the error |
38 char_u *qf_text; // description of the error | 40 char_u *qf_text; // description of the error |
39 char_u qf_viscol; // set to TRUE if qf_col is screen column | 41 char_u qf_viscol; // set to TRUE if qf_col and qf_end_col is |
42 // screen column | |
40 char_u qf_cleared; // set to TRUE if line has been deleted | 43 char_u qf_cleared; // set to TRUE if line has been deleted |
41 char_u qf_type; // type of the error (mostly 'E'); 1 for | 44 char_u qf_type; // type of the error (mostly 'E'); 1 for |
42 // :helpgrep | 45 // :helpgrep |
43 char_u qf_valid; // valid error message detected | 46 char_u qf_valid; // valid error message detected |
44 }; | 47 }; |
163 | 166 |
164 // callback function for 'quickfixtextfunc' | 167 // callback function for 'quickfixtextfunc' |
165 static callback_T qftf_cb; | 168 static callback_T qftf_cb; |
166 | 169 |
167 static void qf_new_list(qf_info_T *qi, char_u *qf_title); | 170 static void qf_new_list(qf_info_T *qi, char_u *qf_title); |
168 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); | 171 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); |
169 static void qf_free(qf_list_T *qfl); | 172 static void qf_free(qf_list_T *qfl); |
170 static char_u *qf_types(int, int); | 173 static char_u *qf_types(int, int); |
171 static int qf_get_fnum(qf_list_T *qfl, char_u *, char_u *); | 174 static int qf_get_fnum(qf_list_T *qfl, char_u *, char_u *); |
172 static char_u *qf_push_dir(char_u *, struct dir_stack_T **, int is_file_stack); | 175 static char_u *qf_push_dir(char_u *, struct dir_stack_T **, int is_file_stack); |
173 static char_u *qf_pop_dir(struct dir_stack_T **); | 176 static char_u *qf_pop_dir(struct dir_stack_T **); |
174 static char_u *qf_guess_filepath(qf_list_T *qfl, char_u *); | 177 static char_u *qf_guess_filepath(qf_list_T *qfl, char_u *); |
175 static void qf_jump_newwin(qf_info_T *qi, int dir, int errornr, int forceit, int newwin); | 178 static void qf_jump_newwin(qf_info_T *qi, int dir, int errornr, int forceit, int newwin); |
176 static void qf_fmt_text(char_u *text, char_u *buf, int bufsize); | 179 static void qf_fmt_text(char_u *text, char_u *buf, int bufsize); |
180 static void qf_range_text(qfline_T *qfp, char_u *buf, int bufsize); | |
177 static int qf_win_pos_update(qf_info_T *qi, int old_qf_index); | 181 static int qf_win_pos_update(qf_info_T *qi, int old_qf_index); |
178 static win_T *qf_find_win(qf_info_T *qi); | 182 static win_T *qf_find_win(qf_info_T *qi); |
179 static buf_T *qf_find_buf(qf_info_T *qi); | 183 static buf_T *qf_find_buf(qf_info_T *qi); |
180 static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last); | 184 static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last); |
181 static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int qf_winid); | 185 static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int qf_winid); |
897 char_u *namebuf; | 901 char_u *namebuf; |
898 char_u *module; | 902 char_u *module; |
899 char_u *errmsg; | 903 char_u *errmsg; |
900 int errmsglen; | 904 int errmsglen; |
901 long lnum; | 905 long lnum; |
906 long end_lnum; | |
902 int col; | 907 int col; |
908 int end_col; | |
903 char_u use_viscol; | 909 char_u use_viscol; |
904 char_u *pattern; | 910 char_u *pattern; |
905 int enr; | 911 int enr; |
906 int type; | 912 int type; |
907 int valid; | 913 int valid; |
1233 fields->module[0] = NUL; | 1239 fields->module[0] = NUL; |
1234 fields->pattern[0] = NUL; | 1240 fields->pattern[0] = NUL; |
1235 if (!qf_multiscan) | 1241 if (!qf_multiscan) |
1236 fields->errmsg[0] = NUL; | 1242 fields->errmsg[0] = NUL; |
1237 fields->lnum = 0; | 1243 fields->lnum = 0; |
1244 fields->end_lnum = 0; | |
1238 fields->col = 0; | 1245 fields->col = 0; |
1246 fields->end_col = 0; | |
1239 fields->use_viscol = FALSE; | 1247 fields->use_viscol = FALSE; |
1240 fields->enr = -1; | 1248 fields->enr = -1; |
1241 fields->type = 0; | 1249 fields->type = 0; |
1242 *tail = NULL; | 1250 *tail = NULL; |
1243 | 1251 |
1628 ? qfl->qf_currfile : (char_u *)NULL), | 1636 ? qfl->qf_currfile : (char_u *)NULL), |
1629 fields->module, | 1637 fields->module, |
1630 0, | 1638 0, |
1631 fields->errmsg, | 1639 fields->errmsg, |
1632 fields->lnum, | 1640 fields->lnum, |
1641 fields->end_lnum, | |
1633 fields->col, | 1642 fields->col, |
1643 fields->end_col, | |
1634 fields->use_viscol, | 1644 fields->use_viscol, |
1635 fields->pattern, | 1645 fields->pattern, |
1636 fields->enr, | 1646 fields->enr, |
1637 fields->type, | 1647 fields->type, |
1638 fields->valid); | 1648 fields->valid); |
2051 char_u *fname, // file name or NULL | 2061 char_u *fname, // file name or NULL |
2052 char_u *module, // module name or NULL | 2062 char_u *module, // module name or NULL |
2053 int bufnum, // buffer number or zero | 2063 int bufnum, // buffer number or zero |
2054 char_u *mesg, // message | 2064 char_u *mesg, // message |
2055 long lnum, // line number | 2065 long lnum, // line number |
2066 long end_lnum, // line number for end | |
2056 int col, // column | 2067 int col, // column |
2068 int end_col, // column for end | |
2057 int vis_col, // using visual column | 2069 int vis_col, // using visual column |
2058 char_u *pattern, // search pattern | 2070 char_u *pattern, // search pattern |
2059 int nr, // error number | 2071 int nr, // error number |
2060 int type, // type character | 2072 int type, // type character |
2061 int valid) // valid entry | 2073 int valid) // valid entry |
2080 { | 2092 { |
2081 vim_free(qfp); | 2093 vim_free(qfp); |
2082 return QF_FAIL; | 2094 return QF_FAIL; |
2083 } | 2095 } |
2084 qfp->qf_lnum = lnum; | 2096 qfp->qf_lnum = lnum; |
2097 qfp->qf_end_lnum = end_lnum; | |
2085 qfp->qf_col = col; | 2098 qfp->qf_col = col; |
2099 qfp->qf_end_col = end_col; | |
2086 qfp->qf_viscol = vis_col; | 2100 qfp->qf_viscol = vis_col; |
2087 if (pattern == NULL || *pattern == NUL) | 2101 if (pattern == NULL || *pattern == NUL) |
2088 qfp->qf_pattern = NULL; | 2102 qfp->qf_pattern = NULL; |
2089 else if ((qfp->qf_pattern = vim_strsave(pattern)) == NULL) | 2103 else if ((qfp->qf_pattern = vim_strsave(pattern)) == NULL) |
2090 { | 2104 { |
2237 NULL, | 2251 NULL, |
2238 from_qfp->qf_module, | 2252 from_qfp->qf_module, |
2239 0, | 2253 0, |
2240 from_qfp->qf_text, | 2254 from_qfp->qf_text, |
2241 from_qfp->qf_lnum, | 2255 from_qfp->qf_lnum, |
2256 from_qfp->qf_end_lnum, | |
2242 from_qfp->qf_col, | 2257 from_qfp->qf_col, |
2258 from_qfp->qf_end_col, | |
2243 from_qfp->qf_viscol, | 2259 from_qfp->qf_viscol, |
2244 from_qfp->qf_pattern, | 2260 from_qfp->qf_pattern, |
2245 from_qfp->qf_nr, | 2261 from_qfp->qf_nr, |
2246 0, | 2262 0, |
2247 from_qfp->qf_valid) == QF_FAIL) | 2263 from_qfp->qf_valid) == QF_FAIL) |
3553 | 3569 |
3554 if (qfp->qf_lnum != 0) | 3570 if (qfp->qf_lnum != 0) |
3555 msg_puts_attr(":", qfSepAttr); | 3571 msg_puts_attr(":", qfSepAttr); |
3556 if (qfp->qf_lnum == 0) | 3572 if (qfp->qf_lnum == 0) |
3557 IObuff[0] = NUL; | 3573 IObuff[0] = NUL; |
3558 else if (qfp->qf_col == 0) | |
3559 sprintf((char *)IObuff, "%ld", qfp->qf_lnum); | |
3560 else | 3574 else |
3561 sprintf((char *)IObuff, "%ld col %d", | 3575 qf_range_text(qfp, IObuff, IOSIZE); |
3562 qfp->qf_lnum, qfp->qf_col); | |
3563 sprintf((char *)IObuff + STRLEN(IObuff), "%s", | 3576 sprintf((char *)IObuff + STRLEN(IObuff), "%s", |
3564 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); | 3577 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); |
3565 msg_puts_attr((char *)IObuff, qfLineAttr); | 3578 msg_puts_attr((char *)IObuff, qfLineAttr); |
3566 msg_puts_attr(":", qfSepAttr); | 3579 msg_puts_attr(":", qfSepAttr); |
3567 if (qfp->qf_pattern != NULL) | 3580 if (qfp->qf_pattern != NULL) |
3681 } | 3694 } |
3682 else | 3695 else |
3683 buf[i] = *p++; | 3696 buf[i] = *p++; |
3684 } | 3697 } |
3685 buf[i] = NUL; | 3698 buf[i] = NUL; |
3699 } | |
3700 | |
3701 /* | |
3702 * Range information from lnum, col, end_lnum, and end_col. | |
3703 * Put the result in "buf[bufsize]". | |
3704 */ | |
3705 static void | |
3706 qf_range_text(qfline_T *qfp, char_u *buf, int bufsize) | |
3707 { | |
3708 int len; | |
3709 vim_snprintf((char *)buf, bufsize, "%ld", qfp->qf_lnum); | |
3710 len = (int)STRLEN(buf); | |
3711 | |
3712 if (qfp->qf_end_lnum > 0 && qfp->qf_lnum != qfp->qf_end_lnum) | |
3713 { | |
3714 vim_snprintf((char *)buf + len, bufsize - len, | |
3715 "-%ld", qfp->qf_end_lnum); | |
3716 len += (int)STRLEN(buf + len); | |
3717 } | |
3718 if (qfp->qf_col > 0) | |
3719 { | |
3720 vim_snprintf((char *)buf + len, bufsize - len, " col %d", qfp->qf_col); | |
3721 len += (int)STRLEN(buf + len); | |
3722 if (qfp->qf_end_col > 0 && qfp->qf_col != qfp->qf_end_col) | |
3723 { | |
3724 vim_snprintf((char *)buf + len, bufsize - len, | |
3725 "-%d", qfp->qf_end_col); | |
3726 len += (int)STRLEN(buf + len); | |
3727 } | |
3728 } | |
3729 buf[len] = NUL; | |
3686 } | 3730 } |
3687 | 3731 |
3688 /* | 3732 /* |
3689 * Display information (list number, list size and the title) about a | 3733 * Display information (list number, list size and the title) about a |
3690 * quickfix/location list. | 3734 * quickfix/location list. |
4563 if (len < IOSIZE - 1) | 4607 if (len < IOSIZE - 1) |
4564 IObuff[len++] = '|'; | 4608 IObuff[len++] = '|'; |
4565 | 4609 |
4566 if (qfp->qf_lnum > 0) | 4610 if (qfp->qf_lnum > 0) |
4567 { | 4611 { |
4568 vim_snprintf((char *)IObuff + len, IOSIZE - len, "%ld", | 4612 qf_range_text(qfp, IObuff + len, IOSIZE - len); |
4569 qfp->qf_lnum); | |
4570 len += (int)STRLEN(IObuff + len); | 4613 len += (int)STRLEN(IObuff + len); |
4571 | |
4572 if (qfp->qf_col > 0) | |
4573 { | |
4574 vim_snprintf((char *)IObuff + len, IOSIZE - len, | |
4575 " col %d", qfp->qf_col); | |
4576 len += (int)STRLEN(IObuff + len); | |
4577 } | |
4578 | 4614 |
4579 vim_snprintf((char *)IObuff + len, IOSIZE - len, "%s", | 4615 vim_snprintf((char *)IObuff + len, IOSIZE - len, "%s", |
4580 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); | 4616 (char *)qf_types(qfp->qf_type, qfp->qf_nr)); |
4581 len += (int)STRLEN(IObuff + len); | 4617 len += (int)STRLEN(IObuff + len); |
4582 } | 4618 } |
5951 NULL, | 5987 NULL, |
5952 duplicate_name ? 0 : buf->b_fnum, | 5988 duplicate_name ? 0 : buf->b_fnum, |
5953 ml_get_buf(buf, | 5989 ml_get_buf(buf, |
5954 regmatch->startpos[0].lnum + lnum, FALSE), | 5990 regmatch->startpos[0].lnum + lnum, FALSE), |
5955 regmatch->startpos[0].lnum + lnum, | 5991 regmatch->startpos[0].lnum + lnum, |
5992 regmatch->endpos[0].lnum + lnum, | |
5956 regmatch->startpos[0].col + 1, | 5993 regmatch->startpos[0].col + 1, |
5994 regmatch->endpos[0].col + 1, | |
5957 FALSE, // vis_col | 5995 FALSE, // vis_col |
5958 NULL, // search pattern | 5996 NULL, // search pattern |
5959 0, // nr | 5997 0, // nr |
5960 0, // type | 5998 0, // type |
5961 TRUE // valid | 5999 TRUE // valid |
5994 fname, | 6032 fname, |
5995 NULL, | 6033 NULL, |
5996 duplicate_name ? 0 : buf->b_fnum, | 6034 duplicate_name ? 0 : buf->b_fnum, |
5997 str, | 6035 str, |
5998 lnum, | 6036 lnum, |
6037 0, | |
5999 matches[0] + col + 1, | 6038 matches[0] + col + 1, |
6039 0, | |
6000 FALSE, // vis_col | 6040 FALSE, // vis_col |
6001 NULL, // search pattern | 6041 NULL, // search pattern |
6002 0, // nr | 6042 0, // nr |
6003 0, // type | 6043 0, // type |
6004 TRUE // valid | 6044 TRUE // valid |
6624 return FAIL; | 6664 return FAIL; |
6625 | 6665 |
6626 buf[0] = qfp->qf_type; | 6666 buf[0] = qfp->qf_type; |
6627 buf[1] = NUL; | 6667 buf[1] = NUL; |
6628 if (dict_add_number(dict, "bufnr", (long)bufnum) == FAIL | 6668 if (dict_add_number(dict, "bufnr", (long)bufnum) == FAIL |
6629 || dict_add_number(dict, "lnum", (long)qfp->qf_lnum) == FAIL | 6669 || dict_add_number(dict, "lnum", (long)qfp->qf_lnum) == FAIL |
6630 || dict_add_number(dict, "col", (long)qfp->qf_col) == FAIL | 6670 || dict_add_number(dict, "end_lnum", (long)qfp->qf_end_lnum) == FAIL |
6631 || dict_add_number(dict, "vcol", (long)qfp->qf_viscol) == FAIL | 6671 || dict_add_number(dict, "col", (long)qfp->qf_col) == FAIL |
6632 || dict_add_number(dict, "nr", (long)qfp->qf_nr) == FAIL | 6672 || dict_add_number(dict, "end_col", (long)qfp->qf_end_col) == FAIL |
6673 || dict_add_number(dict, "vcol", (long)qfp->qf_viscol) == FAIL | |
6674 || dict_add_number(dict, "nr", (long)qfp->qf_nr) == FAIL | |
6633 || dict_add_string(dict, "module", qfp->qf_module) == FAIL | 6675 || dict_add_string(dict, "module", qfp->qf_module) == FAIL |
6634 || dict_add_string(dict, "pattern", qfp->qf_pattern) == FAIL | 6676 || dict_add_string(dict, "pattern", qfp->qf_pattern) == FAIL |
6635 || dict_add_string(dict, "text", qfp->qf_text) == FAIL | 6677 || dict_add_string(dict, "text", qfp->qf_text) == FAIL |
6636 || dict_add_string(dict, "type", buf) == FAIL | 6678 || dict_add_string(dict, "type", buf) == FAIL |
6637 || dict_add_number(dict, "valid", (long)qfp->qf_valid) == FAIL) | 6679 || dict_add_number(dict, "valid", (long)qfp->qf_valid) == FAIL) |
7141 int first_entry, | 7183 int first_entry, |
7142 int *valid_entry) | 7184 int *valid_entry) |
7143 { | 7185 { |
7144 static int did_bufnr_emsg; | 7186 static int did_bufnr_emsg; |
7145 char_u *filename, *module, *pattern, *text, *type; | 7187 char_u *filename, *module, *pattern, *text, *type; |
7146 int bufnum, valid, status, col, vcol, nr; | 7188 int bufnum, valid, status, col, end_col, vcol, nr; |
7147 long lnum; | 7189 long lnum, end_lnum; |
7148 | 7190 |
7149 if (first_entry) | 7191 if (first_entry) |
7150 did_bufnr_emsg = FALSE; | 7192 did_bufnr_emsg = FALSE; |
7151 | 7193 |
7152 filename = dict_get_string(d, (char_u *)"filename", TRUE); | 7194 filename = dict_get_string(d, (char_u *)"filename", TRUE); |
7153 module = dict_get_string(d, (char_u *)"module", TRUE); | 7195 module = dict_get_string(d, (char_u *)"module", TRUE); |
7154 bufnum = (int)dict_get_number(d, (char_u *)"bufnr"); | 7196 bufnum = (int)dict_get_number(d, (char_u *)"bufnr"); |
7155 lnum = (int)dict_get_number(d, (char_u *)"lnum"); | 7197 lnum = (int)dict_get_number(d, (char_u *)"lnum"); |
7198 end_lnum = (int)dict_get_number(d, (char_u *)"end_lnum"); | |
7156 col = (int)dict_get_number(d, (char_u *)"col"); | 7199 col = (int)dict_get_number(d, (char_u *)"col"); |
7200 end_col = (int)dict_get_number(d, (char_u *)"end_col"); | |
7157 vcol = (int)dict_get_number(d, (char_u *)"vcol"); | 7201 vcol = (int)dict_get_number(d, (char_u *)"vcol"); |
7158 nr = (int)dict_get_number(d, (char_u *)"nr"); | 7202 nr = (int)dict_get_number(d, (char_u *)"nr"); |
7159 type = dict_get_string(d, (char_u *)"type", TRUE); | 7203 type = dict_get_string(d, (char_u *)"type", TRUE); |
7160 pattern = dict_get_string(d, (char_u *)"pattern", TRUE); | 7204 pattern = dict_get_string(d, (char_u *)"pattern", TRUE); |
7161 text = dict_get_string(d, (char_u *)"text", TRUE); | 7205 text = dict_get_string(d, (char_u *)"text", TRUE); |
7188 filename, | 7232 filename, |
7189 module, | 7233 module, |
7190 bufnum, | 7234 bufnum, |
7191 text, | 7235 text, |
7192 lnum, | 7236 lnum, |
7237 end_lnum, | |
7193 col, | 7238 col, |
7239 end_col, | |
7194 vcol, // vis_col | 7240 vcol, // vis_col |
7195 pattern, // search pattern | 7241 pattern, // search pattern |
7196 nr, | 7242 nr, |
7197 type == NULL ? NUL : *type, | 7243 type == NULL ? NUL : *type, |
7198 valid); | 7244 valid); |
8056 fname, | 8102 fname, |
8057 NULL, | 8103 NULL, |
8058 0, | 8104 0, |
8059 line, | 8105 line, |
8060 lnum, | 8106 lnum, |
8107 0, | |
8061 (int)(p_regmatch->startp[0] - line) | 8108 (int)(p_regmatch->startp[0] - line) |
8062 + 1, // col | 8109 + 1, // col |
8110 (int)(p_regmatch->endp[0] - line) | |
8111 + 1, // end_col | |
8063 FALSE, // vis_col | 8112 FALSE, // vis_col |
8064 NULL, // search pattern | 8113 NULL, // search pattern |
8065 0, // nr | 8114 0, // nr |
8066 1, // type | 8115 1, // type |
8067 TRUE // valid | 8116 TRUE // valid |