Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete documentation for terraformls #2956

Closed
boojum opened this issue Jan 2, 2024 · 1 comment · Fixed by #3040
Closed

Incomplete documentation for terraformls #2956

boojum opened this issue Jan 2, 2024 · 1 comment · Fixed by #3040
Labels
bug Something isn't working

Comments

@boojum
Copy link

boojum commented Jan 2, 2024

Description

terraformls allows us to customise it via settings. Server configuration page doesn't mention how to set them.

The naive approach I tried:

local M = {}

M.setup = function(on_attach, capabilities)
  require('lspconfig').terraformls.setup {
    on_attach = on_attach,
    capabilities = capabilities,
    settings = {
      terraform = {
        logFilePath = '$HOME/tf.log',
      },
      experimentalFeatures = {
        prefillRequiredFields = true,
      },
    },
  }
end

return M

doesn't work - neither log file is created nor prefillRequiredFields is working. It should be mentioned on the server configuration page how to set them, if at all possible.

Neovim version

NVIM v0.10.0-dev
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Nvim-lspconfig version

No response

Operating system and version

Ubuntu 23.10

Affected language servers

terraformls

Steps to reproduce

Try to set:

local M = {}

M.setup = function(on_attach, capabilities)
  require('lspconfig').terraformls.setup {
    on_attach = on_attach,
    capabilities = capabilities,
    settings = {
      terraform = {
        logFilePath = '$HOME/tf.log',
      },
    },
  }
end

return M

and perform terraform init, terraform plan, terraform apply.

Actual behavior

Log file not being created at the location specified in the config.

Expected behavior

Log file is created at the location specified in the config.

Minimal config

local on_windows = vim.loop.os_uname().version:match 'Windows'

local function join_paths(...)
  local path_sep = on_windows and '\\' or '/'
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.cmd [[set runtimepath=$VIMRUNTIME]]

local temp_dir = vim.loop.os_getenv 'TEMP' or '/tmp'

vim.cmd('set packpath=' .. join_paths(temp_dir, 'nvim', 'site'))

local package_root = join_paths(temp_dir, 'nvim', 'site', 'pack')
local lspconfig_path = join_paths(package_root, 'test', 'start', 'nvim-lspconfig')

if vim.fn.isdirectory(lspconfig_path) ~= 1 then
  vim.fn.system { 'git', 'clone', 'https://github.com/neovim/nvim-lspconfig', lspconfig_path }
end

vim.lsp.set_log_level 'trace'
require('vim.lsp.log').set_format_func(vim.inspect)
local nvim_lsp = require 'lspconfig'
local on_attach = function(_, bufnr)
  local function buf_set_option(...)
    vim.api.nvim_buf_set_option(bufnr, ...)
  end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings.
  local opts = { buffer = bufnr, noremap = true, silent = true }
  vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
  vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
  vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
  vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
  vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
  vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
  vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
  vim.keymap.set('n', '<space>wl', function()
    print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  end, opts)
  vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
  vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
  vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
  vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
  vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
  vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
  vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
end

-- Add the server that troubles you here
local name = 'pyright'
local cmd = { 'pyright-langserver', '--stdio' } -- needed for elixirls, lua_ls, omnisharp
if not name then
  print 'You have not defined a server name, please edit minimal_init.lua'
end
if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
  print [[You have not defined a server default cmd for a server
    that requires it please edit minimal_init.lua]]
end

nvim_lsp[terraformls].setup {
  cmd = cmd,
  on_attach = on_attach,
  settings = {
    terraform = {
      logFilePath = '$HOME/tf.log',
    },
  }
}

LSP log

https://gist.github.com/boojum/5466b3aff50c19a43767ef637fb8fbaa

@boojum boojum added the bug Something isn't working label Jan 2, 2024
@rwblokzijl
Copy link
Contributor

rwblokzijl commented Mar 1, 2024

settings uses the workspace/didChangeConfiguration event, which is not supported by terraform-ls. Instead you should use init_options which passes the settings as part of the LSP initialize call as is required by terraform-ls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants