-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow attaching custom data to setqflist() via 'user_data' field #11818
Conversation
130438b
to
1c242b0
Compare
Codecov Report
@@ Coverage Diff @@
## master #11818 +/- ##
==========================================
+ Coverage 82.06% 82.08% +0.01%
==========================================
Files 160 160
Lines 193437 193469 +32
Branches 43433 43426 -7
==========================================
+ Hits 158740 158801 +61
+ Misses 21866 21827 -39
- Partials 12831 12841 +10
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@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 ///
|
1c242b0
to
d8f6056
Compare
Thanks for the pointers, think I got it now |
src/quickfix.c
Outdated
for (int i = 0; i < LISTCOUNT && !abort; ++i) { | ||
qfline_T *qfp; | ||
int j; | ||
FOR_ALL_QFL_ITEMS(&qi->qf_lists[i], qfp, j) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I was still not sure where to add the default value, but qf_new_list
looked reasonable, hope this is correct?
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, sorry for missing that
I would also expect a change in qf_free_items((). clear_tv() should be called for qf_user_data |
d8f6056
to
7f68ff7
Compare
Added |
7f68ff7
to
5c3bef8
Compare
5c3bef8
to
4a40c81
Compare
@@ -2335,6 +2347,7 @@ copy_loclist_entries(qf_list_T *from_qfl, qf_list_T *to_qfl) | |||
from_qfp->qf_pattern, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
4a40c81
to
897e12e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me.
Thanks for the review and your time and patience! |
@brammool Friendly ping - is there anything stopping this from being included? |
There are some code style test failures caused by trailing white spaces. |
It's in the todo list. I want to include bug fixes first. And please make the tests pass. |
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 branch (and also test_codestyle.vim didn't even exist on my branch). A rebase helped :) |
Can you please update and rebase this PR to the latest? |
Problem: cannot store custom data in quickfix list Solution: add `user_data` field for the quickfix list closes: vim/vim#11818 vim/vim@ca6ac99 Co-authored-by: Tom Praschan <13141438+tom-anders@users.noreply.github.com>
Problem: cannot store custom data in quickfix list Solution: add `user_data` field for the quickfix list closes: vim/vim#11818 vim/vim@ca6ac99 Co-authored-by: Tom Praschan <13141438+tom-anders@users.noreply.github.com>
Problem: cannot store custom data in quickfix list Solution: add `user_data` field for the quickfix list closes: vim/vim#11818 vim/vim@ca6ac99 Co-authored-by: Tom Praschan <13141438+tom-anders@users.noreply.github.com>
Sorry, I was on vacation, thanks for merging! |
Problem: cannot store custom data in quickfix list Solution: add `user_data` field for the quickfix list closes: vim#11818 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Tom Praschan <13141438+tom-anders@users.noreply.github.com>
For example, LSP plugins could use this to attach the original LSP
Location
item for things like 'textDocument/reference'