-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
[READY] Restore cursor position after omnifunc call #2707
Conversation
Calling directly the omnifunc may move the cursor position. This is the case with the default Vim omnifunc for C-family languages (ccomplete#Complete) which calls searchdecl to find a declaration. This function is supposed to move the cursor to the found declaration but it doesn't when called through the omni completion mapping (CTRL-X CTRL-O). So, we restore the cursor position after calling the omnifunc.
Codecov Report
@@ Coverage Diff @@
## master #2707 +/- ##
=========================================
+ Coverage 90.98% 91% +0.01%
=========================================
Files 20 20
Lines 1941 1945 +4
=========================================
+ Hits 1766 1770 +4
Misses 175 175 |
Do you think that adding some tests would be of value here? It looks like the only way to test this would be to mock the cursor to move since we don't run an actual vim here so I'm a little conflicted here 😕 Reviewed 2 of 2 files at r1. Comments from Reviewable |
We are already mocking the cursor position in the omnifunc tests. Added a test. Reviewed 2 of 2 files at r1, 1 of 1 files at r2. Comments from Reviewable |
Nice catch!
Reviewed 2 of 2 files at r1, 1 of 1 files at r2. Comments from Reviewable |
I wasn't thinking that with the new Omnifunc tests this would be so easy to write and especially to read! @zzbot r=bstaletic Review status: all files reviewed at latest revision, all discussions resolved. Comments from Reviewable |
📌 Commit dec9c0f has been approved by |
[READY] Restore cursor position after omnifunc call When compiled without C-family support, YCM will use the default omnifunc from Vim (`ccomplete#Complete`) to provide semantic completion. This omnifunc calls [`searchdecl`](http://vimdoc.sourceforge.net/htmldoc/eval.html#searchdecl()) to find a declaration, which is supposed to move the cursor to that declaration. However, the cursor is not moved when called through the omni completion mapping (`CTRL-X CTRL-O`). Since PR #2657, YCM calls the omnifunc outside completion mode and thus the cursor is moved to the found declaration after typing `.` or `->`. Considering this `searchdecl` trick may be used by other omnifuncs, we fix the issue by always restoring the cursor position after calling the omnifunc. Fixes #2698. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2707) <!-- Reviewable:end -->
☀️ Test successful - status-appveyor, status-travis |
When compiled without C-family support, YCM will use the default omnifunc from Vim (
ccomplete#Complete
) to provide semantic completion. This omnifunc callssearchdecl
to find a declaration, which is supposed to move the cursor to that declaration. However, the cursor is not moved when called through the omni completion mapping (CTRL-X CTRL-O
). Since PR #2657, YCM calls the omnifunc outside completion mode and thus the cursor is moved to the found declaration after typing.
or->
.Considering this
searchdecl
trick may be used by other omnifuncs, we fix the issue by always restoring the cursor position after calling the omnifunc.Fixes #2698.
This change is