Skip to content

Commit

Permalink
feat: support proxy for downloading prebuilt binaries (#1030)
Browse files Browse the repository at this point in the history
* add proxy for downloading libblink_cmp_fuzzy

The Curl command itself does not use system proxies, so use environment variables to avoid not being able to download the blink libraries in some regions.

* feat: load https_proxy env when downloading prebuilt lib

* feat: rename to `proxy.from_env` and `proxy.url`

---------

Co-authored-by: Liam Dyer <[email protected]>
  • Loading branch information
drowning-in-codes and Saghen authored Jan 22, 2025
1 parent 4759c4b commit 6c296e7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lua/blink/cmp/config/fuzzy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
--- @field force_version? string When downloading a prebuilt binary, force the downloader to resolve this version. If this is unset then the downloader will attempt to infer the version from the checked out git tag (if any). WARN: Beware that `main` may be incompatible with the version you select
--- @field force_system_triple? string When downloading a prebuilt binary, force the downloader to use this system triple. If this is unset then the downloader will attempt to infer the system triple from `jit.os` and `jit.arch`. Check the latest release for all available system triples. WARN: Beware that `main` may be incompatible with the version you select
--- @field extra_curl_args string[] Extra arguments that will be passed to curl like { 'curl', ..extra_curl_args, ..built_in_args }
--- @field proxy blink.cmp.PrebuiltBinariesProxyConfig

--- @class (exact) blink.cmp.PrebuiltBinariesProxyConfig
--- @field from_env boolean When downloading a prebuilt binary, use the HTTPS_PROXY environment variable
--- @field url? string When downloading a prebuilt binary, use this proxy URL. This will ignore the HTTPS_PROXY environment variable

--- @alias blink.cmp.SortFunction fun(a: blink.cmp.CompletionItem, b: blink.cmp.CompletionItem): boolean | nil

Expand All @@ -30,6 +35,10 @@ local fuzzy = {
force_version = nil,
force_system_triple = nil,
extra_curl_args = {},
proxy = {
from_env = true,
url = nil,
},
},
},
}
Expand All @@ -54,13 +63,20 @@ function fuzzy.validate(config)
},
prebuilt_binaries = { config.prebuilt_binaries, 'table' },
}, config)

validate('fuzzy.prebuilt_binaries', {
download = { config.prebuilt_binaries.download, 'boolean' },
ignore_version_mismatch = { config.prebuilt_binaries.ignore_version_mismatch, 'boolean' },
force_version = { config.prebuilt_binaries.force_version, { 'string', 'nil' } },
force_system_triple = { config.prebuilt_binaries.force_system_triple, { 'string', 'nil' } },
extra_curl_args = { config.prebuilt_binaries.extra_curl_args, { 'table' } },
proxy = { config.prebuilt_binaries.proxy, 'table' },
}, config.prebuilt_binaries)

validate('fuzzy.prebuilt_binaries.proxy', {
from_env = { config.prebuilt_binaries.proxy.from_env, 'boolean' },
url = { config.prebuilt_binaries.proxy.url, { 'string', 'nil' } },
}, config.prebuilt_binaries.proxy)
end

return fuzzy
3 changes: 3 additions & 0 deletions lua/blink/cmp/config/types_partial.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
--- @field prebuilt_binaries? blink.cmp.PrebuiltBinariesConfigPartial

--- @class (exact) blink.cmp.PrebuiltBinariesConfigPartial : blink.cmp.PrebuiltBinariesConfig, {}
--- @field proxy? blink.cmp.PrebuiltBinariesProxyConfigPartial

--- @class (exact) blink.cmp.PrebuiltBinariesProxyConfigPartial : blink.cmp.PrebuiltBinariesProxyConfig, {}

--- @class blink.cmp.SourceConfigPartial : blink.cmp.SourceConfig, {}
--- @field providers? table<string, blink.cmp.SourceProviderConfigPartial>
Expand Down
9 changes: 9 additions & 0 deletions lua/blink/cmp/fuzzy/download/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ end
function download.download_file(url, filename)
return async.task.new(function(resolve, reject)
local args = { 'curl' }

-- Use https proxy if available
if download_config.proxy.url ~= nil then
vim.list_extend(args, { '--proxy', download_config.proxy.url })
elseif download_config.proxy.from_env then
local proxy_url = os.getenv('HTTPS_PROXY')
if proxy_url ~= nil then vim.list_extend(args, { '--proxy', proxy_url }) end
end

vim.list_extend(args, download_config.extra_curl_args)
vim.list_extend(args, {
'--fail', -- Fail on 4xx/5xx
Expand Down

0 comments on commit 6c296e7

Please sign in to comment.