aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/quickfix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/quickfix.c')
-rw-r--r--src/nvim/quickfix.c159
1 files changed, 60 insertions, 99 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index e022184f2f..ddf2a7247f 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -20,6 +20,7 @@
#include "nvim/cursor.h"
#include "nvim/drawscreen.h"
#include "nvim/edit.h"
+#include "nvim/errors.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/window.h"
@@ -90,6 +91,7 @@ struct qfline_S {
int qf_end_col; ///< column when the error has range or zero
int qf_nr; ///< error number
char *qf_module; ///< module name for this error
+ char *qf_fname; ///< different filename if there're hard links
char *qf_pattern; ///< search pattern for the error
char *qf_text; ///< description of the error
char qf_viscol; ///< set to true if qf_col and qf_end_col is screen column
@@ -381,11 +383,7 @@ static int qf_init_process_nextline(qf_list_T *qfl, efm_T *fmt_first, qfstate_T
int qf_init(win_T *wp, const char *restrict efile, char *restrict errorformat, int newlist,
const char *restrict qf_title, char *restrict enc)
{
- qf_info_T *qi = &ql_info;
-
- if (wp != NULL) {
- qi = ll_get_or_alloc_list(wp);
- }
+ qf_info_T *qi = wp == NULL ? &ql_info : ll_get_or_alloc_list(wp);
return qf_init_ext(qi, qi->qf_curlist, efile, curbuf, NULL, errorformat,
newlist, 0, 0, qf_title, enc);
@@ -723,7 +721,7 @@ static int qf_get_next_str_line(qfstate_T *state)
state->linelen = len;
}
memcpy(state->linebuf, p_str, state->linelen);
- state->linebuf[state->linelen] = '\0';
+ state->linebuf[state->linelen] = NUL;
// Increment using len in order to discard the rest of the line if it
// exceeds LINE_MAXLEN.
@@ -833,8 +831,7 @@ retry:
break;
}
- state->growbufsiz = (2 * state->growbufsiz < LINE_MAXLEN)
- ? 2 * state->growbufsiz : LINE_MAXLEN;
+ state->growbufsiz = MIN(2 * state->growbufsiz, LINE_MAXLEN);
state->growbuf = xrealloc(state->growbuf, state->growbufsiz);
}
@@ -870,8 +867,7 @@ retry:
xfree(state->growbuf);
state->linebuf = line;
state->growbuf = line;
- state->growbufsiz = state->linelen < LINE_MAXLEN
- ? state->linelen : LINE_MAXLEN;
+ state->growbufsiz = MIN(state->linelen, LINE_MAXLEN);
}
}
}
@@ -1151,14 +1147,10 @@ static int qf_init_ext(qf_info_T *qi, int qf_idx, const char *restrict efile, bu
}
}
- char *efm;
-
// Use the local value of 'errorformat' if it's set.
- if (errorformat == p_efm && tv == NULL && buf && *buf->b_p_efm != NUL) {
- efm = buf->b_p_efm;
- } else {
- efm = errorformat;
- }
+ char *efm = (errorformat == p_efm && tv == NULL && buf && *buf->b_p_efm != NUL)
+ ? buf->b_p_efm
+ : errorformat;
// If the errorformat didn't change between calls, then reuse the previously
// parsed values.
@@ -1490,9 +1482,7 @@ static int qf_parse_fmt_s(regmatch_T *rmp, int midx, qffields_T *fields)
return QF_FAIL;
}
size_t len = (size_t)(rmp->endp[midx] - rmp->startp[midx]);
- if (len > CMDBUFFSIZE - 5) {
- len = CMDBUFFSIZE - 5;
- }
+ len = MIN(len, CMDBUFFSIZE - 5);
STRCPY(fields->pattern, "^\\V");
xstrlcat(fields->pattern, rmp->startp[midx], len + 4);
fields->pattern[len + 3] = '\\';
@@ -1510,9 +1500,7 @@ static int qf_parse_fmt_o(regmatch_T *rmp, int midx, qffields_T *fields)
}
size_t len = (size_t)(rmp->endp[midx] - rmp->startp[midx]);
size_t dsize = strlen(fields->module) + len + 1;
- if (dsize > CMDBUFFSIZE) {
- dsize = CMDBUFFSIZE;
- }
+ dsize = MIN(dsize, CMDBUFFSIZE);
xstrlcat(fields->module, rmp->startp[midx], dsize);
return QF_OK;
}
@@ -1879,11 +1867,13 @@ static int qf_add_entry(qf_list_T *qfl, char *dir, char *fname, char *module, in
char vis_col, char *pattern, int nr, char type, typval_T *user_data,
char valid)
{
+ buf_T *buf;
qfline_T *qfp = xmalloc(sizeof(qfline_T));
+ char *fullname = NULL;
+ char *p = NULL;
if (bufnum != 0) {
- buf_T *buf = buflist_findnr(bufnum);
-
+ buf = buflist_findnr(bufnum);
qfp->qf_fnum = bufnum;
if (buf != NULL) {
buf->b_has_qf_entry |=
@@ -1891,7 +1881,21 @@ static int qf_add_entry(qf_list_T *qfl, char *dir, char *fname, char *module, in
}
} else {
qfp->qf_fnum = qf_get_fnum(qfl, dir, fname);
+ buf = buflist_findnr(qfp->qf_fnum);
+ }
+ if (fname != NULL) {
+ fullname = fix_fname(fname);
+ }
+ qfp->qf_fname = NULL;
+ if (buf != NULL && buf->b_ffname != NULL && fullname != NULL) {
+ if (path_fnamecmp(fullname, buf->b_ffname) != 0) {
+ p = path_try_shorten_fname(fullname);
+ if (p != NULL) {
+ qfp->qf_fname = xstrdup(p);
+ }
+ }
}
+ xfree(fullname);
qfp->qf_text = xstrdup(mesg);
qfp->qf_lnum = lnum;
qfp->qf_end_lnum = end_lnum;
@@ -2526,13 +2530,7 @@ static void win_set_loclist(win_T *wp, qf_info_T *qi)
/// window.
static int jump_to_help_window(qf_info_T *qi, bool newwin, bool *opened_window)
{
- win_T *wp = NULL;
-
- if (cmdmod.cmod_tab != 0 || newwin) {
- wp = NULL;
- } else {
- wp = qf_find_help_win();
- }
+ win_T *wp = (cmdmod.cmod_tab != 0 || newwin) ? NULL : qf_find_help_win();
if (wp != NULL && wp->w_buffer->b_nwindows > 0) {
win_enter(wp, true);
@@ -2881,9 +2879,7 @@ static void qf_jump_goto_line(linenr_T qf_lnum, int qf_col, char qf_viscol, char
// Go to line with error, unless qf_lnum is 0.
linenr_T i = qf_lnum;
if (i > 0) {
- if (i > curbuf->b_ml.ml_line_count) {
- i = curbuf->b_ml.ml_line_count;
- }
+ i = MIN(i, curbuf->b_ml.ml_line_count);
curwin->w_cursor.lnum = i;
}
if (qf_col > 0) {
@@ -2914,8 +2910,7 @@ static void qf_jump_print_msg(qf_info_T *qi, int qf_index, qfline_T *qf_ptr, buf
{
garray_T *const gap = qfga_get();
- // Update the screen before showing the message, unless the screen
- // scrolled up.
+ // Update the screen before showing the message, unless messages scrolled.
if (!msg_scrolled) {
update_topline(curwin);
if (must_redraw) {
@@ -2937,7 +2932,8 @@ static void qf_jump_print_msg(qf_info_T *qi, int qf_index, qfline_T *qf_ptr, buf
linenr_T i = msg_scroll;
if (curbuf == old_curbuf && curwin->w_cursor.lnum == old_lnum) {
msg_scroll = true;
- } else if (!msg_scrolled && shortmess(SHM_OVERALL)) {
+ } else if ((msg_scrolled == 0 || (p_ch == 0 && msg_scrolled == 1))
+ && shortmess(SHM_OVERALL)) {
msg_scroll = false;
}
msg_ext_set_kind("quickfix");
@@ -3166,7 +3162,7 @@ static void qf_list_entry(qfline_T *qfp, int qf_idx, bool cursel)
buf_T *buf;
if (qfp->qf_fnum != 0
&& (buf = buflist_findnr(qfp->qf_fnum)) != NULL) {
- fname = buf->b_fname;
+ fname = qfp->qf_fname == NULL ? buf->b_fname : qfp->qf_fname;
if (qfp->qf_type == 1) { // :helpgrep
fname = path_tail(fname);
}
@@ -3452,6 +3448,7 @@ static void qf_free_items(qf_list_T *qfl)
qfline_T *qfp = qfl->qf_start;
qfline_T *qfpnext = qfp->qf_next;
if (!stop) {
+ xfree(qfp->qf_fname);
xfree(qfp->qf_module);
xfree(qfp->qf_text);
xfree(qfp->qf_pattern);
@@ -3897,13 +3894,8 @@ static bool qf_win_pos_update(qf_info_T *qi, int old_qf_index)
if (win != NULL
&& qf_index <= win->w_buffer->b_ml.ml_line_count
&& old_qf_index != qf_index) {
- if (qf_index > old_qf_index) {
- win->w_redraw_top = old_qf_index;
- win->w_redraw_bot = qf_index;
- } else {
- win->w_redraw_top = qf_index;
- win->w_redraw_bot = old_qf_index;
- }
+ win->w_redraw_top = MIN(old_qf_index, qf_index);
+ win->w_redraw_bot = MAX(old_qf_index, qf_index);
qf_win_goto(win, qf_index);
}
return win != NULL;
@@ -4085,7 +4077,7 @@ static int qf_buf_add_line(qf_list_T *qfl, buf_T *buf, linenr_T lnum, const qfli
}
shorten_buf_fname(errbuf, dirname, false);
}
- ga_concat(gap, errbuf->b_fname);
+ ga_concat(gap, qfp->qf_fname == NULL ? errbuf->b_fname : qfp->qf_fname);
}
}
@@ -4219,11 +4211,7 @@ static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int q
qfp = qfl->qf_start;
lnum = 0;
} else {
- if (old_last->qf_next != NULL) {
- qfp = old_last->qf_next;
- } else {
- qfp = old_last;
- }
+ qfp = old_last->qf_next != NULL ? old_last->qf_next : old_last;
lnum = buf->b_ml.ml_line_count;
}
@@ -4450,15 +4438,11 @@ void ex_make(exarg_T *eap)
incr_quickfix_busy();
- char *errorformat = p_efm;
- bool newlist = true;
+ char *errorformat = (eap->cmdidx != CMD_make && eap->cmdidx != CMD_lmake)
+ ? p_gefm
+ : p_efm;
- if (eap->cmdidx != CMD_make && eap->cmdidx != CMD_lmake) {
- errorformat = p_gefm;
- }
- if (eap->cmdidx == CMD_grepadd || eap->cmdidx == CMD_lgrepadd) {
- newlist = false;
- }
+ bool newlist = eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd;
int res = qf_init(wp, fname, errorformat, newlist, qf_cmdtitle(*eap->cmdlinep), enc);
@@ -4530,7 +4514,7 @@ static char *get_mef_name(void)
name = xmalloc(strlen(p_mef) + 30);
STRCPY(name, p_mef);
snprintf(name + (p - p_mef), strlen(name), "%d%d", start, off);
- STRCAT(name, p + 2);
+ strcat(name, p + 2);
// Don't accept a symbolic link, it's a security risk.
FileInfo file_info;
bool file_or_link_found = os_fileinfo_link(name, &file_info);
@@ -5322,9 +5306,7 @@ static bool vgr_match_buflines(qf_list_T *qfl, char *fname, buf_T *buf, char *sp
{
bool found_match = false;
size_t pat_len = strlen(spat);
- if (pat_len > MAX_FUZZY_MATCHES) {
- pat_len = MAX_FUZZY_MATCHES;
- }
+ pat_len = MIN(pat_len, MAX_FUZZY_MATCHES);
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count && *tomatch > 0; lnum++) {
colnr_T col = 0;
@@ -5466,12 +5448,7 @@ static int vgr_process_args(exarg_T *eap, vgr_args_T *args)
args->regmatch.regprog = NULL;
args->qf_title = xstrdup(qf_cmdtitle(*eap->cmdlinep));
-
- if (eap->addr_count > 0) {
- args->tomatch = eap->line2;
- } else {
- args->tomatch = MAXLNUM;
- }
+ args->tomatch = eap->addr_count > 0 ? eap->line2 : MAXLNUM;
// Get the search pattern: either white-separated or enclosed in //
char *p = skip_vimgrep_pat(eap->arg, &args->spat, &args->flags);
@@ -6701,9 +6678,7 @@ static int qf_setprop_curidx(qf_info_T *qi, qf_list_T *qfl, const dictitem_T *di
if (newidx < 1) { // sanity check
return FAIL;
}
- if (newidx > qfl->qf_count) {
- newidx = qfl->qf_count;
- }
+ newidx = MIN(newidx, qfl->qf_count);
const int old_qfidx = qfl->qf_index;
qfline_T *const qf_ptr = get_nth_entry(qfl, newidx, &newidx);
if (qf_ptr == NULL) {
@@ -6900,31 +6875,17 @@ static bool mark_quickfix_ctx(qf_info_T *qi, int copyID)
/// "in use". So that garbage collection doesn't free the context.
bool set_ref_in_quickfix(int copyID)
{
- bool abort = mark_quickfix_ctx(&ql_info, copyID);
- if (abort) {
- return abort;
- }
-
- abort = mark_quickfix_user_data(&ql_info, copyID);
- if (abort) {
- return abort;
- }
-
- abort = set_ref_in_callback(&qftf_cb, copyID, NULL, NULL);
- if (abort) {
- return abort;
+ if (mark_quickfix_ctx(&ql_info, copyID)
+ || mark_quickfix_user_data(&ql_info, copyID)
+ || set_ref_in_callback(&qftf_cb, copyID, NULL, NULL)) {
+ return true;
}
FOR_ALL_TAB_WINDOWS(tp, win) {
if (win->w_llist != NULL) {
- abort = mark_quickfix_ctx(win->w_llist, copyID);
- if (abort) {
- return abort;
- }
-
- abort = mark_quickfix_user_data(win->w_llist, copyID);
- if (abort) {
- return abort;
+ if (mark_quickfix_ctx(win->w_llist, copyID)
+ || mark_quickfix_user_data(win->w_llist, copyID)) {
+ return true;
}
}
@@ -6932,14 +6893,14 @@ bool set_ref_in_quickfix(int copyID)
// In a location list window and none of the other windows is
// referring to this location list. Mark the location list
// context as still in use.
- abort = mark_quickfix_ctx(win->w_llist_ref, copyID);
- if (abort) {
- return abort;
+ if (mark_quickfix_ctx(win->w_llist_ref, copyID)
+ || mark_quickfix_user_data(win->w_llist_ref, copyID)) {
+ return true;
}
}
}
- return abort;
+ return false;
}
/// Return the autocmd name for the :cbuffer Ex commands
@@ -7236,7 +7197,7 @@ static void hgr_search_files_in_dir(qf_list_T *qfl, char *dirname, regmatch_T *p
// Find all "*.txt" and "*.??x" files in the "doc" directory.
add_pathsep(dirname);
- STRCAT(dirname, "doc/*.\\(txt\\|??x\\)"); // NOLINT
+ strcat(dirname, "doc/*.\\(txt\\|??x\\)"); // NOLINT
if (gen_expand_wildcards(1, &dirname, &fcount, &fnames, EW_FILE|EW_SILENT) == OK
&& fcount > 0) {
for (int fi = 0; fi < fcount && !got_int; fi++) {