nvim: Only start ltex LSP if spellchecking enabled

Since ltex-lsp eats quite a lot of resources and takes a while to start
up we don't always want it enabled for every prose file. This commit
ensures that it only starts up when spellchecking is enabled for a
buffer (through the custom user command `SpellToggle`).
This commit is contained in:
Marty Oehme 2024-06-27 17:20:35 +02:00
parent 9ded34f73c
commit e6497a2241
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
3 changed files with 22 additions and 3 deletions

View file

@ -20,7 +20,7 @@ local servers = {
eslint = {},
gopls = {},
julials = {},
ltex = {},
ltex = { autostart = false },
lua_ls = {
settings = {
Lua = {
@ -201,3 +201,23 @@ if require("core.util").is_available("arduino") then
on_new_config = require("arduino").on_new_config,
})
end
vim.api.nvim_create_autocmd("User", {
pattern = "SpellEnable",
callback = function()
lspconfig.ltex.setup({
on_attach = function(client, bufnr)
on_attach(client, bufnr)
if require("core.util").is_available("ltex_extra") then
require("ltex_extra").setup()
end
end,
settings = {
ltex = {
language = vim.opt.spelllang:get(),
},
},
})
vim.cmd("LspStart ltex")
end,
})