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

Make order of 'info' in completion_info consistent #12971

Closed
wants to merge 1 commit into from

Conversation

LemonBoy
Copy link
Contributor

Start the iteration from the same point and follow the same direction as done when assigning the completion numbers. This way we remove the dependance on the completion direction and make the order of 'info' consistent.

Fixes #12230

Some more testing and/or a thorough review would be greatly appreciated ;)

Start the iteration from the same point and follow the same direction as
done when assigning the completion numbers. This way we remove the
dependance on the completion direction and make the order of 'info'
consistent.

Fixes vim#12230
@codecov
Copy link

codecov bot commented Aug 30, 2023

Codecov Report

Merging #12971 (e2e8004) into master (e750f8c) will increase coverage by 0.02%.
Report is 54 commits behind head on master.
The diff coverage is 73.91%.

@@            Coverage Diff             @@
##           master   #12971      +/-   ##
==========================================
+ Coverage   82.04%   82.06%   +0.02%     
==========================================
  Files         160      160              
  Lines      194679   194769      +90     
  Branches    43696    43712      +16     
==========================================
+ Hits       159717   159837     +120     
+ Misses      22095    22065      -30     
  Partials    12867    12867              
Flag Coverage Δ
huge-clang-Array 82.68% <73.91%> (?)
huge-clang-none ?
linux 82.68% <73.91%> (+0.02%) ⬆️
mingw-x64-HUGE 76.62% <77.77%> (+0.02%) ⬆️
mingw-x86-HUGE 77.11% <77.77%> (+0.02%) ⬆️
windows 78.21% <77.77%> (+0.02%) ⬆️

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

Files Changed Coverage Δ
src/insexpand.c 88.22% <73.91%> (+0.01%) ⬆️

... and 32 files with indirect coverage changes

@chrisbra
Copy link
Member

Thanks. I think it makes sense to refactor into a separate function. Let me include this.

@chrisbra chrisbra closed this in 69fb5af Oct 11, 2023
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Oct 11, 2023
Problem:  complete_info() returns wrong index
Solution: Make order of 'info' in completion_info consistent

Start the iteration from the same point and follow the same direction as
done when assigning the completion numbers. This way we remove the
dependence on the completion direction and make the order of 'info'
consistent.

closes: vim/vim#12230
closes: vim/vim#12971

vim/vim@69fb5af

Co-authored-by: LemonBoy <thatlemon@gmail.com>
zeertzjq added a commit to neovim/neovim that referenced this pull request Oct 12, 2023
Problem:  complete_info() returns wrong index
Solution: Make order of 'info' in completion_info consistent

Start the iteration from the same point and follow the same direction as
done when assigning the completion numbers. This way we remove the
dependence on the completion direction and make the order of 'info'
consistent.

closes: vim/vim#12230
closes: vim/vim#12971

vim/vim@69fb5af

Co-authored-by: LemonBoy <thatlemon@gmail.com>
@Shane-XB-Qian
Copy link
Contributor

is this possible did not handle or update index of 'selected' not well when textchangdp or cursormovedi event?
info.items[info.selected] happened out of range err.
// cannot repro at second time, just accidentally happened, please just review and think if it had outage there..

@chrisbra
Copy link
Member

possibly 🤷
Please try to reproduce and open a new issue for it

@Shane-XB-Qian
Copy link
Contributor

// #12230 (comment)
so not sure why it was done this way and i actually not very understand what was the issue problem there,
but looks it made new problem now, i cannot repro it or next time faced it, or wish someone else to jump into..

@Shane-XB-Qian
Copy link
Contributor

@chrisbra i donot know how to fix, but i prepared a test case: #13402

Shane-XB-Qian added a commit to Shane-XB-Qian/vim that referenced this pull request Oct 21, 2023
Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
jaehoonhwang pushed a commit to jaehoonhwang/neovim that referenced this pull request Oct 22, 2023
Problem:  complete_info() returns wrong index
Solution: Make order of 'info' in completion_info consistent

Start the iteration from the same point and follow the same direction as
done when assigning the completion numbers. This way we remove the
dependence on the completion direction and make the order of 'info'
consistent.

closes: vim/vim#12230
closes: vim/vim#12971

vim/vim@69fb5af

Co-authored-by: LemonBoy <thatlemon@gmail.com>
chrisbra added a commit to chrisbra/vim that referenced this pull request Oct 22, 2023
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.

The general case is this:

1) CTRL-X CTRL-N, we will traverse the list starting from
   compl_first_match and then go forwards (using the cp->next pointer)
   through the list (skipping the very first entry, which has the
   CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry

2) CTRL-X CTRL-P, we will traverse the list starting from
   compl_first_match (which now points to the last entry). The previous
   entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
   traversing the list from the second prev pointer.

There are in fact 2 special cases after starting the completion menu
with CTRL-X:

3)  CTRL-N and then going backwards by pressing CTRL-P again.
    compl_first_match will point to the same entry as in step 1 above,
    but since compl_dir_foward() has been switched by pressing CTRL-P
    to backwards we need to pretend to be in still in case 1 and still
    traverse the list in forward direction using the cp_next pointer

4)  CTRL-P and then going forwards by pressing CTRL-N again.
    compl_first_match will point to the same entry as in step 2 above,
    but since compl_dir_foward() has been switched by pressing CTRL-N
    to forwards we need to pretend to be in still in case 2 and still
    traverse the list in backward direction using the cp_prev pointer

related: vim#13402
related: vim#12971
Shane-XB-Qian added a commit to Shane-XB-Qian/vim that referenced this pull request Oct 23, 2023
// to repro and test 'index out of range' err

Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
chrisbra added a commit that referenced this pull request Oct 27, 2023
Problem:  Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
          add more tests, make it work with 'noselect'

completion: move in right direction when  filling completion_info()

When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.

The general case is this:

1) CTRL-X CTRL-N, we will traverse the list starting from
   compl_first_match and then go forwards (using the cp->next pointer)
   through the list (skipping the very first entry, which has the
   CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry

2) CTRL-X CTRL-P, we will traverse the list starting from
   compl_first_match (which now points to the last entry). The previous
   entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
   traversing the list from the second prev pointer.

There are in fact 2 special cases after starting the completion menu
with CTRL-X:

3)  CTRL-N and then going backwards by pressing CTRL-P again.
    compl_first_match will point to the same entry as in step 1 above,
    but since compl_dir_foward() has been switched by pressing CTRL-P
    to backwards we need to pretend to be in still in case 1 and still
    traverse the list in forward direction using the cp_next pointer

4)  CTRL-P and then going forwards by pressing CTRL-N again.
    compl_first_match will point to the same entry as in step 2 above,
    but since compl_dir_foward() has been switched by pressing CTRL-N
    to forwards we need to pretend to be in still in case 2 and still
    traverse the list in backward direction using the cp_prev pointer

For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.

related: #13402
related: #12971
closes: #13408

Signed-off-by: Christian Brabandt <cb@256bit.org>
zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Oct 27, 2023
Problem:  Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
          add more tests, make it work with 'noselect'

completion: move in right direction when  filling completion_info()

When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.

The general case is this:

1) CTRL-X CTRL-N, we will traverse the list starting from
   compl_first_match and then go forwards (using the cp->next pointer)
   through the list (skipping the very first entry, which has the
   CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry

2) CTRL-X CTRL-P, we will traverse the list starting from
   compl_first_match (which now points to the last entry). The previous
   entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
   traversing the list from the second prev pointer.

There are in fact 2 special cases after starting the completion menu
with CTRL-X:

3)  CTRL-N and then going backwards by pressing CTRL-P again.
    compl_first_match will point to the same entry as in step 1 above,
    but since compl_dir_foward() has been switched by pressing CTRL-P
    to backwards we need to pretend to be in still in case 1 and still
    traverse the list in forward direction using the cp_next pointer

4)  CTRL-P and then going forwards by pressing CTRL-N again.
    compl_first_match will point to the same entry as in step 2 above,
    but since compl_dir_foward() has been switched by pressing CTRL-N
    to forwards we need to pretend to be in still in case 2 and still
    traverse the list in backward direction using the cp_prev pointer

For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.

related: vim/vim#13402
related: vim/vim#12971
closes: vim/vim#13408

vim/vim@daef8c7

Co-authored-by: Christian Brabandt <cb@256bit.org>
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.

complete_info() returns incorrect index with behavior that depends on completeopt
3 participants