[vim/vim] Allow attaching custom data to setqflist() via 'user_data' field (PR #11818)

16 views
Skip to first unread message

Tom Praschan

unread,
Jan 14, 2023, 2:44:30 PM1/14/23
to vim/vim, Subscribed

For example, LSP plugins could use this to attach the original LSP Location item for things like 'textDocument/reference'


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/11818

Commit Summary

  • 130438b Allow attaching custom data to setqflist() via 'user_data' field

File Changes

(3 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818@github.com>

codecov[bot]

unread,
Jan 14, 2023, 2:56:02 PM1/14/23
to vim/vim, Subscribed

Codecov Report

Merging #11818 (1c242b0) into master (24a8d06) will decrease coverage by 0.80%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@

##           master   #11818      +/-   ##

==========================================

- Coverage   81.90%   81.09%   -0.81%     

==========================================

  Files         164      154      -10     

  Lines      192861   182433   -10428     

  Branches    43732    41307    -2425     

==========================================

- Hits       157969   147951   -10018     

+ Misses      22102    21553     -549     

- Partials    12790    12929     +139     
Flag Coverage Δ
huge-clang-none 82.60% <100.00%> (+<0.01%) ⬆️
huge-gcc-none ?
huge-gcc-testgui ?
huge-gcc-unittests 0.29% <0.00%> (-0.01%) ⬇️
linux 81.09% <100.00%> (-1.27%) ⬇️
mingw-x64-HUGE ?
mingw-x86-HUGE ?
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/quickfix.c 89.88% <100.00%> (-1.33%) ⬇️
src/if_perl.xs 54.50% <0.00%> (-17.82%) ⬇️
src/regexp_nfa.c 80.56% <0.00%> (-9.33%) ⬇️
src/arabic.c 85.86% <0.00%> (-8.70%) ⬇️
src/typval.c 82.05% <0.00%> (-8.00%) ⬇️
src/regexp_bt.c 78.50% <0.00%> (-7.47%) ⬇️
src/vim9execute.c 82.61% <0.00%> (-7.12%) ⬇️
src/json.c 77.84% <0.00%> (-5.47%) ⬇️
src/vim9instr.c 77.10% <0.00%> (-4.74%) ⬇️
src/vim9compile.c 86.82% <0.00%> (-4.60%) ⬇️
... and 138 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1382902510@github.com>

Yegappan Lakshmanan

unread,
Jan 14, 2023, 3:03:28 PM1/14/23
to vim/vim, Subscribed

@yegappan commented on this pull request.


In src/quickfix.c:

> @@ -951,6 +952,7 @@ typedef struct {
     char_u	*pattern;
     int		enr;
     int		type;
+    typval_T	*user_data;

The support for garbage collection needs to be added for "user_data". You can try setting a Dict as "user_data", invoke test_garbagecollect_now() function to do the garbage collection and then retrieve the user_data using getqflist() and try to access the Dict.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1248976082@github.com>

Tom Praschan

unread,
Jan 14, 2023, 4:19:12 PM1/14/23
to vim/vim, Subscribed

@tom-anders commented on this pull request.


In src/quickfix.c:

> @@ -951,6 +952,7 @@ typedef struct {
     char_u	*pattern;
     int		enr;
     int		type;
+    typval_T	*user_data;

Yeah that indeed seems to clear the dict. How do I add it to garbage collection though? dict_alloc()...?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1249008644@github.com>

Bram Moolenaar

unread,
Jan 14, 2023, 4:47:52 PM1/14/23
to vim/vim, Subscribed


> @tom-anders commented on this pull request.
>
> > @@ -951,6 +952,7 @@ typedef struct {
> char_u *pattern;
> int enr;
> int type;
> + typval_T *user_data;
>
> Yeah that indeed seems to clear the dict. How do I add it to garbage
> collection though? `dict_alloc()`...?

The entry point is set_ref_in_quickfix(). You can see it calls
mark_quickfix_ctx() to handle "qf_ctx", something similar has to happen
for all user_data values.

--
Me? A skeptic? I trust you have proof.

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1382929376@github.com>

Tom Praschan

unread,
Jan 15, 2023, 5:51:55 AM1/15/23
to vim/vim, Subscribed

@tom-anders commented on this pull request. > @@ -951,6 +952,7 @@ typedef struct { char_u pattern; int enr; int type; + typval_T user_data; Yeah that indeed seems to clear the dict. How do I add it to garbage collection though? dict_alloc()...?


The entry point is set_ref_in_quickfix(). You can see it calls mark_quickfix_ctx() to handle "qf_ctx", something similar has to happen for all user_data values.

-- Me? A skeptic? I trust you have proof. /// Bram Moolenaar -- @.* -- http://www.Moolenaar.net \\ /// \\ \\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\ help me help AIDS victims -- http://ICCF-Holland.org ///

Thanks for the pointers, think I got it now


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1383118236@github.com>

Tom Praschan

unread,
Feb 19, 2023, 8:43:13 AM2/19/23
to vim/vim, Subscribed

@brammool @yegappan Does this look good or is there anything else you want me to add? Should I address the code coverage issue?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1435992945@github.com>

Yegappan Lakshmanan

unread,
Feb 19, 2023, 11:03:46 AM2/19/23
to vim/vim, Subscribed

@yegappan commented on this pull request.


In src/quickfix.c:

> @@ -7801,6 +7819,23 @@ set_errorlist(
     return retval;
 }
 
+static int mark_quickfix_user_data(qf_info_T *qi, int copyID) 
+{
+    int abort = FALSE;
+    for (int i = 0; i < LISTCOUNT && !abort; ++i) {
+	qfline_T *qfp;
+	int j;
+        FOR_ALL_QFL_ITEMS(&qi->qf_lists[i], qfp, j) 

This is functionally correct but inefficient. The garbage collection runs often. If a user has multiple quickfix/location lists with a large number of entries (without any user data), then this loop will slow down Vim. Is it possible to set a flag in the list if any of the item has a user data attached to it? This way only lists with items that have a user data attached need to be inspected.


In src/testdir/test_quickfix.vim:

>    let l = g:Xgetlist()
   call assert_equal(2, len(l))
   call assert_equal(2, l[1].lnum)
   call assert_equal(3, l[1].end_lnum)
   call assert_equal(4, l[1].col)
   call assert_equal(5, l[1].end_col)
+  call assert_equal({'6': [7, 8]}, l[1].user_data)
 

Can you add one more test for garbage collection? You can add a complex type as user data, then call the test_garbagecollect_now() function and then retrieve the user data and check to make sure that it is still present.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1304812506@github.com>

Bram Moolenaar

unread,
Feb 19, 2023, 3:33:53 PM2/19/23
to vim/vim, Subscribed

I would also expect a change in qf_free_items((). clear_tv() should be called for qf_user_data


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1436086458@github.com>

Tom Praschan

unread,
Feb 20, 2023, 1:10:42 PM2/20/23
to vim/vim, Push

@tom-anders pushed 1 commit.

  • 7f68ff7 Allow attaching custom data to setqflist() via 'user_data' field


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/push/12684499252@github.com>

Tom Praschan

unread,
Feb 20, 2023, 1:10:53 PM2/20/23
to vim/vim, Subscribed

@tom-anders commented on this pull request.


In src/testdir/test_quickfix.vim:

>    let l = g:Xgetlist()
   call assert_equal(2, len(l))
   call assert_equal(2, l[1].lnum)
   call assert_equal(3, l[1].end_lnum)
   call assert_equal(4, l[1].col)
   call assert_equal(5, l[1].end_col)
+  call assert_equal({'6': [7, 8]}, l[1].user_data)
 

Done, sorry for missing that


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1306196848@github.com>

Tom Praschan

unread,
Feb 20, 2023, 1:13:25 PM2/20/23
to vim/vim, Subscribed

@tom-anders commented on this pull request.


In src/quickfix.c:

> @@ -7801,6 +7819,23 @@ set_errorlist(
     return retval;
 }
 
+static int mark_quickfix_user_data(qf_info_T *qi, int copyID) 
+{
+    int abort = FALSE;
+    for (int i = 0; i < LISTCOUNT && !abort; ++i) {
+	qfline_T *qfp;
+	int j;
+        FOR_ALL_QFL_ITEMS(&qi->qf_lists[i], qfp, j) 

This is certainly possible, but tbh I am not yet familiar enough with the code to find all the right places to set this flag - Obviously we should update the flag inside qf_add_entry(), but I'm not sure in which other places I'd need to initialize/update/copy this flag..?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1306198677@github.com>

Tom Praschan

unread,
Feb 20, 2023, 1:14:08 PM2/20/23
to vim/vim, Subscribed

I would also expect a change in qf_free_items((). clear_tv() should be called for qf_user_data

Added clear_tv as suggested, thanks!


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1437396712@github.com>

Tom Praschan

unread,
Feb 21, 2023, 2:41:31 PM2/21/23
to vim/vim, Push

@tom-anders pushed 1 commit.

  • 5c3bef8 Allow attaching custom data to setqflist() via 'user_data' field

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/push/12698124448@github.com>

dundargoc

unread,
Mar 16, 2023, 3:14:50 AM3/16/23
to vim/vim, Subscribed

@dundargoc commented on this pull request.


In src/quickfix.c:

> @@ -7801,6 +7819,23 @@ set_errorlist(
     return retval;
 }
 
+static int mark_quickfix_user_data(qf_info_T *qi, int copyID) 
+{
+    int abort = FALSE;
+    for (int i = 0; i < LISTCOUNT && !abort; ++i) {
+	qfline_T *qfp;
+	int j;
+        FOR_ALL_QFL_ITEMS(&qi->qf_lists[i], qfp, j) 

@yegappan would you say this is a blocker? If so, mind giving a few pointers so this fellow can get this to the finish line?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1343038081@github.com>

Yegappan Lakshmanan

unread,
Mar 16, 2023, 10:09:42 AM3/16/23
to vim/vim, Subscribed

@yegappan commented on this pull request.


In src/quickfix.c:

> @@ -7801,6 +7819,23 @@ set_errorlist(
     return retval;
 }
 
+static int mark_quickfix_user_data(qf_info_T *qi, int copyID) 
+{
+    int abort = FALSE;
+    for (int i = 0; i < LISTCOUNT && !abort; ++i) {
+	qfline_T *qfp;
+	int j;
+        FOR_ALL_QFL_ITEMS(&qi->qf_lists[i], qfp, j) 

Yes. This will slow down the garbage collection with a large number of quickfix/location lists/entries.

To address this, a flag should be added to qf_list_T that indicates whether any of the entries in that list have user data. By default, this will be set to FALSE. In the qf_add_entry() function, when copying the user data, set this flag to TRUE. When running the garbage collection for the quickfix lists, check this flag. If the flag is set, then do the garbage collection update for the user data in the quickfix items for that list. If the flag it not set, the list can be skipped.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1343854899@github.com>

Tom Praschan

unread,
Mar 16, 2023, 10:59:21 AM3/16/23
to vim/vim, Push

@tom-anders pushed 1 commit.

  • 4a40c81 Allow attaching custom data to setqflist() via 'user_data' field

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/push/12967954447@github.com>

Tom Praschan

unread,
Mar 16, 2023, 11:00:26 AM3/16/23
to vim/vim, Subscribed

@tom-anders commented on this pull request.


In src/quickfix.c:

> @@ -7801,6 +7819,23 @@ set_errorlist(
     return retval;
 }
 
+static int mark_quickfix_user_data(qf_info_T *qi, int copyID) 
+{
+    int abort = FALSE;
+    for (int i = 0; i < LISTCOUNT && !abort; ++i) {
+	qfline_T *qfp;
+	int j;
+        FOR_ALL_QFL_ITEMS(&qi->qf_lists[i], qfp, j) 

Thanks, I was still not sure where to add the default value, but qf_new_list looked reasonable, hope this is correct?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1344001930@github.com>

Yegappan Lakshmanan

unread,
Mar 16, 2023, 11:50:31 AM3/16/23
to vim/vim, Subscribed

@yegappan commented on this pull request.


In src/quickfix.c:

> @@ -2173,6 +2179,12 @@ qf_add_entry(
     qfp->qf_col = col;
     qfp->qf_end_col = end_col;
     qfp->qf_viscol = vis_col;
+    if (user_data == NULL || user_data->v_type == VAR_UNKNOWN)
+        qfp->qf_user_data.v_type = VAR_UNKNOWN;
+    else {

Can you move the curly brace to the next line (to follow the coding style)?


In src/quickfix.c:

> @@ -7801,6 +7824,27 @@ set_errorlist(
     return retval;
 }
 
+static int mark_quickfix_user_data(qf_info_T *qi, int copyID) 
+{
+    int abort = FALSE;
+    for (int i = 0; i < LISTCOUNT && !abort; ++i) {
+	qf_list_T *qfl = &qi->qf_lists[i];
+	if (qfl->qf_has_user_data) 

To reduce the indentation below, can you change the above to the following?

     if (!qfl->qf_has_user_data)
        continue;


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1344150644@github.com>

Yegappan Lakshmanan

unread,
Mar 16, 2023, 12:01:54 PM3/16/23
to vim/vim, Subscribed

@yegappan commented on this pull request.


In src/quickfix.c:

> @@ -2335,6 +2347,7 @@ copy_loclist_entries(qf_list_T *from_qfl, qf_list_T *to_qfl)
 		    from_qfp->qf_pattern,

The new flag has to be copied to the new location list in copy_loclist(). Also, do you need to copy the per quickfix item user_data in copy_loclist_entries()?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1344178028@github.com>

Tom Praschan

unread,
Mar 16, 2023, 12:17:21 PM3/16/23
to vim/vim, Push

@tom-anders pushed 1 commit.

  • 897e12e Allow attaching custom data to setqflist() via 'user_data' field

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/push/12969069248@github.com>

Tom Praschan

unread,
Mar 16, 2023, 12:17:29 PM3/16/23
to vim/vim, Subscribed

@tom-anders commented on this pull request.


In src/quickfix.c:

> @@ -2335,6 +2347,7 @@ copy_loclist_entries(qf_list_T *from_qfl, qf_list_T *to_qfl)
 		    from_qfp->qf_pattern,

Done 👍


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1344234317@github.com>

Yegappan Lakshmanan

unread,
Mar 16, 2023, 12:28:41 PM3/16/23
to vim/vim, Subscribed

@yegappan commented on this pull request.


In src/quickfix.c:

> @@ -2335,6 +2347,7 @@ copy_loclist_entries(qf_list_T *from_qfl, qf_list_T *to_qfl)
 		    from_qfp->qf_pattern,

I think you also need to copy the per-item user_data in the copy_loclist_entries() function?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1344262147@github.com>

Yegappan Lakshmanan

unread,
Mar 16, 2023, 12:29:50 PM3/16/23
to vim/vim, Subscribed

@yegappan approved this pull request.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1344264476@github.com>

Yegappan Lakshmanan

unread,
Mar 16, 2023, 12:30:31 PM3/16/23
to vim/vim, Subscribed

@yegappan commented on this pull request.

The changes look good to me.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/review/1344265661@github.com>

Tom Praschan

unread,
Mar 16, 2023, 12:31:45 PM3/16/23
to vim/vim, Subscribed

Thanks for the review and your time and patience!


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1472308386@github.com>

Tom Praschan

unread,
May 6, 2023, 12:19:02 PM5/6/23
to vim/vim, Subscribed

@brammool Friendly ping - is there anything stopping this from being included?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1537174672@github.com>

zeertzjq

unread,
May 6, 2023, 12:23:48 PM5/6/23
to vim/vim, Subscribed

There are some code style test failures caused by trailing white spacez.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1537175558@github.com>

Bram Moolenaar

unread,
May 6, 2023, 12:56:22 PM5/6/23
to vim/vim, Subscribed

It's in the todo list. I want to include bug fixes first. And please make the tests pass.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1537181095@github.com>

Tom Praschan

unread,
May 6, 2023, 1:17:05 PM5/6/23
to vim/vim, Push

@tom-anders pushed 1 commit.

  • bc72cd1 Allow attaching custom data to setqflist() via 'user_data' field

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/push/13546371780@github.com>

Tom Praschan

unread,
May 6, 2023, 1:18:53 PM5/6/23
to vim/vim, Subscribed

Ahh, sorry about that - I think the last time I took a look at the CI, I was really confused because the line numbers wouldn't match with my local and branch (and also test_codestyle.vim didn't even exist on my branch).

A rebase helped :)


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1537185371@github.com>

Yegappan Lakshmanan

unread,
Aug 11, 2023, 11:06:31 AM8/11/23
to vim/vim, Subscribed

Can you please update and rebase this PR to the latest?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1674938359@github.com>

Christian Brabandt

unread,
Aug 11, 2023, 5:29:32 PM8/11/23
to vim/vim, Subscribed

Closed #11818 via ca6ac99.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/issue_event/10073904777@github.com>

Tom Praschan

unread,
Aug 20, 2023, 6:39:30 AM8/20/23
to vim/vim, Subscribed

Sorry, I was on vacation, thanks for merging!


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/11818/c1685250540@github.com>

Reply all
Reply to author
Forward
0 new messages