diff options
| author | William Boman <william@redwill.se> | 2022-01-06 18:21:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-06 18:21:19 +0100 |
| commit | 5cc73ef7360866c65169e0e7d55d3b59fb3b6eaa (patch) | |
| tree | b958f26ae3964e7ba8aa3572b81ece1e23b49df1 /lua/nvim-lsp-installer/core | |
| parent | rerun autogen (diff) | |
| download | mason-5cc73ef7360866c65169e0e7d55d3b59fb3b6eaa.tar mason-5cc73ef7360866c65169e0e7d55d3b59fb3b6eaa.tar.gz mason-5cc73ef7360866c65169e0e7d55d3b59fb3b6eaa.tar.bz2 mason-5cc73ef7360866c65169e0e7d55d3b59fb3b6eaa.tar.lz mason-5cc73ef7360866c65169e0e7d55d3b59fb3b6eaa.tar.xz mason-5cc73ef7360866c65169e0e7d55d3b59fb3b6eaa.tar.zst mason-5cc73ef7360866c65169e0e7d55d3b59fb3b6eaa.zip | |
feat(ui): display outdated servers (#395)
Diffstat (limited to 'lua/nvim-lsp-installer/core')
| -rw-r--r-- | lua/nvim-lsp-installer/core/clients/eclipse.lua | 21 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/clients/github.lua | 82 | ||||
| -rw-r--r-- | lua/nvim-lsp-installer/core/receipt.lua | 64 |
3 files changed, 154 insertions, 13 deletions
diff --git a/lua/nvim-lsp-installer/core/clients/eclipse.lua b/lua/nvim-lsp-installer/core/clients/eclipse.lua new file mode 100644 index 00000000..a788f2e2 --- /dev/null +++ b/lua/nvim-lsp-installer/core/clients/eclipse.lua @@ -0,0 +1,21 @@ +local fetch = require "nvim-lsp-installer.core.fetch" +local M = {} + +---@param version string The version string as found in the latest.txt endpoint. +---@return string The parsed version number. +function M._parse_jdtls_version_string(version) + return vim.trim(version):gsub("^jdt%-language%-server%-", ""):gsub("%.tar%.gz$", "") +end + +---@param callback fun(err: string|nil, data: string|nil) +function M.fetch_latest_jdtls_version(callback) + fetch("https://download.eclipse.org/jdtls/snapshots/latest.txt", function(err, data) + if err then + callback(err, nil) + else + callback(nil, M._parse_jdtls_version_string(data)) + end + end) +end + +return M diff --git a/lua/nvim-lsp-installer/core/clients/github.lua b/lua/nvim-lsp-installer/core/clients/github.lua new file mode 100644 index 00000000..080edbb0 --- /dev/null +++ b/lua/nvim-lsp-installer/core/clients/github.lua @@ -0,0 +1,82 @@ +local fetch = require "nvim-lsp-installer.core.fetch" +local Data = require "nvim-lsp-installer.data" +local log = require "nvim-lsp-installer.log" + +local list_find_first = Data.list_find_first + +local M = {} + +---@alias GitHubRelease {tag_name:string, prerelease: boolean, draft: boolean} +---@alias GitHubTag {name: string} + +---@param repo string The GitHub repo ("username/repo"). +---@param callback fun(error: string|nil, data: GitHubRelease[]|nil) +function M.fetch_releases(repo, callback) + log.fmt_trace("Fetching GitHub releases for repo=%s", repo) + fetch(("https://api.github.com/repos/%s/releases"):format(repo), function(err, response) + if err then + log.fmt_error("Failed to fetch releases for repo=%s", repo) + return callback("Failed to fetch GitHub releases.", nil) + end + callback(nil, vim.json.decode(response)) + end) +end + +---@alias FetchLatestGithubReleaseOpts {tag_name_pattern:string} +---@param repo string The GitHub repo ("username/repo"). +---@param opts FetchLatestGithubReleaseOpts|nil +---@param callback fun(error: string|nil, data: GitHubRelease|nil) +function M.fetch_latest_release(repo, opts, callback) + M.fetch_releases(repo, function(err, releases) + if err then + callback(err, nil) + return + end + + local latest_release = list_find_first(releases, function(_release) + ---@type GitHubRelease + local release = _release + local is_stable_release = not release.prerelease and not release.draft + if opts.tag_name_pattern then + return is_stable_release and release.tag_name:match(opts.tag_name_pattern) + end + return is_stable_release + end) + + if not latest_release then + log.fmt_info("Failed to find latest release. repo=%s, opts=%s", repo, opts) + return callback("Failed to find latest release.", nil) + end + + log.fmt_debug("Resolved latest version repo=%s, tag_name=%s", repo, latest_release.tag_name) + callback(nil, latest_release) + end) +end + +---@param repo string The GitHub repo ("username/repo"). +---@param callback fun(err: string|nil, tags: GitHubTag[]|nil) +function M.fetch_tags(repo, callback) + fetch(("https://api.github.com/repos/%s/tags"):format(repo), function(err, response) + if err then + log.fmt_error("Failed to fetch tags for repo=%s", err) + return callback("Failed to fetch tags.", nil) + end + callback(nil, vim.json.decode(response)) + end) +end + +---@param repo string The GitHub repo ("username/repo"). +---@param callback fun(err: string|nil, latest_tag: GitHubTag|nil) +function M.fetch_latest_tag(repo, callback) + M.fetch_tags(repo, function(err, tags) + if err then + return callback(err, nil) + end + if vim.tbl_count(tags) == 0 then + return callback("No tags found.", nil) + end + callback(nil, tags[1]) + end) +end + +return M diff --git a/lua/nvim-lsp-installer/core/receipt.lua b/lua/nvim-lsp-installer/core/receipt.lua index 5808dfeb..834bb68c 100644 --- a/lua/nvim-lsp-installer/core/receipt.lua +++ b/lua/nvim-lsp-installer/core/receipt.lua @@ -1,41 +1,62 @@ local M = {} ----@alias InstallerReceiptSource table +---@alias InstallReceiptSchemaVersion +---| '"1.0"' +---| '"1.0a"' + +---@alias InstallReceiptSourceType +---| '"npm"' +---| '"pip3"' +---| '"gem"' +---| '"go"' +---| '"dotnet"' +---| '"unmanaged"' +---| '"system"' +---| '"jdtls"' +---| '"git"' +---| '"github_tag"' +---| '"github_release_file"' + +---@alias InstallReceiptSource {type: InstallReceiptSourceType} ---@class InstallReceiptBuilder ----@field private secondary_sources InstallerReceiptSource[] +---@field public is_marked_invalid boolean Whether this instance of the builder has been marked as invalid. This is an exception that only apply to a few select servers whose installation is not yet compatible with the receipt schema due to having a too complicated installation structure. +---@field private secondary_sources InstallReceiptSource[] ---@field private epoch_time number local InstallReceiptBuilder = {} InstallReceiptBuilder.__index = InstallReceiptBuilder function InstallReceiptBuilder.new() return setmetatable({ + is_marked_invalid = false, secondary_sources = {}, }, InstallReceiptBuilder) end +function InstallReceiptBuilder:mark_invalid() + self.is_marked_invalid = true + return self +end + ---@param name string function InstallReceiptBuilder:with_name(name) self.name = name return self end ----@alias InstallerReceiptSchemaVersion ----| '"1.0"' - ----@param version InstallerReceiptSchemaVersion +---@param version InstallReceiptSchemaVersion function InstallReceiptBuilder:with_schema_version(version) self.schema_version = version return self end ----@param source InstallerReceiptSource +---@param source InstallReceiptSource function InstallReceiptBuilder:with_primary_source(source) self.primary_source = source return self end ----@param source InstallerReceiptSource +---@param source InstallReceiptSource function InstallReceiptBuilder:with_secondary_source(source) table.insert(self.secondary_sources, source) return self @@ -81,7 +102,7 @@ function InstallReceiptBuilder:build() } end ----@param type string +---@param type InstallReceiptSourceType local function package_source(type) ---@param package string return function(package) @@ -103,13 +124,12 @@ function InstallReceiptBuilder.system(dependency) end ---@param remote_url string ----@param revision string -function InstallReceiptBuilder.git_remote(remote_url, revision) - return { type = "git", remote = remote_url, revision = revision } +function InstallReceiptBuilder.git_remote(remote_url) + return { type = "git", remote = remote_url } end ---@param ctx ServerInstallContext ----@param opts UseGithubReleaseOpts|nil +---@param opts FetchLatestGithubReleaseOpts|nil function InstallReceiptBuilder.github_release_file(ctx, opts) opts = opts or {} return { @@ -129,6 +149,24 @@ function InstallReceiptBuilder.github_tag(ctx) } end +---@class InstallReceipt +---@field public name string +---@field public schema_version InstallReceiptSchemaVersion +---@field public metrics {start_time:integer, completion_time:integer} +---@field public primary_source InstallReceiptSource +---@field public secondary_sources InstallReceiptSource[] +local InstallReceipt = {} +InstallReceipt.__index = InstallReceipt + +function InstallReceipt.new(props) + return setmetatable(props, InstallReceipt) +end + +function InstallReceipt.from_json(json) + return InstallReceipt.new(json) +end + M.InstallReceiptBuilder = InstallReceiptBuilder +M.InstallReceipt = InstallReceipt return M |
