tofuutils / tenv

OpenTofu / Terraform / Terragrunt and Atmos version manager
https://tofuutils.github.io/tenv/
Apache License 2.0
662 stars 32 forks source link

tenv 2.2.0 breaks terraform fmt with nvim lsp and terraform-ls #191

Closed verygitmuchhub closed 3 months ago

verygitmuchhub commented 3 months ago

Describe the bug nvim with terraform-ls, terraform fmt code on save results in the document being empty. Possibly something related to stdin/stdout, I guess. Downgrade to 2.1.8 reverted the behaviour and terraform fmt called from nvim lsp works again as expected.

To Reproduce Steps to reproduce the behavior:

  1. Install 2.2.0
  2. Open terraform code in nvim with terraform-ls
  3. Save file with autocommand terraform fmt

Expected behavior nvim receives formatted code output from terraform fmt and updates the buffer.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

This is untested configuration and for illustration purposes.

require('lazy').setup({
  {
    'neovim/nvim-lspconfig',
    config = function()
      local lsp_capabilities = vim.lsp.protocol.make_client_capabilities()
      lsp_capabilities = require('cmp_nvim_lsp').default_capabilities(lsp_capabilities)
      lsp_capabilities.textDocument.completion.completionItem.snippetSupport = true

      local lsp_signature_cfg = {}

      if vim.fn.executable('terraform-ls') == 1 then
        local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
        lsp_config.terraformls.setup({
          capabilities = lsp_capabilities,
          on_attach = function(client, bufnr)
            require('lsp_signature').on_attach(lsp_signature_cfg, bufnr)
            if client.supports_method('textDocument/formatting') then
              vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
              vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
                group = augroup,
                buffer = bufnr,
                callback = function()
                  vim.lsp.buf.format({ bufnr = bufnr })
                end
              })
            end
          end,
        })
      end
    end
  }
})
kvendingoldo commented 3 months ago

@dvaumoron looks like that we have to revert changes related to proxy for a while

dvaumoron commented 3 months ago

Find something, I will fix

dvaumoron commented 3 months ago

@verygitmuchhub , can you check that things work as expected with v2.2.1 ?

verygitmuchhub commented 3 months ago

Fixed with 2.2.1. Thank you guys, for both tenv and how you deal with such things!