Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

[Bug?] Lsp servers fail to start #87

Closed
starptr opened this issue Aug 8, 2021 · 8 comments · Fixed by #149
Closed

[Bug?] Lsp servers fail to start #87

starptr opened this issue Aug 8, 2021 · 8 comments · Fixed by #149

Comments

@starptr
Copy link

starptr commented Aug 8, 2021

Description
Running :LspInfo in various filetypes shows that LSP does not start.

Reproduce
Using:

  • wsl2
  • neovim 0.5.0 stable
  • doom stable (3.0.9 I believe)

Configs:

  • Enable 'html', 'css', 'javascript +lsp', 'typescript +lsp', 'tsx', 'rust +lsp'

Steps:

  • Open a javascript, typescriptreact, or rust project file (file with extensions js, tsx, or rs)
  • Run :LspInfo

Any debugging ideas appreciated :)

@NTBBloodbath
Copy link
Collaborator

Hey, sorry for the late reply!

What happens if you do (e.g. for tsserver)

:lua print(vim.inspect(require("lspconfig")["typescript"].filetypes))

@starptr
Copy link
Author

starptr commented Aug 8, 2021

No worries!
It seems that the "typescript" key doesn't exist:

E5108: Error executing lua [string ":lua"]:1: attempt to index field 'typescript' (a nil value)

I tried running :lua print(vim.inspect(require("lspconfig"))) as well:

{
  _root = {
    _setup = <function 1>,
    commands = {
      LspInfo = { <function 2>, "-nargs=0",
        description = "`:LspInfo` Displays attached, active, and configured language servers"
      },
      LspRestart = { <function 3>, "-nargs=? -complete=customlist,v:lua.lsp_get_active_client_ids",
        description = "`:LspRestart` Manually restart the given language client."
      },
      LspStart = { <function 4>, "-nargs=? -complete=custom,v:lua.lsp_complete_configured_servers",
        description = "`:LspStart` Manually launches a language server."
      },
      LspStop = { <function 5>, "-nargs=? -complete=customlist,v:lua.lsp_get_active_client_ids",
        description = "`:LspStop` Manually stops the given language client."
      }
    }
  },
  available_servers = <function 6>,
  util = {
    add_hook_after = <function 7>,
    add_hook_before = <function 8>,
    create_module_commands = <function 9>,
    default_config = {
      autostart = true,
      handlers = {},
      init_options = vim.empty_dict(),
      log_level = 2,
      message_level = 2,
      settings = vim.empty_dict()
    },
    find_git_ancestor = <function 10>,
    find_node_modules_ancestor = <function 11>,
    find_package_json_ancestor = <function 12>,
    has_bins = <function 13>,
    path = {
      dirname = <function 14>,
      exists = <function 15>,
      is_absolute = <function 16>,
      is_descendant = <function 17>,
      is_dir = <function 18>,
      is_file = <function 19>,
      iterate_parents = <function 20>,
      join = <function 21>,
      sep = "/",
      traverse_parents = <function 22>
    },
    root_pattern = <function 23>,
    script_path = <function 24>,
    search_ancestors = <function 25>,
    server_per_root_dir_manager = <function 26>,
    validate_bufnr = <function 27>
  },
  <metatable> = {
    __index = <function 28>
  }
}

There doesn't seem to be lsp servers installed? I'm not sure

@starptr
Copy link
Author

starptr commented Aug 8, 2021

By the way, I just figured out that running :LspInstall typescript does seem to start the typescript lang server (it finally shows in :LspInfo🎉); however, I think this is a hack, since it's not using the config values from doomrc.lua. (Also I'd rather doom take care of this like intended, since it will be more reproducible hah. I think it'll work temporarily for me for now though :))

For debugging the original issue though, I will uninstall & reinstall everything so that this won't affect debugging 👍

@NTBBloodbath
Copy link
Collaborator

Hmm that's pretty strange. Maybe the server wasn't installed properly? Don't know but hey, at least it's working now!

I'll try to dig on it too by reinstalling my servers, hopefully if there's an error I should be able to get it so I can start debugging :)

@connorgmeehan
Copy link
Collaborator

connorgmeehan commented Oct 1, 2021

I've been investigating this issue myself and I think I found the source.

It seems as if install_servers is running before lspinstall gets loaded by packer.

-- install_servers will install the language servers for the languages with
-- the +lsp flag.
--
-- @param langs The list of languages in the doomrc
M.install_servers = function(langs)
  log.info("Installing servers")
  log.info("packer_plugins[\"nvim-lspinstall\"].loaded: " .. string.format("%s", packer_plugins["nvim-lspinstall"].loaded))

  -- This if statement fails as loaded == false
  if packer_plugins and packer_plugins["nvim-lspinstall"] and packer_plugins["nvim-lspinstall"].loaded then


    local lspinstall = require("lspinstall")
    local installed_servers = lspinstall.installed_servers()
    local available_servers = lspinstall.available_servers()

I've been trying to solve this but I'm pretty new to lua and nvim config in general so not sure what the best solution is.

It'd be great to be able to attach a callback to trigger once packer loads a plugin. Alternatively we could put install_servers behind a PackerComplete autocmd? Also not sure if this is on my end but it seems like lspinstall has been renamed to nvim-lspinstall in packer_plugins.

Here's a log showing the race condition CONFIGURING LSP INSTALL comes from modules/config/doom-lspinstall.lua

If you can point me in the right direction for a solution I'm happy to put in a PR :)

[INFO  Fri  1 Oct 13:32:00 2021] .../connormeehan/.config/nvim/lua/doom/core/config/init.lua:441: Installing servers
[INFO  Fri  1 Oct 13:32:00 2021] .../connormeehan/.config/nvim/lua/doom/core/config/init.lua:471: packer_plugins["nvim-lspinstall"].loaded: false
[INFO  Fri  1 Oct 13:32:00 2021] [string "..."]:0: CONFIGURING LSP INSTALL

@NTBBloodbath
Copy link
Collaborator

Hi, thank you for digging on this and also for providing such useful information!

Now I think I know what could be happening. Can you please try modifying Doom's plugins setup? It's at lua/doom/modules/init.lua and you should modify two plugins.

  1. Stop lazy-loading lspconfig (optional)
  2. Change how is lspinstall lazy-loaded

Since lspinstall is being loaded right after lspconfig then lspinstall should load before the install_servers function run.

Otherwise if you don't want to stop lazy-loading lspconfig because it could increase startup time by a lot because there's a ton of stuff lazy-loaded to be loaded after lspconfig, you can change how is lspinstall lazy-loaded.

So, you could use module = "lspinstall", in lspinstall plugin declaration and remove the after = "nvim-lspconfig",.

Additional to this change you could remove the packer_plugins["nvim-lspinstall"].loaded statement from the conditional, because we now care only if the plugin is installed and we will load it right after doing the require("lspinstall").

@connorgmeehan
Copy link
Collaborator

Hmm I tried modifying the packer use part like you described

  -- provides the missing `:LspInstall` for `nvim-lspconfig`.
  use({
    "kabouzeid/nvim-lspinstall",
    config = require("doom.modules.config.doom-lspinstall"),
    disable = disabled_lsp,
    module = 'lspinstall',
  })

But this just pushed the issue down to doom-lspinstall.lua where require("lspconfig") fails.

Could we keep the same after: 'lspconfig' on the packer import and move the part of the code that manages LSP installation into nvim-lspinstall?

@NTBBloodbath
Copy link
Collaborator

Hi, yeah this sounds like a better approach :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants