From ec0c90875929f8bd9cb42f2d5a5befc40b39cfc7 Mon Sep 17 00:00:00 2001 From: Stefan Boca Date: Wed, 26 Feb 2025 15:26:55 -0800 Subject: [PATCH 1/2] fix(download): correctly handle `download = false` and `implementation = "rust"` Previously, this set of options would result in the lua implementation being used. The new flow should be more linear and easy to follow. --- lua/blink/cmp/fuzzy/download/init.lua | 108 +++++++++++++++----------- 1 file changed, 63 insertions(+), 45 deletions(-) diff --git a/lua/blink/cmp/fuzzy/download/init.lua b/lua/blink/cmp/fuzzy/download/init.lua index f5a4ec36..dfc9d0fa 100644 --- a/lua/blink/cmp/fuzzy/download/init.lua +++ b/lua/blink/cmp/fuzzy/download/init.lua @@ -11,7 +11,7 @@ local download = {} function download.ensure_downloaded(callback) callback = vim.schedule_wrap(callback) - if not download_config.download or fuzzy_config.implementation == 'lua' then return callback(nil, 'lua') end + if fuzzy_config.implementation == 'lua' then return callback(nil, 'lua') end async.task .await_all({ git.get_version(), files.get_version() }) @@ -24,53 +24,74 @@ function download.ensure_downloaded(callback) :map(function(version) local target_git_tag = download_config.force_version or version.git.tag - -- not built locally, not on a git tag, error - assert( - version.current.sha ~= nil or target_git_tag ~= nil, - "\nDetected an out of date or missing fuzzy matching library. Can't download from github due to not being on a git tag and no `fuzzy.prebuilt_binaries.force_version` is set." - .. '\nEither run `cargo build --release` via your package manager, switch to a git tag, or set `fuzzy.prebuilt_binaries.force_version` in config. ' - .. 'See the docs for more info.' - ) + -- built locally + if version.current.sha ~= nil then + -- up to date or version ignored, ignore + if version.current.sha == version.git.sha or download_config.ignore_version_mismatch then return end - -- built locally, ignore - if - not download_config.force_version - and ( - version.current.sha == version.git.sha - or version.current.sha ~= nil and download_config.ignore_version_mismatch + -- out of date + vim.schedule( + function() + vim.notify( + '[blink.cmp]: Found an outdated version of the locally built fuzzy matching library', + vim.log.levels.WARN, + { title = 'blink.cmp' } + ) + end ) - then - return - end - -- built locally but outdated and not on a git tag, error - if - not download_config.force_version - and version.current.sha ~= nil - and version.current.sha ~= version.git.sha - then - assert( - target_git_tag or download_config.ignore_version_mismatch, - "\nFound an outdated version of the fuzzy matching library, but can't download from github due to not being on a git tag. " - .. '\n!! FOR DEVELOPERS !!, set `fuzzy.prebuilt_binaries.ignore_version_mismatch = true` in config. ' - .. '\n!! FOR USERS !!, either run `cargo build --release` via your package manager, switch to a git tag, or set `fuzzy.prebuilt_binaries.force_version` in config. ' - .. 'See the docs for more info.' - ) - if not download_config.ignore_version_mismatch then - vim.schedule( - function() - vim.notify( - '[blink.cmp]: Found an outdated version of the fuzzy matching library built locally', - vim.log.levels.INFO, - { title = 'blink.cmp' } - ) - end + -- downloading enabled but not on a git tag, error + if download_config.download and target_git_tag == nil then + error( + "Found an outdated version of the fuzzy matching library, but can't download from github due to not being on a git tag." + .. '\n!! FOR DEVELOPERS !!, set `fuzzy.prebuilt_binaries.ignore_version_mismatch = true` in config.' + .. '\n!! FOR USERS !!, either run `cargo build --release` via your package manager, switch to a git tag, or set `fuzzy.prebuilt_binaries.force_version` in config.' + .. '\nSee the docs for more info.' + ) + + -- downloading is disabled, error + else + error( + 'Found an outdated version of the fuzzy matching library, but downloading from github is disabled.' + .. '\n!! FOR DEVELOPERS !!, set `fuzzy.prebuilt_binaries.ignore_version_mismatch = true` in config.' + .. '\n!! FOR USERS !!, either run `cargo build --release` via your package manager, or set either `fuzzy.prebuilt_binaries.download = true` or `fuzzy.prebuilt_binaries.force_version` in config.' + .. '\nSee the docs for more info.' ) end end + -- downloading disabled but not built locally + if not download_config.download then + vim.schedule( + function() + vim.notify('[blink.cmp]: No fuzzy matching library found', vim.log.levels.WARN, { title = 'blink.cmp' }) + end + ) + + error( + 'No fuzzy matching library found, but downloading from github is disabled.' + .. '\nEither run `cargo build --release` via your package manager, or set `fuzzy.prebuilt_binaries.download = true` in config.' + .. '\nSee the docs for more info.' + ) + end + + -- downloading enabled but not on a git tag + if target_git_tag == nil then + vim.schedule( + function() + vim.notify('[blink.cmp]: No fuzzy matching library found', vim.log.levels.WARN, { title = 'blink.cmp' }) + end + ) + + error( + "No fuzzy matching library found, but can't download from github due to not being on a git tag and no `fuzzy.prebuilt_binaries.force_version` is set." + .. '\nEither run `cargo build --release` via your package manager, switch to a git tag, or set `fuzzy.prebuilt_binaries.force_version` in config.' + .. '\nSee the docs for more info.' + ) + end + -- already downloaded and the correct version, just verify the checksum, and re-download if checksum fails - if version.current.tag ~= nil and version.current.tag == target_git_tag then + if version.current.tag == target_git_tag then return files.verify_checksum():catch(function(err) vim.schedule(function() vim.notify(err, vim.log.levels.WARN, { title = 'blink.cmp' }) @@ -84,9 +105,6 @@ function download.ensure_downloaded(callback) end) end - -- unknown state - if not target_git_tag then error('Unknown error while getting pre-built binary. Consider re-installing') end - -- download as per usual vim.schedule( function() vim.notify('[blink.cmp]: Downloading pre-built binary', vim.log.levels.INFO, { title = 'blink.cmp' }) end @@ -103,12 +121,12 @@ function download.ensure_downloaded(callback) elseif fuzzy_config.implementation == 'prefer_rust_with_warning' then vim.schedule(function() vim.notify( - '[blink.cmp]: Falling back to Lua implementation due to error while downloading pre-built binary: ' .. err, + '[blink.cmp]: Falling back to Lua implementation due to error while downloading pre-built binary:\n' .. err, vim.log.levels.WARN, { title = 'blink.cmp' } ) vim.notify( - "[blink.cmp]: Set `fuzzy.implementation = 'prefer_rust' | 'lua'` to suppress this warning", + "[blink.cmp]: Set `fuzzy.implementation = 'prefer_rust' | 'lua'` to suppress this warning.", vim.log.levels.WARN, { title = 'blink.cmp' } ) From 5d5e2f5fd830c34ca7ac2f6c06c22dd15c7d08ab Mon Sep 17 00:00:00 2001 From: Liam Dyer Date: Thu, 27 Feb 2025 10:57:35 -0500 Subject: [PATCH 2/2] fix: download when on git tag with out of date locally built --- lua/blink/cmp/fuzzy/download/init.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lua/blink/cmp/fuzzy/download/init.lua b/lua/blink/cmp/fuzzy/download/init.lua index dfc9d0fa..192bef5f 100644 --- a/lua/blink/cmp/fuzzy/download/init.lua +++ b/lua/blink/cmp/fuzzy/download/init.lua @@ -41,13 +41,15 @@ function download.ensure_downloaded(callback) ) -- downloading enabled but not on a git tag, error - if download_config.download and target_git_tag == nil then - error( - "Found an outdated version of the fuzzy matching library, but can't download from github due to not being on a git tag." - .. '\n!! FOR DEVELOPERS !!, set `fuzzy.prebuilt_binaries.ignore_version_mismatch = true` in config.' - .. '\n!! FOR USERS !!, either run `cargo build --release` via your package manager, switch to a git tag, or set `fuzzy.prebuilt_binaries.force_version` in config.' - .. '\nSee the docs for more info.' - ) + if download_config.download then + if target_git_tag == nil then + error( + "Found an outdated version of the fuzzy matching library, but can't download from github due to not being on a git tag." + .. '\n!! FOR DEVELOPERS !!, set `fuzzy.prebuilt_binaries.ignore_version_mismatch = true` in config.' + .. '\n!! FOR USERS !!, either run `cargo build --release` via your package manager, switch to a git tag, or set `fuzzy.prebuilt_binaries.force_version` in config.' + .. '\nSee the docs for more info.' + ) + end -- downloading is disabled, error else