nvim: Fix ltex disabled autostart

Fixes #1ef7570.

We implement our own autostart-aware lsp register function. Any lsp
which has the option {autostart=false} set at their config root will be
not automatically enabled and can instead be enabled on demand.
This commit is contained in:
Marty Oehme 2025-06-07 09:38:37 +02:00
parent 6e6f804c08
commit 63c6c81f6e
Signed by: Marty
GPG key ID: 4E535BC19C61886E
3 changed files with 36 additions and 23 deletions

View file

@ -56,9 +56,14 @@ local lsp = {
vim.fn.sign_define("DiagnosticSignInfo", { text = "", texthl = "DiagnosticSignInfo" })
vim.fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" })
local function register(server_name, config)
local function register(server_name, config, enabled)
if vim.fn.has("nvim-0.11") == 1 then
vim.lsp.config(server_name, config)
if enabled == false or vim.lsp.config[server_name]["autostart"] == false then
vim.lsp.enable(server_name, false)
else
vim.lsp.enable(server_name, true)
end
else
require("lspconfig")[server_name].setup(config)
end
@ -186,19 +191,28 @@ local lsp = {
vim.api.nvim_create_autocmd("User", {
pattern = "SpellEnable",
callback = function()
register("ltex", {
on_attach = function(_, _)
if require("core.util").is_available("ltex_extra") then
require("ltex_extra").setup()
end
end,
settings = {
ltex = {
language = vim.o.spelllang,
},
},
local mapped = {}
local lang_map = {
en_us = "en-US",
en_gb = "en-GB",
de_de = "de-DE",
}
for _, v in ipairs(vim.opt.spelllang:get()) do
table.insert(mapped, lang_map[v])
end
vim.lsp.config("ltex", {
settings = { ltex = { language = mapped } },
})
vim.cmd("LspStart ltex")
-- single-shot setup: Enable for this buffer
-- but instantly disable again globally
vim.lsp.enable("ltex")
vim.lsp.enable("ltex", false)
end,
})
vim.api.nvim_create_autocmd("User", {
pattern = "SpellDisable",
callback = function()
vim.lsp.enable("ltex", false)
end,
})
end,