comparison src/quickfix.c @ 15042:e95e8b356a65 v8.1.0532

patch 8.1.0532: cannot distinguish between quickfix and location list commit https://github.com/vim/vim/commit/2d67d307ee5dba911e8fbe73193bf596ebf76c1a Author: Bram Moolenaar <Bram@vim.org> Date: Fri Nov 16 18:46:02 2018 +0100 patch 8.1.0532: cannot distinguish between quickfix and location list Problem: Cannot distinguish between quickfix and location list. Solution: Add an explicit type variable. (Yegappan Lakshmanan)
author Bram Moolenaar <Bram@vim.org>
date Fri, 16 Nov 2018 19:00:04 +0100
parents 3a3c9b638187
children 7903dce131d4
comparison
equal deleted inserted replaced
15041:f51dd8405b99 15042:e95e8b356a65
48 */ 48 */
49 #define LISTCOUNT 10 49 #define LISTCOUNT 10
50 #define INVALID_QFIDX (-1) 50 #define INVALID_QFIDX (-1)
51 51
52 /* 52 /*
53 * Quickfix list type.
54 */
55 typedef enum
56 {
57 QFLT_QUICKFIX, // Quickfix list - global list
58 QFLT_LOCATION, // Location list - per window list
59 QFLT_INTERNAL // Internal - Temporary list used by getqflist()/getloclist()
60 } qfltype_T;
61
62 /*
53 * Quickfix/Location list definition 63 * Quickfix/Location list definition
54 * Contains a list of entries (qfline_T). qf_start points to the first entry 64 * Contains a list of entries (qfline_T). qf_start points to the first entry
55 * and qf_last points to the last entry. qf_count contains the list size. 65 * and qf_last points to the last entry. qf_count contains the list size.
56 * 66 *
57 * Usually the list contains one or more entries. But an empty list can be 67 * Usually the list contains one or more entries. But an empty list can be
59 * information and entries can be added later using setqflist()/setloclist(). 69 * information and entries can be added later using setqflist()/setloclist().
60 */ 70 */
61 typedef struct qf_list_S 71 typedef struct qf_list_S
62 { 72 {
63 int_u qf_id; // Unique identifier for this list 73 int_u qf_id; // Unique identifier for this list
74 qfltype_T qfl_type;
64 qfline_T *qf_start; // pointer to the first error 75 qfline_T *qf_start; // pointer to the first error
65 qfline_T *qf_last; // pointer to the last error 76 qfline_T *qf_last; // pointer to the last error
66 qfline_T *qf_ptr; // pointer to the current error 77 qfline_T *qf_ptr; // pointer to the current error
67 int qf_count; // number of errors (0 means empty list) 78 int qf_count; // number of errors (0 means empty list)
68 int qf_index; // current index in the error list 79 int qf_index; // current index in the error list
93 // reaches 0, the list is freed. 104 // reaches 0, the list is freed.
94 int qf_refcount; 105 int qf_refcount;
95 int qf_listcount; // current number of lists 106 int qf_listcount; // current number of lists
96 int qf_curlist; // current error list 107 int qf_curlist; // current error list
97 qf_list_T qf_lists[LISTCOUNT]; 108 qf_list_T qf_lists[LISTCOUNT];
109 qfltype_T qfl_type; // type of list
98 }; 110 };
99 111
100 static qf_info_T ql_info; // global quickfix list 112 static qf_info_T ql_info; // global quickfix list
101 static int_u last_qf_id = 0; // Last used quickfix list id 113 static int_u last_qf_id = 0; // Last used quickfix list id
102 114
168 #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL) 180 #define IS_QF_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref == NULL)
169 // Location list window check helper macro 181 // Location list window check helper macro
170 #define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL) 182 #define IS_LL_WINDOW(wp) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL)
171 183
172 // Quickfix and location list stack check helper macros 184 // Quickfix and location list stack check helper macros
173 #define IS_QF_STACK(qi) (qi == &ql_info) 185 #define IS_QF_STACK(qi) (qi->qfl_type == QFLT_QUICKFIX)
174 #define IS_LL_STACK(qi) (qi != &ql_info) 186 #define IS_LL_STACK(qi) (qi->qfl_type == QFLT_LOCATION)
187 #define IS_QF_LIST(qfl) (qfl->qfl_type == QFLT_QUICKFIX)
188 #define IS_LL_LIST(qfl) (qfl->qfl_type == QFLT_LOCATION)
175 189
176 /* 190 /*
177 * Return location list for window 'wp' 191 * Return location list for window 'wp'
178 * For location list window, return the referenced location list 192 * For location list window, return the referenced location list
179 */ 193 */
1845 else 1859 else
1846 qi->qf_curlist = qi->qf_listcount++; 1860 qi->qf_curlist = qi->qf_listcount++;
1847 qfl = &qi->qf_lists[qi->qf_curlist]; 1861 qfl = &qi->qf_lists[qi->qf_curlist];
1848 vim_memset(qfl, 0, (size_t)(sizeof(qf_list_T))); 1862 vim_memset(qfl, 0, (size_t)(sizeof(qf_list_T)));
1849 qf_store_title(qfl, qf_title); 1863 qf_store_title(qfl, qf_title);
1864 qfl->qfl_type = qi->qfl_type;
1850 qfl->qf_id = ++last_qf_id; 1865 qfl->qf_id = ++last_qf_id;
1851 } 1866 }
1852 1867
1853 /* 1868 /*
1854 * Queue location list stack delete request. 1869 * Queue location list stack delete request.
2005 buf_T *buf = buflist_findnr(bufnum); 2020 buf_T *buf = buflist_findnr(bufnum);
2006 2021
2007 qfp->qf_fnum = bufnum; 2022 qfp->qf_fnum = bufnum;
2008 if (buf != NULL) 2023 if (buf != NULL)
2009 buf->b_has_qf_entry |= 2024 buf->b_has_qf_entry |=
2010 IS_QF_STACK(qi) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY; 2025 IS_QF_LIST(qfl) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY;
2011 } 2026 }
2012 else 2027 else
2013 qfp->qf_fnum = qf_get_fnum(qi, qf_idx, dir, fname); 2028 qfp->qf_fnum = qf_get_fnum(qi, qf_idx, dir, fname);
2014 if ((qfp->qf_text = vim_strsave(mesg)) == NULL) 2029 if ((qfp->qf_text = vim_strsave(mesg)) == NULL)
2015 { 2030 {
2067 2082
2068 return OK; 2083 return OK;
2069 } 2084 }
2070 2085
2071 /* 2086 /*
2072 * Allocate a new location list stack 2087 * Allocate a new quickfix/location list stack
2073 */ 2088 */
2074 static qf_info_T * 2089 static qf_info_T *
2075 ll_new_list(void) 2090 qf_alloc_stack(qfltype_T qfltype)
2076 { 2091 {
2077 qf_info_T *qi; 2092 qf_info_T *qi;
2078 2093
2079 qi = (qf_info_T *)alloc_clear((unsigned)sizeof(qf_info_T)); 2094 qi = (qf_info_T *)alloc_clear((unsigned)sizeof(qf_info_T));
2080 if (qi != NULL) 2095 if (qi != NULL)
2096 {
2081 qi->qf_refcount++; 2097 qi->qf_refcount++;
2098 qi->qfl_type = qfltype;
2099 }
2082 return qi; 2100 return qi;
2083 } 2101 }
2084 2102
2085 /* 2103 /*
2086 * Return the location list stack for window 'wp'. 2104 * Return the location list stack for window 'wp'.
2096 // For a non-location list window, w_llist_ref should not point to a 2114 // For a non-location list window, w_llist_ref should not point to a
2097 // location list. 2115 // location list.
2098 ll_free_all(&wp->w_llist_ref); 2116 ll_free_all(&wp->w_llist_ref);
2099 2117
2100 if (wp->w_llist == NULL) 2118 if (wp->w_llist == NULL)
2101 wp->w_llist = ll_new_list(); // new location list 2119 wp->w_llist = qf_alloc_stack(QFLT_LOCATION); // new location list
2102 return wp->w_llist; 2120 return wp->w_llist;
2103 } 2121 }
2104 2122
2105 /* 2123 /*
2106 * Copy location list entries from 'from_qfl' to 'to_qfl'. 2124 * Copy location list entries from 'from_qfl' to 'to_qfl'.
2151 */ 2169 */
2152 static int 2170 static int
2153 copy_loclist(qf_list_T *from_qfl, qf_list_T *to_qfl, qf_info_T *to_qi) 2171 copy_loclist(qf_list_T *from_qfl, qf_list_T *to_qfl, qf_info_T *to_qi)
2154 { 2172 {
2155 // Some of the fields are populated by qf_add_entry() 2173 // Some of the fields are populated by qf_add_entry()
2174 to_qfl->qfl_type = from_qfl->qfl_type;
2156 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid; 2175 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid;
2157 to_qfl->qf_count = 0; 2176 to_qfl->qf_count = 0;
2158 to_qfl->qf_index = 0; 2177 to_qfl->qf_index = 0;
2159 to_qfl->qf_start = NULL; 2178 to_qfl->qf_start = NULL;
2160 to_qfl->qf_last = NULL; 2179 to_qfl->qf_last = NULL;
2212 2231
2213 if (qi == NULL) // no location list to copy 2232 if (qi == NULL) // no location list to copy
2214 return; 2233 return;
2215 2234
2216 // allocate a new location list 2235 // allocate a new location list
2217 if ((to->w_llist = ll_new_list()) == NULL) 2236 if ((to->w_llist = qf_alloc_stack(QFLT_LOCATION)) == NULL)
2218 return; 2237 return;
2219 2238
2220 to->w_llist->qf_listcount = qi->qf_listcount; 2239 to->w_llist->qf_listcount = qi->qf_listcount;
2221 2240
2222 // Copy the location lists one at a time 2241 // Copy the location lists one at a time
2298 } 2317 }
2299 if (buf == NULL) 2318 if (buf == NULL)
2300 return 0; 2319 return 0;
2301 2320
2302 buf->b_has_qf_entry = 2321 buf->b_has_qf_entry =
2303 IS_QF_STACK(qi) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY; 2322 IS_QF_LIST(qfl) ? BUF_HAS_QF_ENTRY : BUF_HAS_LL_ENTRY;
2304 return buf->b_fnum; 2323 return buf->b_fnum;
2305 } 2324 }
2306 2325
2307 /* 2326 /*
2308 * Push dirbuf onto the directory stack and return pointer to actual dir or 2327 * Push dirbuf onto the directory stack and return pointer to actual dir or
2993 int forceit, 3012 int forceit,
2994 win_T *oldwin, 3013 win_T *oldwin,
2995 int *opened_window) 3014 int *opened_window)
2996 { 3015 {
2997 qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist]; 3016 qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist];
3017 qfltype_T qfl_type = qfl->qfl_type;
2998 int retval = OK; 3018 int retval = OK;
2999 int old_qf_curlist = qi->qf_curlist; 3019 int old_qf_curlist = qi->qf_curlist;
3000 int save_qfid = qfl->qf_id; 3020 int save_qfid = qfl->qf_id;
3001 3021
3002 if (qf_ptr->qf_type == 1) 3022 if (qf_ptr->qf_type == 1)
3017 retval = buflist_getfile(qf_ptr->qf_fnum, 3037 retval = buflist_getfile(qf_ptr->qf_fnum,
3018 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit); 3038 (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit);
3019 3039
3020 // If a location list, check whether the associated window is still 3040 // If a location list, check whether the associated window is still
3021 // present. 3041 // present.
3022 if (IS_LL_STACK(qi) && !win_valid_any_tab(oldwin)) 3042 if (qfl_type == QFLT_LOCATION && !win_valid_any_tab(oldwin))
3023 { 3043 {
3024 EMSG(_("E924: Current window was closed")); 3044 EMSG(_("E924: Current window was closed"));
3025 *opened_window = FALSE; 3045 *opened_window = FALSE;
3026 return NOTDONE; 3046 return NOTDONE;
3027 } 3047 }
3028 3048
3029 if (IS_QF_STACK(qi) && !qflist_valid(NULL, save_qfid)) 3049 if (qfl_type == QFLT_QUICKFIX && !qflist_valid(NULL, save_qfid))
3030 { 3050 {
3031 EMSG(_("E925: Current quickfix was changed")); 3051 EMSG(_("E925: Current quickfix was changed"));
3032 return NOTDONE; 3052 return NOTDONE;
3033 } 3053 }
3034 3054
3035 if (old_qf_curlist != qi->qf_curlist 3055 if (old_qf_curlist != qi->qf_curlist
3036 || !is_qf_entry_present(qfl, qf_ptr)) 3056 || !is_qf_entry_present(qfl, qf_ptr))
3037 { 3057 {
3038 if (IS_QF_STACK(qi)) 3058 if (qfl_type == QFLT_QUICKFIX)
3039 EMSG(_("E925: Current quickfix was changed")); 3059 EMSG(_("E925: Current quickfix was changed"));
3040 else 3060 else
3041 EMSG(_(e_loc_list_changed)); 3061 EMSG(_(e_loc_list_changed));
3042 return NOTDONE; 3062 return NOTDONE;
3043 } 3063 }
5894 5914
5895 l = list_alloc(); 5915 l = list_alloc();
5896 if (l == NULL) 5916 if (l == NULL)
5897 return FAIL; 5917 return FAIL;
5898 5918
5899 qi = ll_new_list(); 5919 qi = qf_alloc_stack(QFLT_INTERNAL);
5900 if (qi != NULL) 5920 if (qi != NULL)
5901 { 5921 {
5902 if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat, 5922 if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat,
5903 TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) 5923 TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0)
5904 { 5924 {
6038 6058
6039 /* 6059 /*
6040 * Return default values for quickfix list properties in retdict. 6060 * Return default values for quickfix list properties in retdict.
6041 */ 6061 */
6042 static int 6062 static int
6043 qf_getprop_defaults(qf_info_T *qi, int flags, dict_T *retdict) 6063 qf_getprop_defaults(qf_info_T *qi, int flags, int locstack, dict_T *retdict)
6044 { 6064 {
6045 int status = OK; 6065 int status = OK;
6046 6066
6047 if (flags & QF_GETLIST_TITLE) 6067 if (flags & QF_GETLIST_TITLE)
6048 status = dict_add_string(retdict, "title", (char_u *)""); 6068 status = dict_add_string(retdict, "title", (char_u *)"");
6066 status = dict_add_number(retdict, "idx", 0); 6086 status = dict_add_number(retdict, "idx", 0);
6067 if ((status == OK) && (flags & QF_GETLIST_SIZE)) 6087 if ((status == OK) && (flags & QF_GETLIST_SIZE))
6068 status = dict_add_number(retdict, "size", 0); 6088 status = dict_add_number(retdict, "size", 0);
6069 if ((status == OK) && (flags & QF_GETLIST_TICK)) 6089 if ((status == OK) && (flags & QF_GETLIST_TICK))
6070 status = dict_add_number(retdict, "changedtick", 0); 6090 status = dict_add_number(retdict, "changedtick", 0);
6071 if ((status == OK) && IS_LL_STACK(qi) && (flags & QF_GETLIST_FILEWINID)) 6091 if ((status == OK) && locstack && (flags & QF_GETLIST_FILEWINID))
6072 status = dict_add_number(retdict, "filewinid", 0); 6092 status = dict_add_number(retdict, "filewinid", 0);
6073 6093
6074 return status; 6094 return status;
6075 } 6095 }
6076 6096
6189 if (!qf_stack_empty(qi)) 6209 if (!qf_stack_empty(qi))
6190 qf_idx = qf_getprop_qfidx(qi, what); 6210 qf_idx = qf_getprop_qfidx(qi, what);
6191 6211
6192 // List is not present or is empty 6212 // List is not present or is empty
6193 if (qf_stack_empty(qi) || qf_idx == INVALID_QFIDX) 6213 if (qf_stack_empty(qi) || qf_idx == INVALID_QFIDX)
6194 return qf_getprop_defaults(qi, flags, retdict); 6214 return qf_getprop_defaults(qi, flags, wp != NULL, retdict);
6195 6215
6196 qfl = &qi->qf_lists[qf_idx]; 6216 qfl = &qi->qf_lists[qf_idx];
6197 6217
6198 if (flags & QF_GETLIST_TITLE) 6218 if (flags & QF_GETLIST_TITLE)
6199 status = qf_getprop_title(qfl, retdict); 6219 status = qf_getprop_title(qfl, retdict);
6614 } 6634 }
6615 else if (IS_LL_WINDOW(orig_wp)) 6635 else if (IS_LL_WINDOW(orig_wp))
6616 { 6636 {
6617 // If the location list window is open, then create a new empty 6637 // If the location list window is open, then create a new empty
6618 // location list 6638 // location list
6619 qf_info_T *new_ll = ll_new_list(); 6639 qf_info_T *new_ll = qf_alloc_stack(QFLT_LOCATION);
6620 6640
6621 // first free the list reference in the location list window 6641 // first free the list reference in the location list window
6622 ll_free_all(&orig_wp->w_llist_ref); 6642 ll_free_all(&orig_wp->w_llist_ref);
6623 6643
6624 orig_wp->w_llist_ref = new_ll; 6644 orig_wp->w_llist_ref = new_ll;
6962 qi = wp->w_llist; 6982 qi = wp->w_llist;
6963 6983
6964 if (qi == NULL) 6984 if (qi == NULL)
6965 { 6985 {
6966 // Allocate a new location list for help text matches 6986 // Allocate a new location list for help text matches
6967 if ((qi = ll_new_list()) == NULL) 6987 if ((qi = qf_alloc_stack(QFLT_LOCATION)) == NULL)
6968 return NULL; 6988 return NULL;
6969 *new_ll = TRUE; 6989 *new_ll = TRUE;
6970 } 6990 }
6971 6991
6972 return qi; 6992 return qi;