From fd45bc8caba2b7f40bdb64aec4c997cc9849fff6 Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Wed, 28 Jan 2026 06:59:36 +0800 Subject: fix: lsp.enable() don't work correctly inside FileType event #37538 Problem: Two cases lsp.enable() won't work in the first FileType event 1. lsp.enable luals inside FileType or ftplugin/lua.lua, then: ``` nvim a.lua ``` 2. lsp.enable luals inside FileType or ftplugin/lua.lua, then: ``` nvim -> :edit a.lua -> :mksession! | restart +qa! so Session.vim ``` Solution: Currently `v:vim_did_enter` is used to detected two cases: 1. "maunally enabled" (lsp.enable() or `:lsp enable`) 2. "inside FileType event" To detect 2. correctly we use did_filetype(). --- runtime/lua/vim/lsp.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/vim/lsp.lua') diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index a464ed47df..db17f992ba 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -590,7 +590,7 @@ function lsp.enable(name, enable) -- Ensure any pre-existing buffers start/stop their LSP clients. if enable ~= false then - if vim.v.vim_did_enter == 1 and next(lsp._enabled_configs) then + if (vim.v.vim_did_enter == 1 or vim.fn.did_filetype() == 1) and next(lsp._enabled_configs) then vim.cmd.doautoall('nvim.lsp.enable FileType') end else -- cgit