aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/servers/tflint/init.lua
blob: d4cb74c3e687a73f268de4dedf15b073dce20de1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local server = require "nvim-lsp-installer.server"
local notify = require "nvim-lsp-installer.notify"
local path = require "nvim-lsp-installer.path"
local installers = require "nvim-lsp-installer.installers"
local shell = require "nvim-lsp-installer.installers.shell"
local process = require "nvim-lsp-installer.process"

return function(name, root_dir)
    local bin_path = path.concat { root_dir, "tflint" }

    return server.Server:new {
        name = name,
        root_dir = root_dir,
        installer = installers.when {
            unix = shell.remote_bash(
                "https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh",
                {
                    env = {
                        TFLINT_INSTALL_PATH = root_dir,
                        TFLINT_INSTALL_NO_ROOT = 1,
                    },
                }
            ),
        },
        default_options = {
            cmd = { bin_path, "--langserver" },
        },
        post_setup = function()
            function _G.lsp_installer_tflint_init()
                notify "Installing TFLint plugins…"
                process.spawn(
                    bin_path,
                    {
                        args = { "--init" },
                        cwd = path.cwd(),
                        stdio_sink = process.simple_sink(),
                    },
                    vim.schedule_wrap(function(success)
                        if success then
                            notify "Successfully installed TFLint plugins."
                        else
                            notify "Failed to install TFLint."
                        end
                    end)
                )
            end

            vim.cmd [[ command! TFLintInit call v:lua.lsp_installer_tflint_init() ]]
        end,
    }
end