williamboman / mason-lspconfig.nvim

Extension to mason.nvim that makes it easier to use lspconfig with mason.nvim.
Apache License 2.0
2.69k stars 165 forks source link

TFLint is missing the TFLintInit function #242

Closed mbainter closed 1 year ago

mbainter commented 1 year ago

Problem description

There is no way to initialize tflint when using it with mason so that it downloads its plugins and weirdly, even if you've already initialized tflint in the current path, and the plugin is available in ~/.tflint.d/ it still complains and fails on startup.

[ERROR][2023-06-26 16:46:56] .../vim/lsp/rpc.lua:734    "rpc"   "/home/mbainter/.local/share/nvim/mason/bin/tflint"     "stderr"        "16:46:56 langserver.go:26: Starting language server...\n"
[ERROR][2023-06-26 16:46:56] .../vim/lsp/rpc.lua:734    "rpc"   "/home/mbainter/.local/share/nvim/mason/bin/tflint"     "stderr"        '16:46:56 langserver.go:30: Failed to start language server: Plugin "aws" SDK version is incompatible. Compatible versions: >= 0.14.0\n'

But from that same path:

$ /home/mbainter/.local/share/nvim/mason/bin/tflint --version
TFLint version 0.47.0
+ ruleset.aws (0.17.0)
+ ruleset.terraform (0.4.0-bundled)

Why do you think this is an issue with mason-lspconfig.nvim?

The documentation for tflint appears to pull from the old nvim-lsp-installer code, indicating that there will be a "TFLintInit" function available when the server is set up.

Indeed, in the nvm-lsp-installer plugin, there was a "post_setup" config for the server that looked like this:

    post_setup = function()
        function _G.lsp_installer_tflint_init()
            notify "Installing TFLint plugins…"
            vim.fn.termopen(("%q --init"):format(bin_path), {
                cwd = path.cwd(),
                on_exit = function(_, exit_code)
                    if exit_code ~= 0 then
                        notify(("Failed to install TFLint (exit code %)."):format(exit_code))
                    else
                        notify "Successfully installed TFLint plugins."
                    end
                end,
            })
            vim.cmd [[startinsert]] -- so that we tail the term log nicely ¯\_(ツ)_/¯
        end

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

But, as far as I can tell, this is not a part of mason, or mason-lspconfig.

Neovim version (>= 0.7)

NVIM v0.9.1 Build type: Release LuaJIT 2.1.0-beta3

Operating system/version

Linux 6.26 x86_64

I've manually reviewed the Nvim LPS client log (:LspLog) to find potential errors

I've recently downloaded the latest plugin version of mason.nvim, mason-lspconfig.nvim, and nvim-lspconfig

Affected language servers

tflint

Steps to reproduce

  1. Setup tflint in mason for terraform
  2. Edit a terraform file

Actual behavior

TFLint client fails with an error

Expected behavior

TFLint returns results

LspInfo

Language client log: /home/mbainter/.local/state/nvim/lsp.log
 Detected filetype:   terraform

 2 client(s) attached to this buffer: 

 Client: terraformls (id: 1, bufnr: [1])
    filetypes:       terraform, terraform-vars
    autostart:       true
    root directory:  /home/mbainter/repos/github.com/litmus/terraform-aws-kms
    cmd:             /home/mbainter/.local/share/nvim/mason/bin/terraform-ls serve

 Client: null-ls (id: 3, bufnr: [1])
    filetypes:       tf, terraform-vars, terraform, handlebars, graphql, javascriptreact, markdown.mdx, typescript, typescriptreact, css, scss, html, less, yaml, json, javascript, vue, jsonc, markdown, luau, lua
    autostart:       false
    root directory:  /home/mbainter/repos/github.com/litmus/terraform-aws-kms
    cmd:             <function>

 Other clients that match the filetype: terraform

 Config: tflint
    filetypes:         terraform
    root directory:    /home/mbainter/repos/github.com/litmus/terraform-aws-kms
    cmd:               /home/mbainter/.local/share/nvim/mason/bin/tflint --langserver
    cmd is executable: true
    autostart:         true
    custom handlers:   

 Configured servers list: golangci_lint_ls, sqlls, taplo, lua_ls, tflint, bashls, jsonls, yamlls, dockerls, terraformls, ansiblels

LspLog

[ERROR][2023-06-26 16:46:56] .../vim/lsp/rpc.lua:734    "rpc"   "/home/mbainter/.local/share/nvim/mason/bin/tflint"     "stderr"        "16:46:56 langserver.go:26: Starting language server...\n"
[ERROR][2023-06-26 16:46:56] .../vim/lsp/rpc.lua:734    "rpc"   "/home/mbainter/.local/share/nvim/mason/bin/tflint"     "stderr"        '16:46:56 langserver.go:30: Failed to start language server: Plugin "aws" SDK version is incompatible. Compatible versions: >= 0.14.0\n'

Healthcheck

==============================================================================
mason: require("mason.health").check()

mason.nvim ~
- OK mason.nvim version v1.4.0
- OK PATH: prepend
- OK Providers: 
  mason.providers.registry-api
  mason.providers.client
- OK neovim version >= 0.7.0

mason.nvim [Registries] ~
- OK Registry `github.com/mason-org/mason-registry version: 2023-06-26-toxic-dirt` is installed.

mason.nvim [Core utils] ~
- OK unzip: `UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.`
- OK wget: `GNU Wget 1.21.2 built on linux-gnu.`
- OK curl: `curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.14`
- OK gzip: `gzip 1.10`
- OK tar: `tar (GNU tar) 1.34`
- OK bash: `GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)`
- OK sh: `Ok`

mason.nvim [Languages] ~
- WARNING luarocks: not available
  - ADVICE:
    - spawn: luarocks failed with exit code - and signal -. luarocks is not executable
- WARNING Composer: not available
  - ADVICE:
    - spawn: composer failed with exit code - and signal -. composer is not executable
- WARNING PHP: not available
  - ADVICE:
    - spawn: php failed with exit code - and signal -. php is not executable
- WARNING Ruby: not available
  - ADVICE:
    - spawn: ruby failed with exit code - and signal -. ruby is not executable
- WARNING RubyGem: not available
  - ADVICE:
    - spawn: gem failed with exit code - and signal -. gem is not executable
- WARNING javac: not available
  - ADVICE:
    - spawn: javac failed with exit code - and signal -. javac is not executable
- WARNING java: not available
  - ADVICE:
    - spawn: java failed with exit code - and signal -. java is not executable
- WARNING julia: not available
  - ADVICE:
    - spawn: julia failed with exit code - and signal -. julia is not executable
- OK Go: `go version go1.19.4 linux/amd64`
- OK python: `Python 3.10.6`
- OK node: `v19.3.0`
- OK cargo: `cargo 1.70.0 (ec8a8a0ca 2023-04-25)`
- OK pip: `pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)`
- OK npm: `9.2.0`
- OK python venv: `Ok`

mason.nvim [GitHub] ~
- OK GitHub API rate limit. Used: 33. Remaining: 4967. Limit: 5000. Reset: Mon 26 Jun 2023 04:57:17 PM CDT.

Screenshots or recordings

No response

williamboman commented 1 year ago

Hey! Yeah that seems a bit odd, I'll remove that doc page entirely instead of reintroducing the :TFLintInit command. Have you tried initializing tflint manually, for example in a :terminal or directly via :!tflint --init?

mbainter commented 1 year ago

That also didn't work properly, but it did lead me to figuring out what was going on. The problem isn't the init, the problem is that tflint needs to know where its config file is. Normally I run this as part of pre-commit, and in our pre-commit we specify the path which is the root of the repository -- that's not something tflint can find on its own.

So, for anyone else who might run into this situation - you probably want to setup your own personal tflint configuration in your homedir that you use while writing code, and then deal with any variances you might have from repository to repository in your pre-commit. Otherwise, you'll need to setup something custom in the tflint configuration for mason that figures out which tflint.hcl file to use.

We still should delete that TFLintInit note for the server though, and that can close this issue out.

williamboman commented 1 year ago

243