-
Notifications
You must be signed in to change notification settings - Fork 8
feat: remove plenary.nvim dependency
#54
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,42 +1,208 @@ | ||||||||||||||||||||
| local a = require("plenary.async") | ||||||||||||||||||||
|
|
||||||||||||||||||||
| local async = { | ||||||||||||||||||||
| run = a.run, | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ---run function in async context, until timeout or complete | ||||||||||||||||||||
| ---@param suspend_fn fun() | ||||||||||||||||||||
| ---@param callback fun(success, ret_val) | ||||||||||||||||||||
| ---@param timeout number? | ||||||||||||||||||||
| run_blocking = function(suspend_fn, callback, timeout) | ||||||||||||||||||||
| local resolved = false | ||||||||||||||||||||
| local msg | ||||||||||||||||||||
| vim.schedule(function() | ||||||||||||||||||||
| a.run(suspend_fn, function(data) | ||||||||||||||||||||
| msg = data | ||||||||||||||||||||
| resolved = true | ||||||||||||||||||||
| end) | ||||||||||||||||||||
| local a = require("vim._async") | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| --- @brief Neopyter's async module, which provides async functions and utilities for Neopyter. | ||||||||||||||||||||
| --- Which is built on top of native async support (`vim._async`) in Neovim, and provides a more convenient API for users to use async functions in Neopyter. | ||||||||||||||||||||
| --- The API of neopyter are mostly async, and users could call them in a sync context, neopyter will automatically wrap them in an async context, so | ||||||||||||||||||||
| --- that users could call them directly without worrying about async context, but the order of execution is not guaranteed, if you want to guarantee | ||||||||||||||||||||
| --- the order of execution, you should use `require("neopyter.async").run(...)` to run them in an async context. | ||||||||||||||||||||
|
Comment on lines
+1
to
+9
|
||||||||||||||||||||
| --- | ||||||||||||||||||||
| --- Example1: Call API in sync context, but the order of execution is not guaranteed | ||||||||||||||||||||
| --- ```lua | ||||||||||||||||||||
| --- vim.defer_fn(function() | ||||||||||||||||||||
| --- -- non-async context, API response may be unordered | ||||||||||||||||||||
| --- current_notebook:run_selected_cell() | ||||||||||||||||||||
| --- current_notebook:run_all_above() | ||||||||||||||||||||
| --- current_notebook:run_all_below() | ||||||||||||||||||||
| --- end, 0) | ||||||||||||||||||||
| --- Example2: Call API in async context, the order of execution is guaranteed | ||||||||||||||||||||
| --- require("neopyter.async").run(function() | ||||||||||||||||||||
| --- -- async context, so which will call and return in order | ||||||||||||||||||||
| --- current_notebook:run_selected_cell() | ||||||||||||||||||||
| --- current_notebook:run_all_above() | ||||||||||||||||||||
| --- current_notebook:run_all_below() | ||||||||||||||||||||
| --- end) | ||||||||||||||||||||
| --- ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| local async = {} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ---Creates an async function with a callback style function. | ||||||||||||||||||||
| ---@param func function: A callback style function to be converted. The last argument must be the callback. | ||||||||||||||||||||
| ---@param argc number: The number of arguments of func. Must be included. | ||||||||||||||||||||
| ---@return async fun: Returns an async function | ||||||||||||||||||||
| function async.wrap(func, argc) | ||||||||||||||||||||
| ---@async | ||||||||||||||||||||
| return function(...) | ||||||||||||||||||||
| return a.await(argc, func, ...) | ||||||||||||||||||||
| end | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
||||||||||||||||||||
| async.scheduler = async.wrap(vim.schedule, 1) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function async.safe_async() | ||||||||||||||||||||
| if vim.in_fast_event() then | ||||||||||||||||||||
| async.scheduler() | ||||||||||||||||||||
| end | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ---Use this to either run a future concurrently and then do something else | ||||||||||||||||||||
| ---or use it to run a future with a callback in a non async context | ||||||||||||||||||||
| ---@param func async fun(): ...:any | ||||||||||||||||||||
| ---@param on_finish? fun(err: string?, ...:any) | ||||||||||||||||||||
| function async.run(func, on_finish) | ||||||||||||||||||||
| if on_finish == nil then | ||||||||||||||||||||
| on_finish = function(err) | ||||||||||||||||||||
| if err then | ||||||||||||||||||||
| error(err) | ||||||||||||||||||||
| end | ||||||||||||||||||||
| end | ||||||||||||||||||||
| end | ||||||||||||||||||||
| a.run(func, on_finish) | ||||||||||||||||||||
| end | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ---run function in async context, until timeout or complete | ||||||||||||||||||||
| ---@param suspend_fn fun() | ||||||||||||||||||||
| ---@param on_finish? fun(err: string?, ...:any) | ||||||||||||||||||||
| ---@param timeout number? | ||||||||||||||||||||
| function async.run_blocking(suspend_fn, on_finish, timeout) | ||||||||||||||||||||
|
||||||||||||||||||||
| function async.run_blocking(suspend_fn, on_finish, timeout) | |
| function async.run_blocking(suspend_fn, on_finish, timeout) | |
| if on_finish == nil then | |
| on_finish = function(err) | |
| if err then | |
| error(err) | |
| end | |
| end | |
| end |
Copilot
AI
Apr 20, 2026
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.
fs_opendir wrapper uses an undefined uv identifier, so this module will error on load. Use vim.uv (or a local uv = vim.uv) and keep the argument order consistent with vim.uv.fs_opendir’s signature.
| return uv.fs_opendir(path, callback, entries) | |
| return vim.uv.fs_opendir(path, entries, callback) |
Copilot
AI
Apr 20, 2026
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.
add("shutdown", 2) is listed twice in the stream section, which is redundant and makes the wrapper list harder to maintain. Remove the duplicate entry (or replace it with the intended missing wrapper if this was a copy/paste).
| add("shutdown", 2) |
Copilot
AI
Apr 20, 2026
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.
async.run invokes callbacks as (err, ...), but the callback passed here is function(result) so result will actually receive the error value and successful return values will be shifted/dropped. Update the callback signature to accept (err, result) (and handle err) so notifications/logging reflect the real result.
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 PR switches the runtime async implementation away from plenary and relies on newer built-in Neovim primitives (e.g.
vim._async,vim.uv,vim.packin scripts). The README currently says “latest stable or nightly” but doesn’t state a minimum Neovim version required for these APIs; please document the minimum supported Neovim version so users know what they need.