-
-
Notifications
You must be signed in to change notification settings - Fork 856
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
smooth one-shot finder #1853
base: master
Are you sure you want to change the base?
smooth one-shot finder #1853
Conversation
This problems is a problem with I dont wanna comment on this prior to #1491 (just tested it with that PR and it also seems to be fixed using that branch). This PR completely changes the rendering. Thanks for the PR thought :) CC @tjdevries |
I've seen #1491 :) but I dont know how soon it will be on master. Indeed the small fix I made is because of ascending vs descending. And this fix might then soon be obsolete. And admittedly very ad-hoc and messy. However, the changes on |
-- TODO ok something is very wrong here, scheduler waits until we are on the main thread? then we always need it | ||
-- or should process_result do it itself, because they want to call vim.api stuff | ||
-- original did something like every 1000 iterations, but that makes no sense because you dont know how fast is your command | ||
-- how does this relate to await_schedule()? ah the same. just an alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason the old one did every 1000 iterations was because it was expensive to do it every single time for something that might be called a million times.
We could do some testing to see how this fairs, but I'm hesitant to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tested it with the above script producing 1M entries, it was still super fast and very responsive, but my current machine is very up-to-date. I'm not saying we need it every single time, my problem is that I dont quite understand what's happening. Maybe you can help me:
Inside the process_result
callback we do call vim.api.nvim_*
functions. There are restrictions on when you can call nvim apis, right? Something like "It is an error to directly invoke vim.api functions in vim.loop callbacks.". I'm not sure in what context is the finder running in (an "libuv/plenary async" thread?) and if from that context I can call vim apis. Without the scheduler it sometimes failed trying to call the vim api.
What is async.util.scheduler()
doing? Maybe then I get it. Plenary says "An async function that when awaited will await the scheduler to be able to call the api." Does that mean that my thread is yielding until it can be scheduled on the vim main thread and then I can call vim apis safely? That would mean only right after scheduler()
because if something else yields on my thread I might already again be off the main thread?
c1ef522
to
3cfec52
Compare
Sadly, this is still an issue :) I tried it with |
I'm trying to improve responsiveness and smoothness of the user experience if you have slow one-shot finders. Slow because the command you run is slow, not slow because the actual lua code is heavy.
If you use a finder like this
and you have this script in your path
then, on current master, you'll notice a bumpy ride:
picker
indropdown
mode.There is still a pretty big
TODO
comment inasync_oneshot_finder.lua
where I'm still a bit lost. Overall I'm not very robust onplenary
,libuv
, and the whole async stuff. But I noticed that sometimesprocess_results(...)
fails because it tries inside to callvim.api
functions and that is only allowed (?) when we are on the main event-loop. Originallyasync.util.scheduler()
was only called every1000
entries or so. But if I do that I occasionally get the problem withvim.api
calls. I dont quite understand what thescheduler()
is doing.