comparison src/quickfix.c @ 11412:84baca75b7f2 v8.0.0590

patch 8.0.0590: cannot add a context to locations commit https://github.com/vim/vim/commit/8f77c5a4ec756f3f866bd6b18feb6fca6f2a2e91 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 30 14:21:00 2017 +0200 patch 8.0.0590: cannot add a context to locations Problem: Cannot add a context to locations. Solution: Add the "context" entry in location entries. (Yegappan Lakshmanan, closes #1012)
author Christian Brabandt <cb@256bit.org>
date Sun, 30 Apr 2017 14:30:04 +0200
parents 30af33f4d353
children ad4b56939140
comparison
equal deleted inserted replaced
11411:ab53b2f7ffc3 11412:84baca75b7f2
55 int qf_count; /* number of errors (0 means no error list) */ 55 int qf_count; /* number of errors (0 means no error list) */
56 int qf_index; /* current index in the error list */ 56 int qf_index; /* current index in the error list */
57 int qf_nonevalid; /* TRUE if not a single valid entry found */ 57 int qf_nonevalid; /* TRUE if not a single valid entry found */
58 char_u *qf_title; /* title derived from the command that created 58 char_u *qf_title; /* title derived from the command that created
59 * the error list */ 59 * the error list */
60 typval_T *qf_ctx; /* context set by setqflist/setloclist */
60 } qf_list_T; 61 } qf_list_T;
61 62
62 struct qf_info_S 63 struct qf_info_S
63 { 64 {
64 /* 65 /*
1594 to_qfl->qf_ptr = NULL; 1595 to_qfl->qf_ptr = NULL;
1595 if (from_qfl->qf_title != NULL) 1596 if (from_qfl->qf_title != NULL)
1596 to_qfl->qf_title = vim_strsave(from_qfl->qf_title); 1597 to_qfl->qf_title = vim_strsave(from_qfl->qf_title);
1597 else 1598 else
1598 to_qfl->qf_title = NULL; 1599 to_qfl->qf_title = NULL;
1600 if (from_qfl->qf_ctx != NULL)
1601 {
1602 to_qfl->qf_ctx = alloc_tv();
1603 if (to_qfl->qf_ctx != NULL)
1604 copy_tv(from_qfl->qf_ctx, to_qfl->qf_ctx);
1605 }
1606 else
1607 to_qfl->qf_ctx = NULL;
1599 1608
1600 if (from_qfl->qf_count) 1609 if (from_qfl->qf_count)
1601 { 1610 {
1602 qfline_T *from_qfp; 1611 qfline_T *from_qfp;
1603 qfline_T *prevp; 1612 qfline_T *prevp;
2747 qi->qf_lists[idx].qf_start = qfpnext; 2756 qi->qf_lists[idx].qf_start = qfpnext;
2748 --qi->qf_lists[idx].qf_count; 2757 --qi->qf_lists[idx].qf_count;
2749 } 2758 }
2750 vim_free(qi->qf_lists[idx].qf_title); 2759 vim_free(qi->qf_lists[idx].qf_title);
2751 qi->qf_lists[idx].qf_title = NULL; 2760 qi->qf_lists[idx].qf_title = NULL;
2761 free_tv(qi->qf_lists[idx].qf_ctx);
2762 qi->qf_lists[idx].qf_ctx = NULL;
2752 qi->qf_lists[idx].qf_index = 0; 2763 qi->qf_lists[idx].qf_index = 0;
2753 qi->qf_lists[idx].qf_start = NULL; 2764 qi->qf_lists[idx].qf_start = NULL;
2754 qi->qf_lists[idx].qf_last = NULL; 2765 qi->qf_lists[idx].qf_last = NULL;
2755 qi->qf_lists[idx].qf_ptr = NULL; 2766 qi->qf_lists[idx].qf_ptr = NULL;
2756 qi->qf_lists[idx].qf_nonevalid = TRUE; 2767 qi->qf_lists[idx].qf_nonevalid = TRUE;
4627 QF_GETLIST_NONE = 0x0, 4638 QF_GETLIST_NONE = 0x0,
4628 QF_GETLIST_TITLE = 0x1, 4639 QF_GETLIST_TITLE = 0x1,
4629 QF_GETLIST_ITEMS = 0x2, 4640 QF_GETLIST_ITEMS = 0x2,
4630 QF_GETLIST_NR = 0x4, 4641 QF_GETLIST_NR = 0x4,
4631 QF_GETLIST_WINID = 0x8, 4642 QF_GETLIST_WINID = 0x8,
4643 QF_GETLIST_CONTEXT = 0x10,
4632 QF_GETLIST_ALL = 0xFF 4644 QF_GETLIST_ALL = 0xFF
4633 }; 4645 };
4634 4646
4635 /* 4647 /*
4636 * Return quickfix/location list details (title) as a 4648 * Return quickfix/location list details (title) as a
4679 flags |= QF_GETLIST_TITLE; 4691 flags |= QF_GETLIST_TITLE;
4680 4692
4681 if (dict_find(what, (char_u *)"winid", -1) != NULL) 4693 if (dict_find(what, (char_u *)"winid", -1) != NULL)
4682 flags |= QF_GETLIST_WINID; 4694 flags |= QF_GETLIST_WINID;
4683 4695
4696 if (dict_find(what, (char_u *)"context", -1) != NULL)
4697 flags |= QF_GETLIST_CONTEXT;
4698
4684 if (flags & QF_GETLIST_TITLE) 4699 if (flags & QF_GETLIST_TITLE)
4685 { 4700 {
4686 char_u *t; 4701 char_u *t;
4687 t = qi->qf_lists[qf_idx].qf_title; 4702 t = qi->qf_lists[qf_idx].qf_title;
4688 if (t == NULL) 4703 if (t == NULL)
4695 { 4710 {
4696 win_T *win; 4711 win_T *win;
4697 win = qf_find_win(qi); 4712 win = qf_find_win(qi);
4698 if (win != NULL) 4713 if (win != NULL)
4699 status = dict_add_nr_str(retdict, "winid", win->w_id, NULL); 4714 status = dict_add_nr_str(retdict, "winid", win->w_id, NULL);
4715 }
4716
4717 if ((status == OK) && (flags & QF_GETLIST_CONTEXT))
4718 {
4719 if (qi->qf_lists[qf_idx].qf_ctx != NULL)
4720 {
4721 di = dictitem_alloc((char_u *)"context");
4722 if (di != NULL)
4723 {
4724 copy_tv(qi->qf_lists[qf_idx].qf_ctx, &di->di_tv);
4725 dict_add(retdict, di);
4726 }
4727 }
4728 else
4729 status = dict_add_nr_str(retdict, "context", 0L, (char_u *)"");
4700 } 4730 }
4701 4731
4702 return status; 4732 return status;
4703 } 4733 }
4704 4734
4872 qf_update_win_titlevar(qi); 4902 qf_update_win_titlevar(qi);
4873 retval = OK; 4903 retval = OK;
4874 } 4904 }
4875 } 4905 }
4876 4906
4907 if ((di = dict_find(what, (char_u *)"context", -1)) != NULL)
4908 {
4909 typval_T *ctx;
4910 free_tv(qi->qf_lists[qi->qf_curlist].qf_ctx);
4911 ctx = alloc_tv();
4912 if (ctx != NULL)
4913 copy_tv(&di->di_tv, ctx);
4914 qi->qf_lists[qi->qf_curlist].qf_ctx = ctx;
4915 }
4916
4877 return retval; 4917 return retval;
4878 } 4918 }
4879 4919
4880 /* 4920 /*
4881 * Find the non-location list window with the specified location list. 4921 * Find the non-location list window with the specified location list.
4978 retval = qf_set_properties(qi, what, action); 5018 retval = qf_set_properties(qi, what, action);
4979 else 5019 else
4980 retval = qf_add_entries(qi, list, title, action); 5020 retval = qf_add_entries(qi, list, title, action);
4981 5021
4982 return retval; 5022 return retval;
5023 }
5024
5025 static int
5026 mark_quickfix_ctx(qf_info_T *qi, int copyID)
5027 {
5028 int i;
5029 int abort = FALSE;
5030 typval_T *ctx;
5031
5032 for (i = 0; i < LISTCOUNT && !abort; ++i)
5033 {
5034 ctx = qi->qf_lists[i].qf_ctx;
5035 if (ctx != NULL && ctx->v_type != VAR_NUMBER &&
5036 ctx->v_type != VAR_STRING && ctx->v_type != VAR_FLOAT)
5037 abort = set_ref_in_item(ctx, copyID, NULL, NULL);
5038 }
5039
5040 return abort;
5041 }
5042
5043 /*
5044 * Mark the context of the quickfix list and the location lists (if present) as
5045 * "in use". So that garabage collection doesn't free the context.
5046 */
5047 int
5048 set_ref_in_quickfix(int copyID)
5049 {
5050 int abort = FALSE;
5051 tabpage_T *tp;
5052 win_T *win;
5053
5054 abort = mark_quickfix_ctx(&ql_info, copyID);
5055 if (abort)
5056 return abort;
5057
5058 FOR_ALL_TAB_WINDOWS(tp, win)
5059 {
5060 if (win->w_llist != NULL)
5061 {
5062 abort = mark_quickfix_ctx(win->w_llist, copyID);
5063 if (abort)
5064 return abort;
5065 }
5066 }
5067
5068 return abort;
4983 } 5069 }
4984 #endif 5070 #endif
4985 5071
4986 /* 5072 /*
4987 * ":[range]cbuffer [bufnr]" command. 5073 * ":[range]cbuffer [bufnr]" command.