feat(picker): automatically download sqlite3.dll on Windows when using frecency / history for the first time.

This commit is contained in:
Folke Lemaitre 2025-02-03 08:59:00 +01:00
parent adf93a32ae
commit 65907f75ba
No known key found for this signature in database
GPG key ID: 36B7C1C85AAC487F
2 changed files with 36 additions and 1 deletions

View file

@ -31,6 +31,12 @@ function M.health()
if not have_fd then
Snacks.health.warn("'fd' is required for `Snacks.picker.explorer()`")
end
local ok = pcall(require, "snacks.picker.util.db")
if ok then
Snacks.health.ok("`SQLite3` is available")
else
Snacks.health.warn("`SQLite3` is not available. Frecency and history will be stored in a file instead.")
end
end
return M

View file

@ -19,7 +19,36 @@ ffi.cdef([[
long long sqlite3_column_int64(sqlite3_stmt*, int);
]])
local sqlite = ffi.load("sqlite3")
local function sqlite3_lib()
if jit.os ~= "Windows" then
return "sqlite3"
end
local sqlite_path = vim.fn.stdpath("cache") .. "\\sqlite3.dll"
if vim.fn.filereadable(sqlite_path) == 0 then
Snacks.notify("Downloading `sqlite3.dll`")
local url = ("https://www.sqlite.org/2025/sqlite-dll-win-%s-3480000.zip"):format(jit.arch)
local out = vim.fn.system({
"powershell",
"-Command",
[[
$url = "]] .. url .. [[";
$zipPath = "$env:TEMP\sqlite.zip";
$extractPath = "$env:TEMP\sqlite";
Invoke-WebRequest -Uri $url -OutFile $zipPath;
Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force;
Move-Item -Path "$extractPath\sqlite3.dll" -Destination "]] .. sqlite_path .. [[" -Force
]],
})
if vim.v.shell_error ~= 0 then
Snacks.notify.error("Failed to download `sqlite3.dll`:\n" .. out)
else
Snacks.notify("Downloaded `sqlite3.dll`")
end
end
return sqlite_path
end
local sqlite = ffi.load(sqlite3_lib())
---@alias sqlite3* ffi.cdata*
---@alias sqlite3_stmt* ffi.cdata*