diff options
| author | Tom Ampuero <46233260+tampueroc@users.noreply.github.com> | 2025-07-13 21:43:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-13 13:43:11 -0700 |
| commit | 7cd5356a6f89a46d83bbba9b7f6496b67f054629 (patch) | |
| tree | 04ac6a86e7419297e8ff3e7eb765b4e987a91181 /runtime/lua/vim/_editor.lua | |
| parent | 444a8b3ec6375b03f1483a97095a00b067a499ec (diff) | |
feat(net): vim.net.request(), :edit [url] #34140
Problem:
Nvim depends on netrw to download/request URL contents.
Solution:
- Add `vim.net.request()` as a thin curl wrapper:
- Basic GET with --silent, --show-error, --fail, --location, --retry
- Optional `opts.outpath` to save to a file
- Operates asynchronously. Pass an `on_response` handler to get the result.
- Add integ tests (requires NVIM_TEST_INTEG to be set) to test success
and 404 failure.
- Health check for missing `curl`.
- Handle `:edit https://…` using `vim.net.request()`.
API Usage:
1. Asynchronous request:
vim.net.request('https://httpbingo.org/get', { retry = 2 }, function(err, response)
if err then
print('Fetch failed:', err)
else
print('Got body of length:', #response.body)
end
end)
2. Download to file:
vim.net.request('https://httpbingo.org/get', { outpath = 'out_async.txt' }, function(err)
if err then print('Error:', err) end
end)
3. Remote :edit integration (in runtime/plugin/net.lua) fetches into buffer:
:edit https://httpbingo.org/get
Diffstat (limited to 'runtime/lua/vim/_editor.lua')
| -rw-r--r-- | runtime/lua/vim/_editor.lua | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index dd9fc221d1..50fac8cf9e 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -41,6 +41,7 @@ for k, v in pairs({ snippet = true, pack = true, _watch = true, + net = true, }) do vim._submodules[k] = v end |
