Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

tom-anders
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Jan 14, 2023

Codecov Report

Merging #11818 (bc72cd1) into master (3ab3a86) will increase coverage by 0.01%.
The diff coverage is 84.37%.

@@            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     
Flag Coverage Δ
huge-clang-none 82.73% <84.37%> (+0.02%) ⬆️
linux 82.73% <84.37%> (+0.02%) ⬆️
mingw-x64-HUGE 76.56% <84.61%> (+<0.01%) ⬆️
mingw-x86-HUGE 77.02% <84.61%> (-0.01%) ⬇️
windows 78.15% <84.61%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
src/quickfix.c 91.18% <84.37%> (-0.09%) ⬇️

... and 15 files with indirect coverage changes

@brammool
Copy link
Contributor

brammool commented Jan 14, 2023 via email

@tom-anders
Copy link
Contributor Author

@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

@tom-anders
Copy link
Contributor Author

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

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)
Copy link
Member

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.

Copy link
Contributor Author

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..?

Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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

@brammool
Copy link
Contributor

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

@tom-anders
Copy link
Contributor Author

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!

src/quickfix.c Outdated Show resolved Hide resolved
src/quickfix.c Outdated Show resolved Hide resolved
@@ -2335,6 +2347,7 @@ copy_loclist_entries(qf_list_T *from_qfl, qf_list_T *to_qfl)
from_qfp->qf_pattern,
Copy link
Member

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()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

Copy link
Member

@yegappan yegappan left a 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.

@tom-anders
Copy link
Contributor Author

Thanks for the review and your time and patience!

@tom-anders
Copy link
Contributor Author

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

@zeertzjq
Copy link
Member

zeertzjq commented May 6, 2023

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

@brammool
Copy link
Contributor

brammool commented May 6, 2023

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

@tom-anders
Copy link
Contributor Author

tom-anders commented May 6, 2023

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 :)

@yegappan
Copy link
Member

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

@yegappan yegappan added this to the vim-9.1 milestone Aug 11, 2023
@chrisbra chrisbra closed this in ca6ac99 Aug 11, 2023
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Aug 11, 2023
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>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Aug 11, 2023
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>
zeertzjq added a commit to neovim/neovim that referenced this pull request Aug 12, 2023
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>
@tom-anders
Copy link
Contributor Author

Sorry, I was on vacation, thanks for merging!

chrisbra pushed a commit to chrisbra/vim that referenced this pull request Sep 22, 2023
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants