Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ https://github.com/user-attachments/assets/5d0e1ce9-642c-4c44-aa88-01b05bb86abb
```lua
{
'dmtrKovalenko/fff.nvim',
version = 'v0.10.0',
build = function()
-- downloads a prebuilt binary or falls back to cargo build
require("fff.download").download_or_build_binary()
-- Downloads a prebuilt binary or falls back to `cargo build --release`.
-- Pass the same value you set as `version` above to guarantee the binary
-- matches the pinned Lua code. Omit to derive the tag from the checked-out
-- commit.
require("fff.download").download_or_build_binary({ version = 'v0.10.0' })
end,
-- for nixos:
-- build = "nix run .#release",
Expand Down
18 changes: 15 additions & 3 deletions lua/fff/download.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,23 @@ function M.build_binary(callback)
end)
end

function M.download_or_build_binary()
--- opts.version pins the GitHub release tag (accepts "0.10.0" or "v0.10.0").
--- When omitted the tag is derived from the checked-out git ref.
---@param opts? { version?: string, proxy?: string, extra_curl_args?: string[], timeout_ms?: integer }
function M.download_or_build_binary(opts)
opts = opts or {}
local ensure_opts = { force = true, proxy = opts.proxy, extra_curl_args = opts.extra_curl_args }
if type(opts.version) == 'string' and opts.version ~= '' then
local v = opts.version
-- Stable release tags are `v<semver>`; nightly/dev per-sha tags are unprefixed.
if v:match('^%d+%.%d+%.%d+$') then v = 'v' .. v end
ensure_opts.version = v
end

local done = false
local fatal_error = nil

M.ensure_downloaded({ force = true }, function(download_success, download_error)
M.ensure_downloaded(ensure_opts, function(download_success, download_error)
if download_success then
done = true
return
Expand Down Expand Up @@ -267,7 +279,7 @@ function M.download_or_build_binary()
-- and if Neovim exits before the final rename(tmp → libfff_nvim.{dylib,so,dll})
-- executes, the binary is never written to disk. vim.wait pumps the event
-- loop so all vim.system / vim.schedule callbacks can fire.
local timeout_ms = 1000 * 60 * 2 -- 2 minutes
local timeout_ms = opts.timeout_ms or (1000 * 60 * 2) -- default: 2 minutes
local ok, wait_err = vim.wait(timeout_ms, function() return done end, 100)
if not ok and wait_err == -2 then error('fff.nvim: download_or_build_binary timed out') end

Expand Down
Loading