comparison src/quickfix.c @ 12287:20641a7e1fc9 v8.0.1023

patch 8.0.1023: it is not easy to identify a quickfix list commit https://github.com/vim/vim/commit/a539f4f1ae4a2b3a7dfce89cd3800214c9e990cf Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 30 20:33:55 2017 +0200 patch 8.0.1023: it is not easy to identify a quickfix list Problem: It is not easy to identify a quickfix list. Solution: Add the "id" field. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Wed, 30 Aug 2017 20:45:03 +0200
parents 3d0e042ec13c
children f4d00472e617
comparison
equal deleted inserted replaced
12286:27efa3b025f4 12287:20641a7e1fc9
56 * created using setqflist()/setloclist() with a title and/or user context 56 * created using setqflist()/setloclist() with a title and/or user context
57 * information and entries can be added later using setqflist()/setloclist(). 57 * information and entries can be added later using setqflist()/setloclist().
58 */ 58 */
59 typedef struct qf_list_S 59 typedef struct qf_list_S
60 { 60 {
61 int_u qf_id; /* Unique identifier for this list */
61 qfline_T *qf_start; /* pointer to the first error */ 62 qfline_T *qf_start; /* pointer to the first error */
62 qfline_T *qf_last; /* pointer to the last error */ 63 qfline_T *qf_last; /* pointer to the last error */
63 qfline_T *qf_ptr; /* pointer to the current error */ 64 qfline_T *qf_ptr; /* pointer to the current error */
64 int qf_count; /* number of errors (0 means empty list) */ 65 int qf_count; /* number of errors (0 means empty list) */
65 int qf_index; /* current index in the error list */ 66 int qf_index; /* current index in the error list */
94 int qf_curlist; /* current error list */ 95 int qf_curlist; /* current error list */
95 qf_list_T qf_lists[LISTCOUNT]; 96 qf_list_T qf_lists[LISTCOUNT];
96 }; 97 };
97 98
98 static qf_info_T ql_info; /* global quickfix list */ 99 static qf_info_T ql_info; /* global quickfix list */
100 static int_u last_qf_id = 0; /* Last used quickfix list id */
99 101
100 #define FMT_PATTERNS 10 /* maximum number of % recognized */ 102 #define FMT_PATTERNS 10 /* maximum number of % recognized */
101 103
102 /* 104 /*
103 * Structure used to hold the info of one part of 'errorformat' 105 * Structure used to hold the info of one part of 'errorformat'
1397 } 1399 }
1398 else 1400 else
1399 qi->qf_curlist = qi->qf_listcount++; 1401 qi->qf_curlist = qi->qf_listcount++;
1400 vim_memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T))); 1402 vim_memset(&qi->qf_lists[qi->qf_curlist], 0, (size_t)(sizeof(qf_list_T)));
1401 qf_store_title(qi, qi->qf_curlist, qf_title); 1403 qf_store_title(qi, qi->qf_curlist, qf_title);
1404 qi->qf_lists[qi->qf_curlist].qf_id = ++last_qf_id;
1402 } 1405 }
1403 1406
1404 /* 1407 /*
1405 * Free a location list 1408 * Free a location list
1406 */ 1409 */
1670 } 1673 }
1671 } 1674 }
1672 1675
1673 to_qfl->qf_index = from_qfl->qf_index; /* current index in the list */ 1676 to_qfl->qf_index = from_qfl->qf_index; /* current index in the list */
1674 1677
1678 /* Assign a new ID for the location list */
1679 to_qfl->qf_id = ++last_qf_id;
1680
1675 /* When no valid entries are present in the list, qf_ptr points to 1681 /* When no valid entries are present in the list, qf_ptr points to
1676 * the first item in the list */ 1682 * the first item in the list */
1677 if (to_qfl->qf_nonevalid) 1683 if (to_qfl->qf_nonevalid)
1678 { 1684 {
1679 to_qfl->qf_ptr = to_qfl->qf_start; 1685 to_qfl->qf_ptr = to_qfl->qf_start;
2806 2812
2807 vim_free(qfl->qf_title); 2813 vim_free(qfl->qf_title);
2808 qfl->qf_title = NULL; 2814 qfl->qf_title = NULL;
2809 free_tv(qfl->qf_ctx); 2815 free_tv(qfl->qf_ctx);
2810 qfl->qf_ctx = NULL; 2816 qfl->qf_ctx = NULL;
2817 qfl->qf_id = 0;
2811 } 2818 }
2812 2819
2813 /* 2820 /*
2814 * qf_mark_adjust: adjust marks 2821 * qf_mark_adjust: adjust marks
2815 */ 2822 */
4626 QF_GETLIST_TITLE = 0x1, 4633 QF_GETLIST_TITLE = 0x1,
4627 QF_GETLIST_ITEMS = 0x2, 4634 QF_GETLIST_ITEMS = 0x2,
4628 QF_GETLIST_NR = 0x4, 4635 QF_GETLIST_NR = 0x4,
4629 QF_GETLIST_WINID = 0x8, 4636 QF_GETLIST_WINID = 0x8,
4630 QF_GETLIST_CONTEXT = 0x10, 4637 QF_GETLIST_CONTEXT = 0x10,
4638 QF_GETLIST_ID = 0x20,
4631 QF_GETLIST_ALL = 0xFF 4639 QF_GETLIST_ALL = 0xFF
4632 }; 4640 };
4633 4641
4634 /* 4642 /*
4635 * Parse text from 'di' and return the quickfix list items 4643 * Parse text from 'di' and return the quickfix list items
4686 4694
4687 if ((di = dict_find(what, (char_u *)"text", -1)) != NULL) 4695 if ((di = dict_find(what, (char_u *)"text", -1)) != NULL)
4688 return qf_get_list_from_text(di, retdict); 4696 return qf_get_list_from_text(di, retdict);
4689 4697
4690 if (wp != NULL) 4698 if (wp != NULL)
4691 {
4692 qi = GET_LOC_LIST(wp); 4699 qi = GET_LOC_LIST(wp);
4693 if (qi == NULL) 4700
4694 { 4701 /* List is not present or is empty */
4695 /* If querying for the size of the location list, return 0 */ 4702 if (qi == NULL || qi->qf_listcount == 0)
4696 if (((di = dict_find(what, (char_u *)"nr", -1)) != NULL) 4703 {
4697 && (di->di_tv.v_type == VAR_STRING) 4704 /* If querying for the size of the list, return 0 */
4698 && (STRCMP(di->di_tv.vval.v_string, "$") == 0)) 4705 if (((di = dict_find(what, (char_u *)"nr", -1)) != NULL)
4699 return dict_add_nr_str(retdict, "nr", 0, NULL); 4706 && (di->di_tv.v_type == VAR_STRING)
4700 return FAIL; 4707 && (STRCMP(di->di_tv.vval.v_string, "$") == 0))
4701 } 4708 return dict_add_nr_str(retdict, "nr", 0, NULL);
4709 return FAIL;
4702 } 4710 }
4703 4711
4704 qf_idx = qi->qf_curlist; /* default is the current list */ 4712 qf_idx = qi->qf_curlist; /* default is the current list */
4705 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL) 4713 if ((di = dict_find(what, (char_u *)"nr", -1)) != NULL)
4706 { 4714 {
4712 { 4720 {
4713 qf_idx = di->di_tv.vval.v_number - 1; 4721 qf_idx = di->di_tv.vval.v_number - 1;
4714 if (qf_idx < 0 || qf_idx >= qi->qf_listcount) 4722 if (qf_idx < 0 || qf_idx >= qi->qf_listcount)
4715 return FAIL; 4723 return FAIL;
4716 } 4724 }
4717 else if (qi->qf_listcount == 0) /* stack is empty */
4718 return FAIL;
4719 flags |= QF_GETLIST_NR;
4720 } 4725 }
4721 else if ((di->di_tv.v_type == VAR_STRING) 4726 else if ((di->di_tv.v_type == VAR_STRING)
4722 && (STRCMP(di->di_tv.vval.v_string, "$") == 0)) 4727 && (STRCMP(di->di_tv.vval.v_string, "$") == 0))
4723 {
4724 /* Get the last quickfix list number */ 4728 /* Get the last quickfix list number */
4725 if (qi->qf_listcount > 0) 4729 qf_idx = qi->qf_listcount - 1;
4726 qf_idx = qi->qf_listcount - 1;
4727 else
4728 qf_idx = -1; /* Quickfix stack is empty */
4729 flags |= QF_GETLIST_NR;
4730 }
4731 else 4730 else
4732 return FAIL; 4731 return FAIL;
4733 } 4732 flags |= QF_GETLIST_NR;
4734 4733 }
4735 if (qf_idx != -1) 4734
4736 { 4735 if ((di = dict_find(what, (char_u *)"id", -1)) != NULL)
4737 if (dict_find(what, (char_u *)"all", -1) != NULL) 4736 {
4738 flags |= QF_GETLIST_ALL; 4737 /* Look for a list with the specified id */
4739 4738 if (di->di_tv.v_type == VAR_NUMBER)
4740 if (dict_find(what, (char_u *)"title", -1) != NULL) 4739 {
4741 flags |= QF_GETLIST_TITLE; 4740 /* For zero, use the current list or the list specifed by 'nr' */
4742 4741 if (di->di_tv.vval.v_number != 0)
4743 if (dict_find(what, (char_u *)"winid", -1) != NULL) 4742 {
4744 flags |= QF_GETLIST_WINID; 4743 for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++)
4745 4744 {
4746 if (dict_find(what, (char_u *)"context", -1) != NULL) 4745 if (qi->qf_lists[qf_idx].qf_id == di->di_tv.vval.v_number)
4747 flags |= QF_GETLIST_CONTEXT; 4746 break;
4748 4747 }
4749 if (dict_find(what, (char_u *)"items", -1) != NULL) 4748 if (qf_idx == qi->qf_listcount)
4750 flags |= QF_GETLIST_ITEMS; 4749 return FAIL; /* List not found */
4751 } 4750 }
4751 flags |= QF_GETLIST_ID;
4752 }
4753 else
4754 return FAIL;
4755 }
4756
4757 if (dict_find(what, (char_u *)"all", -1) != NULL)
4758 flags |= QF_GETLIST_ALL;
4759
4760 if (dict_find(what, (char_u *)"title", -1) != NULL)
4761 flags |= QF_GETLIST_TITLE;
4762
4763 if (dict_find(what, (char_u *)"winid", -1) != NULL)
4764 flags |= QF_GETLIST_WINID;
4765
4766 if (dict_find(what, (char_u *)"context", -1) != NULL)
4767 flags |= QF_GETLIST_CONTEXT;
4768
4769 if (dict_find(what, (char_u *)"items", -1) != NULL)
4770 flags |= QF_GETLIST_ITEMS;
4752 4771
4753 if (flags & QF_GETLIST_TITLE) 4772 if (flags & QF_GETLIST_TITLE)
4754 { 4773 {
4755 char_u *t; 4774 char_u *t;
4756 t = qi->qf_lists[qf_idx].qf_title; 4775 t = qi->qf_lists[qf_idx].qf_title;
4795 status = FAIL; 4814 status = FAIL;
4796 } 4815 }
4797 else 4816 else
4798 status = dict_add_nr_str(retdict, "context", 0L, (char_u *)""); 4817 status = dict_add_nr_str(retdict, "context", 0L, (char_u *)"");
4799 } 4818 }
4819
4820 if ((status == OK) && (flags & QF_GETLIST_ID))
4821 status = dict_add_nr_str(retdict, "id", qi->qf_lists[qf_idx].qf_id,
4822 NULL);
4800 4823
4801 return status; 4824 return status;
4802 } 4825 }
4803 4826
4804 /* 4827 /*
4976 qf_idx = qi->qf_listcount - 1; 4999 qf_idx = qi->qf_listcount - 1;
4977 else if (newlist) 5000 else if (newlist)
4978 qf_idx = 0; 5001 qf_idx = 0;
4979 else 5002 else
4980 return FAIL; 5003 return FAIL;
5004 }
5005 else
5006 return FAIL;
5007 }
5008
5009 if (!newlist && (di = dict_find(what, (char_u *)"id", -1)) != NULL)
5010 {
5011 /* Use the quickfix/location list with the specified id */
5012 if (di->di_tv.v_type == VAR_NUMBER)
5013 {
5014 for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++)
5015 if (qi->qf_lists[qf_idx].qf_id == di->di_tv.vval.v_number)
5016 break;
5017 if (qf_idx == qi->qf_listcount)
5018 return FAIL; /* List not found */
4981 } 5019 }
4982 else 5020 else
4983 return FAIL; 5021 return FAIL;
4984 } 5022 }
4985 5023