From 00f87db6923c696b7d561a5f817aed0dcf3dc48c Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Wed, 13 Aug 2025 14:28:33 +0100 Subject: [PATCH] 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. --- lua/plugins/completions.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lua/plugins/completions.lua b/lua/plugins/completions.lua index 0ec0be5..1d73553 100644 --- a/lua/plugins/completions.lua +++ b/lua/plugins/completions.lua @@ -3,6 +3,7 @@ local ensure_installed = { 'clangd', -- C/C++ 'lua_ls', -- Lua 'opencl_ls', -- OpenCL + 'harper_ls', -- Spelling & grammar } if vim.fn.executable('npm') == 1 then @@ -117,6 +118,32 @@ return { }, }) + vim.lsp.config('harper_ls', { + filetypes = {}, -- Disable for all filetypes + }) + + -- (Dis|en)able harper-ls when spell mode is (dis|en)enabled. + vim.api.nvim_create_autocmd("OptionSet", { + pattern = "spell", + callback = function() + 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, + }) + local cmp = require('cmp') cmp.setup({ snippet = {