From 5cc73ef7360866c65169e0e7d55d3b59fb3b6eaa Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 6 Jan 2022 18:21:19 +0100 Subject: feat(ui): display outdated servers (#395) --- lua/nvim-lsp-installer/server.lua | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'lua/nvim-lsp-installer/server.lua') diff --git a/lua/nvim-lsp-installer/server.lua b/lua/nvim-lsp-installer/server.lua index b06249b3..948d11db 100644 --- a/lua/nvim-lsp-installer/server.lua +++ b/lua/nvim-lsp-installer/server.lua @@ -174,19 +174,36 @@ function M.Server:promote_install_dir(install_dir) return true end +function M.Server:_get_receipt_path() + return path.concat { self.root_dir, "nvim-lsp-installer-receipt.json" } +end + ---@param receipt_builder InstallReceiptBuilder function M.Server:_write_receipt(receipt_builder) - receipt_builder:with_name(self.name):with_schema_version("1.0"):with_completion_time(vim.loop.gettimeofday()) + if receipt_builder.is_marked_invalid then + log.fmt_debug("Skipping writing receipt for %s because it is marked as invalid.", self.name) + return + end + receipt_builder:with_name(self.name):with_schema_version("1.0a"):with_completion_time(vim.loop.gettimeofday()) local receipt_success, install_receipt = pcall(receipt_builder.build, receipt_builder) if receipt_success then - local install_receipt_path = path.concat { self.root_dir, "nvim-lsp-installer-receipt.json" } - pcall(fs.write_file, install_receipt_path, vim.json.encode(install_receipt)) + pcall(fs.write_file, self:_get_receipt_path(), vim.json.encode(install_receipt)) else log.fmt_error("Failed to build receipt for server=%s. Error=%s", self.name, install_receipt) end end +---@return InstallReceipt|nil +function M.Server:get_receipt() + local receipt_path = self:_get_receipt_path() + if fs.file_exists(receipt_path) then + local receipt_json = vim.json.decode(fs.read_file(receipt_path)) + return receipt.InstallReceipt.from_json(receipt_json) + end + return nil +end + ---@param context ServerInstallContext ---@param callback ServerInstallCallback function M.Server:install_attached(context, callback) -- cgit v1.2.3-70-g09d2