Skip to content

Commit

Permalink
Add config to explicitly specify the dll version (Saghen#36)
Browse files Browse the repository at this point in the history
This adds a new `fuzzy.prebuiltBinaries` config table which allows:

1. Enabling or disabling the dll downloader
2. Explicitly specifying the version to download

This is useful if I want to track master without needing to run
`cargo build --release`.
  • Loading branch information
julienvincent authored and lopi-py committed Oct 10, 2024
1 parent 151c2f8 commit 45f73ac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ For LazyVim/distro users, you can disable nvim-cmp via:
max_items = 200,
-- controls which sorts to use and in which order, these three are currently the only allowed options
sorts = { 'label', 'kind', 'score' },

prebuiltBinaries = {
-- Whether or not to automatically download a prebuilt binary from github. If this is set to `false`
-- you will need to manually build the fuzzy binary dependencies by running `cargo build --release`
download = true,
-- When downloading a prebuilt binary force the downloader to resolve this version. If this is uset
-- then the downloader will attempt to infer the version from the checked out git tag (if any).
--
-- Beware that if the FFI ABI changes while tracking main then this may result in blink breaking.
forceVersion = nil,
},
},

sources = {
Expand Down
15 changes: 15 additions & 0 deletions lua/blink/cmp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@
--- @field enabled boolean
--- @field priority number

--- @class blink.cmp.PrebuiltBinariesConfig
--- @field download boolean
--- @field forceVersion string | nil

--- @class blink.cmp.FuzzyConfig
--- @field use_frecency boolean
--- @field use_proximity boolean
--- @field max_items number
--- @field sorts ("label" | "kind" | "score")[]
--- @field prebuiltBinaries blink.cmp.PrebuiltBinariesConfig

--- @class blink.cmp.WindowConfig
--- @field autocomplete blink.cmp.AutocompleteConfig
Expand Down Expand Up @@ -201,6 +206,16 @@ local config = {
max_items = 200,
-- controls which sorts to use and in which order, these three are currently the only allowed options
sorts = { 'label', 'kind', 'score' },
prebuiltBinaries = {
-- Whether or not to automatically download a prebuilt binary from github. If this is set to `false`
-- you will need to manually build the fuzzy binary dependencies by running `cargo build --release`
download = true,
-- When downloading a prebuilt binary force the downloader to resolve this version. If this is uset
-- then the downloader will attempt to infer the version from the checked out git tag (if any).
--
-- Beware that if the FFI ABI changes while tracking main then this may result in blink breaking.
forceVersion = nil,
},
},

sources = {
Expand Down
20 changes: 14 additions & 6 deletions lua/blink/cmp/fuzzy/download.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local download_config = require('blink.cmp.config').fuzzy.prebuiltBinaries

local download = {}

--- @return string
Expand All @@ -17,28 +19,34 @@ function download.ensure_downloaded(callback)
vim.schedule(function() callback(err) end)
end

if not download_config.download then return cb() end

download.get_git_tag(function(git_version_err, git_version)
if git_version_err then return cb(git_version_err) end

download.get_downloaded_version(function(version_err, version)
download.is_downloaded(function(downloaded)
local target_version = download_config.forceVersion or git_version

-- not built locally, not a git tag, error
if not downloaded and not git_version then
if not downloaded and not target_version then
return cb(
"Can't download from github due to not being on a git tag but found no built version of the library. Either run cargo build --release via your package manager or switch to a git tag. See the README for more info."
"Can't download from github due to not being on a git tag and no native_download.version set, but found no built version of the library. "
.. 'Either run `cargo build --release` via your package manager, switch to a git tag, or set `native_download.version` in config. '
.. 'See the README for more info.'
)
end
-- built locally, ignore
if downloaded and (version_err or version == nil) then return cb() end
-- already downloaded and the correct version
if version == git_version and downloaded then return cb() end
if version == target_version and downloaded then return cb() end
-- unknown state
if not git_version then return cb('Unknown error while getting pre-built binary. Consider re-installing') end
if not target_version then return cb('Unknown error while getting pre-built binary. Consider re-installing') end

-- download from github and set version
download.from_github(git_version, function(download_err)
download.from_github(target_version, function(download_err)
if download_err then return cb(download_err) end
download.set_downloaded_version(git_version, function(set_err)
download.set_downloaded_version(target_version, function(set_err)
if set_err then return cb(set_err) end
cb()
end)
Expand Down

0 comments on commit 45f73ac

Please sign in to comment.