diff options
| author | William Boman <william@redwill.se> | 2022-04-21 12:09:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-21 12:09:59 +0200 |
| commit | b68fcc6bb2c770495ff8e2508c06dfdd49abcc80 (patch) | |
| tree | df7c71efb59958deb21a18eeccf3e3c43c4cd704 /lua/nvim-lsp-installer/servers/tflint/init.lua | |
| parent | run autogen_metadata.lua (diff) | |
| download | mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.gz mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.bz2 mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.lz mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.xz mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.zst mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.zip | |
chore: refactor remaining installers to async impl (#616)
Diffstat (limited to 'lua/nvim-lsp-installer/servers/tflint/init.lua')
| -rw-r--r-- | lua/nvim-lsp-installer/servers/tflint/init.lua | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/lua/nvim-lsp-installer/servers/tflint/init.lua b/lua/nvim-lsp-installer/servers/tflint/init.lua index 125afa86..65a04dec 100644 --- a/lua/nvim-lsp-installer/servers/tflint/init.lua +++ b/lua/nvim-lsp-installer/servers/tflint/init.lua @@ -1,68 +1,61 @@ local server = require "nvim-lsp-installer.server" local Data = require "nvim-lsp-installer.data" +local a = require "nvim-lsp-installer.core.async" local platform = require "nvim-lsp-installer.platform" -local std = require "nvim-lsp-installer.installers.std" -local context = require "nvim-lsp-installer.installers.context" +local github = require "nvim-lsp-installer.core.managers.github" +local spawn = require "nvim-lsp-installer.core.spawn" local process = require "nvim-lsp-installer.process" local coalesce, when = Data.coalesce, Data.when return function(name, root_dir) - local os = coalesce( - when(platform.is_mac, "darwin"), - when(platform.is_linux, "linux"), - when(platform.is_win, "windows") - ) - - local arch = coalesce(when(platform.arch == "x64", "amd64"), platform.arch) - - local target = ("tflint_%s_%s.zip"):format(os, arch) - return server.Server:new { name = name, root_dir = root_dir, languages = { "terraform" }, homepage = "https://github.com/terraform-linters/tflint", - installer = { - context.use_github_release_file("terraform-linters/tflint", target), - context.capture(function(ctx) - return std.unzip_remote(ctx.github_release_file) - end), - context.receipt(function(receipt, ctx) - receipt:with_primary_source(receipt.github_release_file(ctx)) - end), - }, + async = true, + installer = function() + github.unzip_release_file({ + repo = "terraform-linters/tflint", + asset_file = coalesce( + when(platform.is_mac and platform.arch == "x64", "tflint_darwin_amd64.zip"), + when(platform.is_mac and platform.arch == "arm64", "tflint_darwin_arm64.zip"), + when(platform.is_linux and platform.arch == "x64", "tflint_linux_amd64.zip"), + when(platform.is_linux and platform.arch == "arm64", "tflint_linux_arm64.zip"), + when(platform.is_linux and platform.arch == "x86", "tflint_linux_386.zip"), + when(platform.is_win and platform.arch == "x64", "tflint_windows_amd64.zip") + ), + }).with_receipt() + end, default_options = { cmd_env = { PATH = process.extend_path { root_dir }, }, commands = { TFLintInit = { - function() - local process = require "nvim-lsp-installer.process" + a.scope(function() local notify = require "nvim-lsp-installer.notify" - local path = require "nvim-lsp-installer.path" notify "Installing TFLint plugins…" - process.spawn( - "tflint", - { - args = { "--init" }, - cwd = path.cwd(), - stdio_sink = process.simple_sink(), - env = process.graft_env { - PATH = process.extend_path { root_dir }, - }, - }, - vim.schedule_wrap(function(success) - if success then - notify "Successfully installed TFLint plugins." - else - notify "Failed to install TFLint plugins." + spawn.tflint({ + "--init", + cwd = vim.loop.getcwd(), + with_paths = { root_dir }, + }) + :on_success(function() + if vim.in_fast_event() then + a.scheduler() + end + notify "Successfully installed TFLint plugins." + end) + :on_failure(function() + if vim.in_fast_event() then + a.scheduler() end + notify "Failed to install TFLint plugins." end) - ) - end, + end), description = "Runs tflint --init in the current working directory.", }, }, |
