diff options
| author | William Boman <william@redwill.se> | 2022-01-07 12:18:47 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-07 12:18:47 +0100 |
| commit | 648437aafae63eda06097113c836a8d9ad6f23c1 (patch) | |
| tree | 52d1ff402bf62dcd3616b795cde3ba7c4c1c0f35 /lua | |
| parent | fix(ui): less intrusive version check UI (#402) (diff) | |
| download | mason-648437aafae63eda06097113c836a8d9ad6f23c1.tar mason-648437aafae63eda06097113c836a8d9ad6f23c1.tar.gz mason-648437aafae63eda06097113c836a8d9ad6f23c1.tar.bz2 mason-648437aafae63eda06097113c836a8d9ad6f23c1.tar.lz mason-648437aafae63eda06097113c836a8d9ad6f23c1.tar.xz mason-648437aafae63eda06097113c836a8d9ad6f23c1.tar.zst mason-648437aafae63eda06097113c836a8d9ad6f23c1.zip | |
feat: integrate gh-cli for GitHub API calls (#403)
Closes #248.
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-lsp-installer/core/clients/github.lua | 14 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/fetch.lua | 15 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/ui/status-win/init.lua | 2 |
3 files changed, 27 insertions, 4 deletions
diff --git a/lua/nvim-lsp-installer/core/clients/github.lua b/lua/nvim-lsp-installer/core/clients/github.lua index 080edbb0..27352e8d 100644 --- a/lua/nvim-lsp-installer/core/clients/github.lua +++ b/lua/nvim-lsp-installer/core/clients/github.lua @@ -19,7 +19,12 @@ function M.fetch_releases(repo, callback) return callback("Failed to fetch GitHub releases.", nil) end callback(nil, vim.json.decode(response)) - end) + end, { + custom_fetcher = { + cmd = "gh", + args = { "api", ("repos/%s/releases"):format(repo) }, + }, + }) end ---@alias FetchLatestGithubReleaseOpts {tag_name_pattern:string} @@ -62,7 +67,12 @@ function M.fetch_tags(repo, callback) return callback("Failed to fetch tags.", nil) end callback(nil, vim.json.decode(response)) - end) + end, { + custom_fetcher = { + cmd = "gh", + args = { "api", ("repos/%s/tags"):format(repo) }, + }, + }) end ---@param repo string The GitHub repo ("username/repo"). diff --git a/lua/nvim-lsp-installer/core/fetch.lua b/lua/nvim-lsp-installer/core/fetch.lua index 3e601cb6..981ad376 100644 --- a/lua/nvim-lsp-installer/core/fetch.lua +++ b/lua/nvim-lsp-installer/core/fetch.lua @@ -4,7 +4,9 @@ local platform = require "nvim-lsp-installer.platform" ---@param url string The url to fetch. ---@param callback fun(err: string|nil, raw_data: string) -local function fetch(url, callback) +---@param opts {custom_fetcher: { cmd: string, args: string[] }} +local function fetch(url, callback, opts) + opts = opts or {} local stdio = process.in_memory_sink() log.fmt_debug("Fetching URL %s", url) local on_exit = function(success) @@ -45,6 +47,17 @@ local function fetch(url, callback) ) end + if opts.custom_fetcher then + table.insert( + job_variants, + 1, + process.lazy_spawn(opts.custom_fetcher.cmd, { + args = opts.custom_fetcher.args, + stdio_sink = stdio.sink, + }) + ) + end + process.attempt { jobs = job_variants, on_iterate = function() diff --git a/lua/nvim-lsp-installer/ui/status-win/init.lua b/lua/nvim-lsp-installer/ui/status-win/init.lua index cb1f59f4..937c6c3f 100644 --- a/lua/nvim-lsp-installer/ui/status-win/init.lua +++ b/lua/nvim-lsp-installer/ui/status-win/init.lua @@ -20,7 +20,7 @@ local function ServerGroupHeading(props) { { props.title, props.highlight or "LspInstallerHeading" }, { " (" .. props.count .. ") ", "Comment" }, - { props.subtitle and props.subtitle or "", "Comment" }, + { props.subtitle or "", "Comment" }, }, } end |
