Coder Social home page Coder Social logo

Comments (9)

VonHeikemen avatar VonHeikemen commented on June 14, 2024 2

I think setting single_file_support = false in the setup function should solve this

from kickstart.nvim.

anthony-S93 avatar anthony-S93 commented on June 14, 2024 1

@eratio08

I myself stumbled upon this issue today. Turning off single file support does prevent multiple instances of sumneko_lua from being attached to the file after the sourcing in the auto-command; however, what if we need single_file_support?

To solve this problem, I wrote a few lines of code that sort of wrap around your require('lspconfig').sumneko_lua.setup{} logic.

Note that this assumes you are calling the setup{} function in the same file containing the auto-command. For me, that's inside the plugins.lua file:

vim.cmd([[
      augroup packer_user_config
          autocmd!
          autocmd BufWritePost plugins.lua source <afile> | PackerCompile
      augroup end
  ]])

...Your other config...

--Setting up language servers
local lspconfig = require("lspconfig")
local start_sumneko_lua = true --boolean defaults to true, otherwise, the server will never start
local current_buf_id = vim.api.nvim_get_current_buf()
local servers_attached_to_current_buf = vim.lsp.get_active_clients({bufnr = current_buf_id})

for _, server in ipairs(servers_attached_to_current_buf) do
    if server.name == "sumneko_lua" then --an instance of sumneko_lua is already attached to the buffer
        start_sumneko_lua = false 
    end
end

--After that, all you have to do is to wrap sumneko lua's setup() call inside a conditional using the boolean

if start_sumneko_lua then
    lspconfig.sumneko_lua.setup{
         -- yada yada yada
    }
end

--Other servers don't need this, so their setup can be called as usual
lspconfig.pyright.setup{

}

--yada yada yada...

The idea is simply to use some kind of "flag" to determine whether or not to call the setup() function for sumneko_lua (since the setup function determines the availability of the language server). The flag defaults to true but will be switched to false if the current buffer already has an instance of sumneko_lua attached to it.

Granted, the code is a bit inelegant and 'hackish', but it worked without any issues for me because all my plugin configuration is inside packer.nvim's plugin specification file (plugins.lua).

I hope this helps.

from kickstart.nvim.

skovati avatar skovati commented on June 14, 2024

Strange, on my machine it just respawns lua-language-server but never has more than one instance running at a time. Are you getting multiple instances running concurrently? Seems like an easy enough solution would be to remove this source that runs every time we save init.lua.

from kickstart.nvim.

gugahoi avatar gugahoi commented on June 14, 2024

I believe the problem stems from L53

-- Automatically source and re-compile packer whenever you save this init.lua
local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true })
vim.api.nvim_create_autocmd('BufWritePost', {
  command = 'source <afile> | PackerCompile',
  group = packer_group,
  pattern = vim.fn.expand '$MYVIMRC',
})

Removing that line makes it so that only 1 client spawns.

from kickstart.nvim.

eratio08 avatar eratio08 commented on June 14, 2024

Strange, on my machine it just respawns lua-language-server but never has more than one instance running at a time. Are you getting multiple instances running concurrently? Seems like an easy enough solution would be to remove this source that runs every time we save init.lua.

Locking at LspInfo I would say there are multiple instances. Saving also uses increasingly more cpu each consequent time
screenshot_2022-06-26_18-05-58_679704351

from kickstart.nvim.

eratio08 avatar eratio08 commented on June 14, 2024

I believe the problem stems from L53

Yes, I know but getting rid of it will also stop auto-sourcing. The offender is the source <afile> part. I was hoping that there might be a trick to have it lazy init the server.

from kickstart.nvim.

eratio08 avatar eratio08 commented on June 14, 2024

Looks like this prevents the multiple start ups, thx @VonHeikemen!

from kickstart.nvim.

eratio08 avatar eratio08 commented on June 14, 2024

Fix for another config was to comment out workspace = { library = vim.api.nvim_get_runtime_file('', true) }, before that it would be very slowly starting server and it was starting always 2 server at the same time.

from kickstart.nvim.

VonHeikemen avatar VonHeikemen commented on June 14, 2024

Problem happens when you source the file more than once. I would just put all the language servers inside an if that checks the value of a global variable.

if vim.g.user_lsp_setup == nil then
  vim.g.user_lsp_setup = true

  require('lspconfig').sumneko_lua.setup({
    on_attach = on_attach,
    capabilities = capabilities,
    --- more code.....
  })

  require('lspconfig').tsserver.setup({
    on_attach = on_attach,
    capabilities = capabilities,
  })
end

from kickstart.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.