Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add proxy for downloading libblink_cmp_fuzzy #1030

Merged
merged 5 commits into from
Jan 22, 2025
Merged
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
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
Loading