neodev.nvim icon indicating copy to clipboard operation
neodev.nvim copied to clipboard

Unwanted default opts for lspconfig setup

Open wookayin opened this issue 4 years ago • 7 comments

require("lua-dev").setup { ... } produces the following opts for lspconfig.sumneko_lua:

  Lua = {
        ...
        completion = { callSnippet = "Replace" },
        workspace = {
          -- Make the server aware of Neovim runtime files
          library = M.library(opts),
          maxPreload = 1000,
          preloadFileSize = 150,
        },
        ...
  },

Reference: https://github.com/folke/lua-dev.nvim/blob/main/lua/lua-dev/sumneko.lua#L82-L93

Personally I don't like the completion.callSnippet and workspace.maxPreload behavior. The reasons are: (i) functions will show up as snippet entries in the completion engine (rather than kind of function); (ii) When analyzing some lua files greater than the maxPreload size, an input prompt will be asked. With the default value of workspace.maxPreload nil, it won't.

I think these values are very opinionated values and should not a part of this plugin (people can have them rather in their own lsp config files). At least these could be customizable through options for lua_dev.setup { ...}.

wookayin avatar Oct 20 '21 03:10 wookayin

FYI the current workaround I ended up using is:

lsp_setup_opts['sumneko_lua'] = vim.tbl_deep_extend('force',
  require("lua-dev").setup {}, {
    settings = {
      Lua = {
        completion = { callSnippet = "Disable" },
        workspace = { maxPreload = nil },
      },
    },
  }
)
-- For example; do lspconfig with additional parameters, e.g., on_attach, capabilities, etc.
-- lspconfig.sumneko_lua.setup(lsp_setup_opts['sumneko_lua'])

Updated: using tbl_deep_extend.

wookayin avatar Oct 20 '21 03:10 wookayin

@wookayin thanks so much for posting this!

UPDATE: @wookayin's post was the hint I needed to get this working with a NvChad based config, however my first version of the post wasn't actually working, I was too tired to notice though. Now it works.

~/.config/nvim/lua/custom/plugins/lspconfig.lua

local M = {}

M.setup_lsp = function(attach, capabilities)
   local lsp_installer = require "nvim-lsp-installer"

   lsp_installer.on_server_ready(function(server)
      local opts = {
         on_attach = attach,
         capabilities = capabilities,
         flags = {
            debounce_text_changes = 150,
         },
         settings = {},
      }

      if server.name == "sumneko_lua" then
        opts.settings = require("lua-dev").setup().settings
        print(opts.settings.Lua)
      end

      server:setup(opts)
      vim.cmd [[ do User LspAttachBuffers ]]
   end)
end

return M

~/.config/nvim/lua/custom/init.lua

hooks.add("install_plugins", function(use)
  use 'neovim/nvim-lspconfig'
  use 'williamboman/nvim-lsp-installer'
  use 'folke/lua-dev.nvim'
end)

~/.config/nvim/lua/custom/chadrc.lua

M.plugins = {
  options = {
    lspconfig = {
      setup_lspconf = "custom.plugins.lspconfig",
    },
  },
  default_plugin_config_replace = {},
}

erwin avatar Nov 16 '21 16:11 erwin

@erwin I don't think your settings is correct. require("lua-dev").setup{} and {...} are supposed to be merged to opts, but they aren't. opts should be used later like server:setup(opts), but it isn't. I guess you wrongly trimmed out the config -- this code won't have any effect.

wookayin avatar Nov 17 '21 00:11 wookayin

Thanks @wookayin ... I was so tired when I was working on the config that I didn't carefully note the difference between "getting rid of global symbol vim not defined" error message, and completely disabling my whole lsp configuration...

Thanks for pointing out that what I first posted couldn't have worked...

I've tested it a little and it seems to be fine now.

erwin avatar Nov 17 '21 07:11 erwin

@wookayin @erwin any pointers on how to use this with lsp-installer? If I uncomment the if bit in the following snippet then the lsp stops working alltogether:

lsp_installer.on_server_ready(function(server)
    local opts = {}

    -- FIXME: adding the following lines break everything
    -- if server.name == 'sumneko_lua' then
    -- opts.settings = require('lua-dev').setup().settings
    -- end

    server:setup(opts)
end)

petobens avatar Jan 24 '22 01:01 petobens

@petobens This setup works for me

if server.name == "sumneko_lua" then
  local luadev = require("lua-dev").setup {
    lspconfig = vim.tbl_deep_extend("force", server:get_default_options(), opts),
  }

  server:setup(luadev)
else
  server:setup(opts)
end

edit: apparently, this is also work

if server.name == "sumneko_lua" then
  opts = vim.tbl_deep_extend("force", require("lua-dev").setup(), opts)
end

server:setup(opts)

sabitm avatar Jan 27 '22 04:01 sabitm

Thanks @sabitm . @folke what's the official/recommended way of doing it? Both (commented and uncommented) in the following snippet seem to work:

    if server.name == 'sumneko_lua' then
        -- opts.settings = require('lua-dev').setup().settings
        opts = vim.tbl_deep_extend('force', require('lua-dev').setup(), opts)
    end

petobens avatar Jan 29 '22 13:01 petobens

There is no longer a need to work around callSnippet:

  • #47

vedxyz avatar Sep 02 '22 20:09 vedxyz

Please check for the new preferred setup in the docs. This should resolve all of this.

folke avatar Sep 12 '22 10:09 folke