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

test: to reproduce regression or broken by #12971 #13402

Conversation

Shane-XB-Qian
Copy link
Contributor

test for #12971 (comment)

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
@chrisbra
Copy link
Member

can you please verify using #13408? CC @LemonBoy can you also have a look please?

@Shane-XB-Qian
Copy link
Contributor Author

seems still failed when 'noselect', i added more test.

@Shane-XB-Qian
Copy link
Contributor Author

Shane-XB-Qian commented Oct 23, 2023

i verified this test with v8.2, the test passed,
so that change is a regression or broken, and your patch seems still not fix that.

// to repro and test 'index out of range' err

Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
@Shane-XB-Qian Shane-XB-Qian force-pushed the test_repro_complete_info_index_out_of_range branch from 77d56c1 to 56edc64 Compare October 23, 2023 07:32
@chrisbra
Copy link
Member

not sure about the noselect, have only concentrated on the other issue so far. Can you please move this to the PR?

@chrisbra
Copy link
Member

oh wait, your test doesn't make any sense. if 'noselect' is set, you cannot possibly try to access the selected items, because completion_info['selected'] will report -1 and that is expected here.

@Shane-XB-Qian
Copy link
Contributor Author

Shane-XB-Qian commented Oct 23, 2023 via email

@chrisbra
Copy link
Member

hm, I see, it's a different problem, caused by 'noselect'. Please report issues not here, but in the corresponding PR.

@Shane-XB-Qian
Copy link
Contributor Author

i think whatever 'noselect' or not which just about the start index was different.
and anyway, this ticket is just for #12971 which i said for that index out of range.
as for your patch #13408 no idea if the same purpose, but for now did not pass this test.

this test can be passed at v8.2, so i preferred whichever later patch can fix this issue, but once re-ran this test passed, then ok to go, as for you'd like to merge this PR or not, it is not a matter.

@chrisbra
Copy link
Member

tests included as part of #13408 so closing this one here.

@chrisbra chrisbra closed this Oct 25, 2023
@Shane-XB-Qian Shane-XB-Qian deleted the test_repro_complete_info_index_out_of_range branch October 27, 2023 04:02
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.

None yet

2 participants