comparison src/quickfix.c @ 13026:7c0e0e923537 v8.0.1389

patch 8.0.1389: getqflist() items are missing if not set commit https://github.com/vim/vim/commit/a6d4849c711379b773529afaed640455287ac934 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Dec 12 22:45:31 2017 +0100 patch 8.0.1389: getqflist() items are missing if not set Problem: getqflist() items are missing if not set, that makes it more difficult to handle the values. Solution: When a value is not available return zero or another invalid value. (Yegappan Lakshmanan, closes #2430)
author Christian Brabandt <cb@256bit.org>
date Tue, 12 Dec 2017 23:00:06 +0100
parents e47e70300f30
children b931b2751650
comparison
equal deleted inserted replaced
13025:5f7d269284a3 13026:7c0e0e923537
4861 return qf_get_list_from_lines(what, di, retdict); 4861 return qf_get_list_from_lines(what, di, retdict);
4862 4862
4863 if (wp != NULL) 4863 if (wp != NULL)
4864 qi = GET_LOC_LIST(wp); 4864 qi = GET_LOC_LIST(wp);
4865 4865
4866 /* List is not present or is empty */
4867 if (qi == NULL || qi->qf_listcount == 0)
4868 {
4869 /* If querying for the size of the list, return 0 */
4870 if (((di = dict_find(what, (char_u *)"nr", -1)) != NULL)
4871 && (di->di_tv.v_type == VAR_STRING)
4872 && (STRCMP(di->di_tv.vval.v_string, "$") == 0))
4873 return dict_add_nr_str(retdict, "nr", 0, NULL);
4874 return FAIL;
4875 }
4876
4877 qf_idx = qi->qf_curlist; /* default is the current list */
4878 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL)
4879 {
4880 /* Use the specified quickfix/location list */
4881 if (di->di_tv.v_type == VAR_NUMBER)
4882 {
4883 /* for zero use the current list */
4884 if (di->di_tv.vval.v_number != 0)
4885 {
4886 qf_idx = di->di_tv.vval.v_number - 1;
4887 if (qf_idx < 0 || qf_idx >= qi->qf_listcount)
4888 return FAIL;
4889 }
4890 }
4891 else if ((di->di_tv.v_type == VAR_STRING)
4892 && (STRCMP(di->di_tv.vval.v_string, "$") == 0))
4893 /* Get the last quickfix list number */
4894 qf_idx = qi->qf_listcount - 1;
4895 else
4896 return FAIL;
4897 flags |= QF_GETLIST_NR;
4898 }
4899
4900 if ((di = dict_find(what, (char_u *)"id", -1)) != NULL)
4901 {
4902 /* Look for a list with the specified id */
4903 if (di->di_tv.v_type == VAR_NUMBER)
4904 {
4905 /* For zero, use the current list or the list specifed by 'nr' */
4906 if (di->di_tv.vval.v_number != 0)
4907 {
4908 qf_idx = qf_id2nr(qi, di->di_tv.vval.v_number);
4909 if (qf_idx == -1)
4910 return FAIL; /* List not found */
4911 }
4912 flags |= QF_GETLIST_ID;
4913 }
4914 else
4915 return FAIL;
4916 }
4917
4918 if (dict_find(what, (char_u *)"all", -1) != NULL) 4866 if (dict_find(what, (char_u *)"all", -1) != NULL)
4919 flags |= QF_GETLIST_ALL; 4867 flags |= QF_GETLIST_ALL;
4920 4868
4921 if (dict_find(what, (char_u *)"title", -1) != NULL) 4869 if (dict_find(what, (char_u *)"title", -1) != NULL)
4922 flags |= QF_GETLIST_TITLE; 4870 flags |= QF_GETLIST_TITLE;
4923 4871
4872 if (dict_find(what, (char_u *)"nr", -1) != NULL)
4873 flags |= QF_GETLIST_NR;
4874
4924 if (dict_find(what, (char_u *)"winid", -1) != NULL) 4875 if (dict_find(what, (char_u *)"winid", -1) != NULL)
4925 flags |= QF_GETLIST_WINID; 4876 flags |= QF_GETLIST_WINID;
4926 4877
4927 if (dict_find(what, (char_u *)"context", -1) != NULL) 4878 if (dict_find(what, (char_u *)"context", -1) != NULL)
4928 flags |= QF_GETLIST_CONTEXT; 4879 flags |= QF_GETLIST_CONTEXT;
4929 4880
4881 if (dict_find(what, (char_u *)"id", -1) != NULL)
4882 flags |= QF_GETLIST_ID;
4883
4930 if (dict_find(what, (char_u *)"items", -1) != NULL) 4884 if (dict_find(what, (char_u *)"items", -1) != NULL)
4931 flags |= QF_GETLIST_ITEMS; 4885 flags |= QF_GETLIST_ITEMS;
4932 4886
4933 if (dict_find(what, (char_u *)"idx", -1) != NULL) 4887 if (dict_find(what, (char_u *)"idx", -1) != NULL)
4934 flags |= QF_GETLIST_IDX; 4888 flags |= QF_GETLIST_IDX;
4935 4889
4936 if (dict_find(what, (char_u *)"size", -1) != NULL) 4890 if (dict_find(what, (char_u *)"size", -1) != NULL)
4937 flags |= QF_GETLIST_SIZE; 4891 flags |= QF_GETLIST_SIZE;
4892
4893 if (qi != NULL && qi->qf_listcount != 0)
4894 {
4895 qf_idx = qi->qf_curlist; /* default is the current list */
4896 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL)
4897 {
4898 /* Use the specified quickfix/location list */
4899 if (di->di_tv.v_type == VAR_NUMBER)
4900 {
4901 /* for zero use the current list */
4902 if (di->di_tv.vval.v_number != 0)
4903 {
4904 qf_idx = di->di_tv.vval.v_number - 1;
4905 if (qf_idx < 0 || qf_idx >= qi->qf_listcount)
4906 qf_idx = -1;
4907 }
4908 }
4909 else if ((di->di_tv.v_type == VAR_STRING)
4910 && (STRCMP(di->di_tv.vval.v_string, "$") == 0))
4911 /* Get the last quickfix list number */
4912 qf_idx = qi->qf_listcount - 1;
4913 else
4914 qf_idx = -1;
4915 flags |= QF_GETLIST_NR;
4916 }
4917
4918 if ((di = dict_find(what, (char_u *)"id", -1)) != NULL)
4919 {
4920 /* Look for a list with the specified id */
4921 if (di->di_tv.v_type == VAR_NUMBER)
4922 {
4923 /*
4924 * For zero, use the current list or the list specifed by 'nr'
4925 */
4926 if (di->di_tv.vval.v_number != 0)
4927 qf_idx = qf_id2nr(qi, di->di_tv.vval.v_number);
4928 flags |= QF_GETLIST_ID;
4929 }
4930 else
4931 qf_idx = -1;
4932 }
4933 }
4934
4935 /* List is not present or is empty */
4936 if (qi == NULL || qi->qf_listcount == 0 || qf_idx == -1)
4937 {
4938 if (flags & QF_GETLIST_TITLE)
4939 status = dict_add_nr_str(retdict, "title", 0L, (char_u *)"");
4940 if ((status == OK) && (flags & QF_GETLIST_ITEMS))
4941 {
4942 list_T *l = list_alloc();
4943 if (l != NULL)
4944 status = dict_add_list(retdict, "items", l);
4945 else
4946 status = FAIL;
4947 }
4948 if ((status == OK) && (flags & QF_GETLIST_NR))
4949 status = dict_add_nr_str(retdict, "nr", 0L, NULL);
4950 if ((status == OK) && (flags & QF_GETLIST_WINID))
4951 status = dict_add_nr_str(retdict, "winid", 0L, NULL);
4952 if ((status == OK) && (flags & QF_GETLIST_CONTEXT))
4953 status = dict_add_nr_str(retdict, "context", 0L, (char_u *)"");
4954 if ((status == OK) && (flags & QF_GETLIST_ID))
4955 status = dict_add_nr_str(retdict, "id", 0L, NULL);
4956 if ((status == OK) && (flags & QF_GETLIST_IDX))
4957 status = dict_add_nr_str(retdict, "idx", 0L, NULL);
4958 if ((status == OK) && (flags & QF_GETLIST_SIZE))
4959 status = dict_add_nr_str(retdict, "size", 0L, NULL);
4960
4961 return status;
4962 }
4938 4963
4939 if (flags & QF_GETLIST_TITLE) 4964 if (flags & QF_GETLIST_TITLE)
4940 { 4965 {
4941 char_u *t; 4966 char_u *t;
4942 t = qi->qf_lists[qf_idx].qf_title; 4967 t = qi->qf_lists[qf_idx].qf_title;