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

feat: cmp async #1583

Merged
merged 17 commits into from
May 25, 2023
Merged

feat: cmp async #1583

merged 17 commits into from
May 25, 2023

Conversation

folke
Copy link
Contributor

@folke folke commented May 21, 2023

Made part of cmp async.

  • async.new: starts a new coroutine that will resume at most 1ms per vim.loop tick. Returns an Async
  • async.yield: when called from inside a coroutine, this will yield. Does nothing when not in an async context
  • async.wrap: wraps a function that async.new for every invocation
  • Async:await: you can either pass a callback that gets executed when the async finishes, or nil, to synchonously wait and get the result
  • Async:cancel: cancels the running function on next yield
  • source.get_entries: added async.yield in the main loop. This method can still be called from outside an async function, but then it will of course not automatically re-schedule on the loop when taking too long
  • Added some additional checks in source.complete to make sure the context is still the same as the one we're completing
  • updated async.throttle to properly deal with async functions in terms of running and cancelling

This PR removes all stuttering from taildwind (biggest offender).

@folke folke force-pushed the async branch 5 times, most recently from a2b7e07 to b23ad7c Compare May 21, 2023 16:39
@folke
Copy link
Contributor Author

folke commented May 21, 2023

Just fixed the tests. Ready for testing by anyone that feels up for it :)

@folke
Copy link
Contributor Author

folke commented May 21, 2023

@yioneko would be great if you could also review this

@yioneko
Copy link
Contributor

yioneko commented May 22, 2023

Nice work! I believe this will completely remove any user-blocking experience.

lua/cmp/utils/async.lua Outdated Show resolved Hide resolved
lua/cmp/utils/async.lua Show resolved Hide resolved
lua/cmp/source.lua Outdated Show resolved Hide resolved
Copy link
Contributor

@yioneko yioneko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested locally and this works fine for me.

@folke
Copy link
Contributor Author

folke commented May 22, 2023

I removed pre-filtering from source.get_entries and added a new config option view.max_items.

The resulting items in the entries view are now always correct according to the scoring.

See d1136e5

@folke
Copy link
Contributor Author

folke commented May 22, 2023

Contexts can now be aborted. Any running source.get_entries will also abort their async coroutine when their context is aborted. e7872be

@bluz71
Copy link

bluz71 commented May 23, 2023

Just tested out your PR @folke.

Note, I am not authoritative since I only dabble in Tailwind occasionally, but this PR makes nvim-cmp absolutely buttery smooth with the Tailwind Language Server. A beautiful developer experience to code and not stall.

This PR definitely works very well alongside the previous PR; actually in my case this PR has more of an effect than the previous PR; though both compliment each other very well.

Two big thumbs up from me.

Great work @folke and @yioneko.

@folke
Copy link
Contributor Author

folke commented May 23, 2023

Thanks!
@bluz71 What other PR are you referring to?

@bluz71
Copy link

bluz71 commented May 23, 2023

Thanks! @bluz71 What other PR are you referring to?

#1574, "perf(source): only filter up to 200 entries and dont use the cache"

@folke
Copy link
Contributor Author

folke commented May 23, 2023

That pr has been merged already and this pr is a continuation of that pr. It depends on those changes

@folke
Copy link
Contributor Author

folke commented May 23, 2023

I get what you mean now 🙂 Yes, this pr will have a bigger effect. The other pr mainly fixed a memory leak

lua/cmp/config/default.lua Outdated Show resolved Hide resolved
lua/cmp/utils/async.lua Outdated Show resolved Hide resolved
lua/cmp/source.lua Outdated Show resolved Hide resolved
@hrsh7th
Copy link
Owner

hrsh7th commented May 25, 2023

Thank you so much for your PR!

@folke
Copy link
Contributor Author

folke commented May 25, 2023

@hrsh7th did most of the requested changes. For the rest, see my comments. Thank you for reviewing!

@hrsh7th
Copy link
Owner

hrsh7th commented May 25, 2023

It's perfect to me! Thank you again!

@hrsh7th hrsh7th merged commit abb5c75 into hrsh7th:main May 25, 2023
@folke
Copy link
Contributor Author

folke commented May 25, 2023

Awesome, thank you for merging!

williamboman added a commit to williamboman/nvim-cmp that referenced this pull request May 26, 2023
…indow

* upstream/main: (31 commits)
  fix entry highlight in complete-menu (hrsh7th#1593)
  Remove max_item_count from source configuration
  feat: cmp async (hrsh7th#1583)
  ghost text inline (hrsh7th#1588)
  Fix demo video in README.md (hrsh7th#1585)
  docs: fix adjecent typo (hrsh7th#1577)
  docs: fix typos, add confirm.behavior example cfg (hrsh7th#1576)
  perf(source): only filter up to 200 entries and dont use the cache (hrsh7th#1574)
  fix(ghost_text): safely apply virtual_text highlight (hrsh7th#1563)
  Improve misc.merge
  Fix hrsh7th#897
  Added a modified=false to documentation buffer, so it can be removed without E89 errors (hrsh7th#1557)
  Fix hrsh7th#1556
  fix 1533, add regression test (hrsh7th#1558)
  Add `buftype=nofile` for entries_win and docs_win - reddit user mention this...
  Fix hrsh7th#1550
  Format with stylua
  Add test for hrsh7th#1552 Close hrsh7th#1552
  Revert hrsh7th#1534 temporaly
  fix typo (hrsh7th#1551)
  ...
choplin added a commit to choplin/dotfiles that referenced this pull request May 28, 2023
This is because after hrsh7th/nvim-cmp#1583 was
merged,
plugins that cannot work within the lua event loop cause an error.
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.

5 participants