williamboman / nvim-lsp-installer

Further development has moved to https://github.com/williamboman/mason.nvim!
https://github.com/williamboman/mason.nvim
Apache License 2.0
2k stars 123 forks source link

Server settings do not get applied to sumneko_lua when using the bootstrap snippet provided #478

Closed katawful closed 2 years ago

katawful commented 2 years ago

Problem description

I am attempting to use this plugin to not just install plugins, which works perfectly, but also apply server settings without needing an extra setup call. The documentation says this is possible with an settings table. The following is the fennel then the compiled lua code:

(def servers [
              :clangd
              :sumneko_lua
              ])
(def lsp_installer (require :nvim-lsp-installer.servers))

(local runtime-path (vim.split package.path ";"))
(table.insert runtime-path :lua/?.lua)
(table.insert runtime-path :lua/?/init.lua)
(defn install_servers []
  (each [_ lsp (pairs servers)]
    (local (server_is_found server) (lsp_installer.get_server lsp))
    (when server_is_found
      (server:on_ready (fn []
                         (let [opts {:on_attach on-attach ; on-attach is just my keymaps
                                     :flags {:debounce_text_changes 150}}]
                           (when (= server.name :sumneko_lua)
                             (set opts.settings {:Lua {:runtime {:version :LuaJIT
                                                                 :path runtime-path}
                                                       :workspace {:library (vim.api.nvim_get_runtime_file "" true)}
                                                       :diagnostics {:globals {1 :vim}}}}))
                         (server:setup_lsp opts)))))
  (when (not (server:is_installed))
    (vim.notify (.. "Installing " lsp) vim.log.levels.INFO)
    (server:install))))

(install_servers)
local servers = {"clangd", "sumneko_lua"}
local lsp_installer = require("nvim-lsp-installer.servers")
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
local function install_servers()
  for _, lsp in pairs(servers) do
    local server_is_found, server = lsp_installer.get_server(lsp)
    if server_is_found then
      local function _1_()
        local opts = {on_attach = on-attach, flags = {debounce_text_changes = 150}}
        if (server.name == "sumneko_lua") then
          opts.settings = {Lua = {runtime = {version = "LuaJIT", path = runtime_path}, workspace = {library = vim.api.nvim_get_runtime_file("", true)}, diagnostics = {globals = {"vim"}}}}
        else
        end
        return server:setup_lsp(opts)
      end
      server:on_ready(_1_)
    else
    end
    if not server:is_installed() then
      vim.notify(("Installing " .. lsp), vim.log.levels.INFO)
      server:install()
    else
    end
  end
  return nil
end
return install_servers() 

While the settings table does get inserted to opts just fine, regardless if i use the setup or setup_lsp method for each server the opts table doesn't actually apply to the server. This is simply checked because "vim" is considered an unknown global still when editing a lua file

Neovim version (>= 0.6)

NVIM v0.6.1 Build type: Release LuaJIT 2.0.5

Operating system/version

Linux Kat-Arch 5.16.5-arch1-1 #1 SMP PREEMPT Tue, 01 Feb 2022 21:42:50 +0000 x86_64 GNU/Linux

I've recently downloaded the latest plugin version of both nvim-lsp-installer and nvim-lspconfig

Affected language servers

all

Actual behavior

Settings are not applied to servers when using a bootstrap

Expected behavior

Settings should apply

Healthcheck output

nvim-lsp-installer: require("nvim-lsp-installer.health").check()
========================================================================
## nvim-lsp-installer report
  - OK: neovim version >= 0.6.0
  - WARNING: **Composer**: not available
  - WARNING: **javac**: not available
  - WARNING: **julia**: not available
  - OK: **gzip**: `gzip 1.11`
  - OK: **curl**: `curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/1.1.1m zlib/1.2.11 brotli/1.0.9 zstd/1.5.2 libidn2/2.3.2 libpsl/0.21.1 (+libidn2/2.3.0) libssh2/1.10.0 nghttp2/1.46.0`
  - OK: **wget**: `GNU Wget 1.21.2 built on linux-gnu.`
  - OK: **python3**: `Python 3.10.2`
  - OK: **Ruby**: `ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]`
  - OK: **bash**: `GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)`
  - OK: **sh**: `Ok`
  - OK: **tar**: `tar (GNU tar) 1.34`
  - OK: **RubyGem**: `3.3.5`
  - OK: **Go**: `go version go1.17.6 linux/amd64`
  - OK: **PHP**: `PHP 8.1.2 (cli) (built: Jan 19 2022 17:12:32) (NTS)`
  - OK: **node**: `v17.3.0`
  - OK: **java**: `Ok`
  - OK: **npm**: `8.4.0`
  - OK: **pip3**: `pip 20.3.4 from /usr/lib/python3.10/site-packages/pip (python 3.10)`

Screenshots

No response

williamboman commented 2 years ago

Hello! Hmm, this looks correct to me. I tried using your transpiled Lua code and it works for me - vim is recognised as a global and definitions are successfully located.

Have you tried debugging this to make sure that this code even ends up executing? Especially the opts.settings assignment?

katawful commented 2 years ago

opts when printed has all of the settings I set with said set opts.settings right before the servers:setup call. But when I go and load a file with the server, none of the settings I picked load. I'm not sure what's happening, everything seems fine on my end as well. I have also deleted the local server, and don't have a global one installed as well

williamboman commented 2 years ago

Hmm are your full dotfiles available somewhere? Here's a recording of me using snippet you provided, w/o any issues:

https://asciinema.org/a/jVckV0pyhY2fcF72smhnyBEq3

katawful commented 2 years ago

https://github.com/katawful/dotfiles/tree/master/.config/nvim

williamboman commented 2 years ago

Do you keep the compiled Lua code outside of version control, or how does it work?

katawful commented 2 years ago

They get compiled on runtime, so I don't need to keep them versioned

williamboman commented 2 years ago

I see. I'm unable to repro this using the transpiled Lua snipped you provided, so I'm a bit at a loss atm. Just 10 minutes ago I added a new issue template for server issues, if you believe this is an issue with nvim-lsp-installer could you please file an issue using that template instead (it makes it so much easier for me to reproduce and isolate the issue) 🙏

Screenshot 2022-02-16 at 21 33 46