Compare commits

..

2 Commits

Author SHA1 Message Date
00f87db692 Add harper-ls for spelling & grammer checking
This language server's default list of supported filetypes is
overridden, instead it is not automatically enabled but rather
(dis|en)abled when the `spell` setting is changed.
2025-08-13 14:28:33 +01:00
5a265839f9 Fix lsp setting overrides 2025-08-13 14:28:18 +01:00

View File

@ -3,6 +3,7 @@ local ensure_installed = {
'clangd', -- C/C++ 'clangd', -- C/C++
'lua_ls', -- Lua 'lua_ls', -- Lua
'opencl_ls', -- OpenCL 'opencl_ls', -- OpenCL
'harper_ls', -- Spelling & grammar
} }
if vim.fn.executable('npm') == 1 then if vim.fn.executable('npm') == 1 then
@ -88,12 +89,17 @@ return {
require('cmp_nvim_lsp').default_capabilities()), require('cmp_nvim_lsp').default_capabilities()),
} }
local lspconfig_custom_opts = { require('mason').setup()
clangd = { require('mason-lspconfig').setup({
cmd = { 'clangd', '--completion-style=detailed' }, automatic_installation = false,
}, ensure_installed = ensure_installed,
})
lua_ls = { vim.lsp.config('clangd', {
cmd = { 'clangd', '--completion-style=detailed' },
})
vim.lsp.config('lua_ls', {
settings = { settings = {
Lua = { Lua = {
diagnostics = { diagnostics = {
@ -102,28 +108,40 @@ return {
}, },
}, },
}, },
}, })
pyright = { vim.lsp.config('pyright', {
settings = { settings = {
pyright = { pyright = {
disableOrganizeImports = true, disableOrganizeImports = true,
}, },
}, },
}, })
}
require('mason').setup() vim.lsp.config('harper_ls', {
require('mason-lspconfig').setup({ filetypes = {}, -- Disable for all filetypes
automatic_installation = false, })
ensure_installed = ensure_installed,
handlers = { -- (Dis|en)able harper-ls when spell mode is (dis|en)enabled.
function(server_name) vim.api.nvim_create_autocmd("OptionSet", {
local opts = vim.tbl_deep_extend("force", pattern = "spell",
lspconfig_default_opts, lspconfig_custom_opts[server_name] or {}) callback = function()
require('lspconfig')[server_name].setup(opts) local bufnr = vim.api.nvim_get_current_buf()
if vim.v.option_new then
vim.lsp.start({
name = "harper_ls",
cmd = { "harper-ls", "--stdio" },
root_dir = vim.fn.getcwd(),
}, { bufnr = bufnr })
else
for _, client in pairs(vim.lsp.get_clients({ bufnr = bufnr })) do
if client.name == "harper_ls" then
vim.lsp.buf_detach_client(bufnr, client.id)
break
end
end
end
end, end,
},
}) })
local cmp = require('cmp') local cmp = require('cmp')