Skip to content

Commit

Permalink
experimental_lazy_setup to reduce startup time
Browse files Browse the repository at this point in the history
  • Loading branch information
dundalek committed Mar 21, 2024
1 parent f5b07c6 commit 72f954b
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions lua/lazy-lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,35 @@ local overrides = require("lazy-lsp.overrides")
local helpers = require("lazy-lsp.helpers")

local function setup(opts)
for server, server_opts in pairs(helpers.server_configs(lspconfig, servers, opts, overrides)) do
lspconfig[server].setup(server_opts)
for server, config in pairs(helpers.server_configs(lspconfig, servers, opts, overrides)) do
if opts.experimental_lazy_setup ~= true or not config.filetypes then
lspconfig[server].setup(config)
else
-- Based on https://github.com/neovim/nvim-lspconfig/blob/d67715d3b746a19e951b6b0a99663fa909bb9e64/lua/lspconfig/configs.lua#L98-L112
-- Decided to avoid wildcard and only register when a server explicitly specifies filetypes
local lsp_group = vim.api.nvim_create_augroup("lazy_lsp_setup", { clear = false })
local autocmd_id
autocmd_id = vim.api.nvim_create_autocmd("FileType", {
pattern = config.filetypes,
callback = function(opt)
-- We just need to setup the server once, remove autocmd so it does not run again.
vim.api.nvim_del_autocmd(autocmd_id)

local M = lspconfig[server]
M.setup(config)

-- Since we setup inside autocmd callback, we need to help trigger autostart manually.
-- Since lspconfig sets up its own autocmd it will handle it in the future by itself.
if M.autostart then
vim.schedule(function()
M.manager:try_add(opt.buf)
end)
end
end,
group = lsp_group,
desc = string.format("Lazily setup %s lsp server", server),
})
end
end
end

Expand Down

0 comments on commit 72f954b

Please sign in to comment.