neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
9.98k stars 2.04k forks source link

Auto attach to exists buffer while call `rquire("lspconfig").lua_ls.setup()` #3182

Closed AbaoFromCUG closed 1 month ago

AbaoFromCUG commented 1 month ago

Description

When I call rquire("lspconfig").lua_ls.setup(), lspconfig don't attach to existing lua buffers

Situation: In my config file nvim/init.lua, I use l use some auto-session plugin to restore a session, which will load files to buffers, then I call the rquire("lspconfig").lua_ls.setup() to setup lua-language-server.

I can't guarantee the order of restore session and setup lspconfig (because I use the asynchronous function to do some check), in fact, the restore session usually before setup lspconfig. Therefore, the lua_ls will don't attach to the existing buffers, and show Other clients that match the filetype: lua in :LspInfo

Should or how to enable lspconfig to attach to existing buffers?

My current temporary solution is to execute :LspStart lua_ls manually

thanks

glepnir commented 1 month ago
    local config = require('lspconfig.configs')[server_name]
    if config then
      config.launch()
      return
    end