-
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] Display diagnostics and parse initial buffer asynchronously using timers #2636
[READY] Display diagnostics and parse initial buffer asynchronously using timers #2636
Conversation
7e6c065
to
e190b67
Compare
Codecov Report
@@ Coverage Diff @@
## master #2636 +/- ##
==========================================
+ Coverage 87.67% 88.48% +0.81%
==========================================
Files 19 19
Lines 1947 1946 -1
==========================================
+ Hits 1707 1722 +15
+ Misses 240 224 -16 |
With that, I'm sold. 👍 Fantastic PR, thank you! I've been wishing to get rid of the CursorHold nonsense for triggering diagnostics for years! Review status: 0 of 4 files reviewed at latest revision, 2 unresolved discussions. autoload/youcompleteme.vim, line 485 at r1 (raw file):
This 100 number should be extracted into a named constant (a script-level var in vimscript might be the best we can do). The var name should reflect the unit of the number, since autoload/youcompleteme.vim, line 495 at r1 (raw file):
Same as above. Comments from Reviewable |
251976b
to
28a02da
Compare
Reviewed 3 of 4 files at r1, 1 of 1 files at r2, 1 of 1 files at r3. autoload/youcompleteme.vim, line 485 at r1 (raw file): Previously, Valloric (Val Markovic) wrote…
Done. autoload/youcompleteme.vim, line 495 at r1 (raw file): Previously, Valloric (Val Markovic) wrote…
Done. Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file): I need to try this out in anger, but meanwhile i have a few questions (disccussion points reallly; i could probably work out all the answers, but I'm being rude and lazy and just asking instead.... hope that's OK :S ) About when we send the file parse request
About the timers mechanism
Anyway, thanks, as always for working on this! autoload/youcompleteme.vim, line 486 at r3 (raw file):
I take it that it is legal to pass an invalid ID here? Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file): Requests
I belive, in theory this could produce more requests, but judging by my limited testing, it is not an issue. I'll explain what I tried later on.
Function
As far as I can tell, that won't be necessary any more as the diagnostics will be updated as soon as possible thanks to the timers being used. Timer mechanism
I just tried incrementing the timer period by 100ms.
Obviously these observations are heavily subjective. How I testedTo have everything snappy I used an almost trivial c++ file: #include <iostream>
#include <vector>
class A {
std::vector<int> myVector;
public:
A(int il) : myVector(il) {}
void is_empty() {
if (myVector.empty()) std::cout << "(empty)";
}
std::vector<int>&& stealVector() {
return std::move(myVector);
}
};
int main() {
A a(5);
std::vector<int> b{2};
b = a.stealVector();
a.is_empty();
return 0;
} To put as much stress on the server as possible I pasted a few random lines of text from my browser which created ~330 The next "test" was quick edits by spamming And the final test was on ycmd's @micbou Thanks for the amazing PR. autoload/youcompleteme.vim, line 486 at r3 (raw file): Previously, puremourning (Ben Jackson) wrote…
Yes, one can pass any integer to Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file):
No, we were calling
I've checked it and
Since PR #2629, we always parse the buffer on load and visit even if its content didn't change because its parsing may be affected by changes from other buffers. However, I realize that it doesn't make sense to parse the buffer when leaving insert mode if we parse it when the buffer has changed. This means that we can remove the
You were triggering the
When leaving a buffer, the new one is parsed and thus the timer is cancelled. When restarting the server, the request is reset so the pending timer cannot end until it's cancelled by a new parse. We should probably add a function that stops all timers and call it on the
100ms because it's a round number and 10ms is too low while 1s is too high. Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file): Previously, micbou wrote…
Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file):
There's also Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file): Previously, bstaletic wrote…
Yes, that's probably why Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file): Previously, micbou wrote…
I tried to remove the changedtick tracking and instead of updating diagnostics on The changes I made: diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim
index 93d1db4d..9cbf9358 100644
--- a/autoload/youcompleteme.vim
+++ b/autoload/youcompleteme.vim
@@ -478,18 +478,17 @@ function! s:OnFileReadyToParse( ... )
return
endif
- " We only want to send a new FileReadyToParse event notification if the buffer
- " has changed since the last time we sent one, or if forced.
- if force_parsing || b:changedtick != get( b:, 'ycm_changedtick', -1 )
- exec s:python_command "ycm_state.OnFileReadyToParse()"
+ if !s:AllowedToCompleteInCurrentBuffer()
+ return
+ endif
- call timer_stop( s:timers.handle_file_parse_request.id )
- let s:timers.handle_file_parse_request.id = timer_start(
- \ s:timers.handle_file_parse_request.wait_milliseconds,
- \ function( 's:HandleFileParseRequest' ) )
+ exec s:python_command "ycm_state.OnFileReadyToParse()"
+
+ call timer_stop( s:timers.handle_file_parse_request.id )
+ let s:timers.handle_file_parse_request.id = timer_start(
+ \ s:timers.handle_file_parse_request.wait_milliseconds,
+ \ function( 's:HandleFileParseRequest' ) )
- let b:ycm_changedtick = b:changedtick
- endif
endfunction
@@ -549,6 +548,8 @@ function! s:OnTextChangedInsertMode()
if s:omnifunc_mode && !s:Pyeval( 'base.LastEnteredCharIsIdentifierChar()')
let s:omnifunc_mode = 0
endif
+
+ call s:OnFileReadyToParse()
endfunction
@@ -576,7 +577,6 @@ function! s:OnInsertLeave()
endif
let s:omnifunc_mode = 0
- call s:OnFileReadyToParse()
exec s:python_command "ycm_state.OnInsertLeave()"
if g:ycm_autoclose_preview_window_after_completion ||
\ g:ycm_autoclose_preview_window_after_insertion Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file): Previously, bstaletic wrote…
We can't do that as diagnostics constantly updating while typing is rather annoying. Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file): Previously, micbou wrote…
Okay, I understand that some (many?) will find it annoying. I personally don't mind it and don't see it as too distracting. Also, it won't update if a new character is inserted before the update from the previous one. So while "light show" diagnostics is annoying, it really didn't feel like that. Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file): Previously, bstaletic wrote…
Another issue is that we extract identifiers when sending a Comments from Reviewable |
Review status: all files reviewed at latest revision, 4 unresolved discussions. a discussion (no related file): Previously, micbou wrote…
Fair enough. I didn't check for that behaviour. I guess "keep diagnostics until InsertLeave" is a good solution. Comments from Reviewable |
I'm not too worried about the possible backlog @puremourning mentioned. What's the policy on using homu with stale LGTM? And when should one use homu's Review status: all files reviewed at latest revision, 4 unresolved discussions. Comments from Reviewable |
@bstaletic Since there's no Using Review status: all files reviewed at latest revision, 4 unresolved discussions. Comments from Reviewable |
@Valloric Alright, thanks. Do we count the stale LGTM's? I know that Reviewable doesn't count them but still reports thtem and that PR's got merged with stale LGTM or two. |
I am waiting for @puremourning and @vheon to test the PR before marking it as ready. This PR involves code that's not tested and an increase in the Vim version requirement so we need to be careful here.
I do if all discussions are resolved (or can be considered as resolved). Review status: all files reviewed at latest revision, 4 unresolved discussions. Comments from Reviewable |
I'm conflicted. I do want to test this and give it a solid amount of attention, but at the same time (and perhaps more importantly) I absolutely don't want to be a bottleneck to progress. Unfortunately and most regrettably I'm still restricted, so I can't promise a timeframe, but I will try and look at it this week/end. So I think the best plan is to not wait for me if I can't but that I will do what I can, because this is a really fantastic PR and super valuable. |
8672253
to
9e51637
Compare
Small update. I removed the unused Reviewed 1 of 1 files at r4, 1 of 1 files at r5. Comments from Reviewable |
Review status: all files reviewed at latest revision, 5 unresolved discussions. a discussion (no related file): steps to repro: put this in err.cpp
expect: error is displayed
expect: error is displayed
but:
Comments from Reviewable |
I've tried debugging what @puremourning mentioned and here's what I've found. After opening vim and visiting the first buffer for thte first time Moving the cursor around i normal mode doesn't help as diagnostics are not updated no Substitute command ( One more thing I've noticed. For some reason, YCM is issuing 4 I'll try to debug some more after lunch/dinner. |
Actually, I was wrong about |
Reviewed 2 of 2 files at r6. a discussion (no related file): Previously, puremourning (Ben Jackson) wrote…
I've included the changes that parse the initial buffer when the server is ready. This should fix the issue you are experiencing. Comments from Reviewable |
2659eba
to
76972db
Compare
Reviewed 2 of 3 files at r7, 1 of 1 files at r8. autoload/youcompleteme.vim, line 463 at r6 (raw file): Previously, puremourning (Ben Jackson) wrote…
I picked autoload/youcompleteme.vim, line 496 at r6 (raw file): Previously, puremourning (Ben Jackson) wrote…
I renamed it to Comments from Reviewable |
0ecbefb
to
ac80483
Compare
☔ The latest upstream changes (presumably #2639) made this pull request unmergeable. Please resolve the merge conflicts. |
Use the timers feature to display diagnostics asynchronously instead of waiting for an autocommand to trigger. Increase Vim version requirement to 7.4.1578. Drop the CursorHold and CursorHoldI autocommands. Parse buffer on the TextChanged autocommand instead of CursorMoved.
ac80483
to
23a518a
Compare
Reviewed 1 of 3 files at r7, 1 of 1 files at r9, 1 of 1 files at r10, 3 of 3 files at r11, 4 of 4 files at r12. python/ycm/youcompleteme.py, line 768 at r11 (raw file):
Tests added to cover this change. Comments from Reviewable |
Reviewed 1 of 4 files at r1, 2 of 3 files at r11, 3 of 4 files at r12. Comments from Reviewable |
@micbou I see this PR is overflowing with LGTM's, but no READY tag. Feel free to kick off zzbot when you're ready. 👍 Review status: all files reviewed at latest revision, 8 unresolved discussions, some commit checks failed. Comments from Reviewable |
Patch EventNotification instead of BaseRequest in event notification tests.
23a518a
to
26ac0c8
Compare
Next step is to use timers for completions. @zzbot r+ Review status: all files reviewed at latest revision, 6 unresolved discussions, all commit checks successful. Comments from Reviewable |
📌 Commit 26ac0c8 has been approved by |
…cbou [READY] Display diagnostics and parse initial buffer asynchronously using timers Currently, we wait for an autocommand to trigger to display diagnostics. This is not ideal as users have to do some actions like moving the cursor or editing the buffer to see them. We can improve that by using [the timers feature introduced in Vim 7.4.1578](vim/vim@975b527) to display diagnostics asynchronously. Here's a demo: ![ycm-diagnostics-async](https://cloud.githubusercontent.com/assets/10026824/25772105/5aac4706-3263-11e7-8304-643a39599d29.gif) By displaying diagnostics asynchronously, we can drop the `CursorHold` and `CursorHoldI` autocommands as well as [the `g:ycm_allow_changing_updatetime` option](https://github.com/Valloric/YouCompleteMe/blob/5a806dcb301beeeac4df9bb84a4f7e4069d40c43/README.md#the-gycm_allow_changing_updatetime-option). In addition, we can now parse the current buffer and display diagnostics on the `TextChanged` event instead of the `CursorMoved` one. Note that we still need to check `b:changed_tick` for the `InsertLeave` event. Given that our policy is to support the latest version of Ubuntu LTS which is 16.04, and that version [bundles Vim 7.4.1689](http://packages.ubuntu.com/xenial/vim), we can increase our Vim version requirement to 7.4.1578. Next steps will be to use timers for parsing the buffer when the server becomes ready and for completions. Fixes #2165. <!-- 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/2636) <!-- Reviewable:end -->
☀️ Test successful - status-travis |
… r=bstaletic [READY] Completely remove g:ycm_allow_changing_updatetime option Forgot to remove the `g:ycm_allow_changing_updatetime` option from `plugin/youcompleteme.vim` in PR #2636. <!-- 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/2656) <!-- Reviewable:end -->
Correct vim 7.4 patch requirement # PR Prelude Thank you for working on YCM! :) **Please complete these steps and check these boxes (by putting an `x` inside the brackets) _before_ filing your PR:** - [x] I have read and understood YCM's [CONTRIBUTING][cont] document. - [x] I have read and understood YCM's [CODE_OF_CONDUCT][code] document. - [ ] I have included tests for the changes in my PR. If not, I have included a rationale for why I haven't. - [x] **I understand my PR may be closed if it becomes obvious I didn't actually perform all of these steps.** # Why this change is necessary and useful [Please explain **in detail** why the changes in this PR are needed.] With #2636 we bumped minimum required vim version to 7.4.1578, but in one place we didn't change the value. Yes, this PR is just one number change, but inconsitency bothers me. [cont]: https://github.com/Valloric/YouCompleteMe/blob/master/CONTRIBUTING.md [code]: https://github.com/Valloric/YouCompleteMe/blob/master/CODE_OF_CONDUCT.md <!-- 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/2697) <!-- Reviewable:end -->
[READY] Remove obsolete notes in documentation Both notes are obsolete: [libclang correctly returns the type for `auto` since version 3.8](ycm-core/ycmd#353) and diagnostics are automatically refreshed after applying a fix-it since PR #2636. <!-- 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/2782) <!-- Reviewable:end -->
Currently, we wait for an autocommand to trigger to display diagnostics. This is not ideal as users have to do some actions like moving the cursor or editing the buffer to see them. We can improve that by using the timers feature introduced in Vim 7.4.1578 to display diagnostics asynchronously. Here's a demo:
By displaying diagnostics asynchronously, we can drop the
CursorHold
andCursorHoldI
autocommands as well as theg:ycm_allow_changing_updatetime
option. In addition, we can now parse the current buffer and display diagnostics on theTextChanged
event instead of theCursorMoved
one. Note that we still need to checkb:changed_tick
for theInsertLeave
event.Given that our policy is to support the latest version of Ubuntu LTS which is 16.04, and that version bundles Vim 7.4.1689, we can increase our Vim version requirement to 7.4.1578.
Next steps will be to use timers for parsing the buffer when the server becomes ready and for completions.
Fixes #2165.
This change is