Ver código fonte

add cspell integration into neovim

Noah Vogt 1 semana atrás
pai
commit
a27ec197a7

+ 0 - 15
dot-config/nvim/lua/autocmds.lua

@@ -102,21 +102,6 @@ autocmd({ "BufLeave", "FocusLost", "InsertEnter" }, {
 })
 
 
--- LSP Highlight
-augroup("LspHighlight", { clear = true })
-autocmd("CursorHold", {
-  group = "LspHighlight",
-  callback = function()
-    vim.lsp.buf.document_highlight()
-  end,
-})
-autocmd("CursorMoved", {
-  group = "LspHighlight",
-  callback = function()
-    vim.lsp.buf.clear_references()
-  end,
-})
-
 -- TeX Macros
 augroup("texMacros", { clear = true })
 local function map(mode, lhs, rhs, opts)

+ 5 - 0
dot-config/nvim/lua/keymaps.lua

@@ -96,3 +96,8 @@ keymap("n", "<C-h>", function() utils.win_move('h') end, opts)
 keymap("n", "<C-j>", function() utils.win_move('j') end, opts)
 keymap("n", "<C-k>", function() utils.win_move('k') end, opts)
 keymap("n", "<C-l>", function() utils.win_move('l') end, opts)
+
+-- gradle stuff
+keymap("n", "<leader>ga", ":GradleSync<CR>")
+keymap("n", "<leader>gb", ":Gradle assembleDebug<CR>")
+keymap("n", "<leader>gr", ":Gradle installDebug<CR>")

+ 72 - 2
dot-config/nvim/lua/lsp.lua

@@ -41,6 +41,22 @@ local on_attach = function(client, bufnr)
     })
   end
 
+  -- Enable Document Highlight if supported
+  if client.supports_method("textDocument/documentHighlight") then
+    vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
+      buffer = bufnr,
+      callback = function()
+        vim.lsp.buf.document_highlight()
+      end,
+    })
+    vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
+      buffer = bufnr,
+      callback = function()
+        vim.lsp.buf.clear_references()
+      end,
+    })
+  end
+
   -- Format on Type (Commented out - prefer Format on Save in conform.nvim)
   -- if client.supports_method("textDocument/onTypeFormatting") then
   --   vim.api.nvim_create_autocmd("InsertLeave", {
@@ -65,6 +81,58 @@ for _, server in ipairs(servers) do
   vim.lsp.enable(server)
 end
 
+-- cspell LSP integration (using the arch package cspell-lsp)
+vim.lsp.config('cspell', {
+  cmd = { 'cspell-lsp', '--stdio' },
+  filetypes = {
+    "python", "sh", "rust", "kotlin", "java", "c", "cpp", "cmake",
+    "markdown", "text", "gitcommit", "lua", "json", "yaml"
+  },
+    -- Explicitly tell Neovim where to look for the project root
+  root_markers = { 'cspell.config.yaml', 'cspell.json', '.cspell.json', 'package.json', '.git' },
+  capabilities = capabilities,
+  -- initializationOptions often helps where 'settings' fails
+  initializationOptions = {
+    enabled = true,
+  },
+  -- Force absolute path in on_init to stop it from creating cspell.json
+  on_init = function(client)
+    local root = client.root_dir
+    if root then
+      local config_file = root .. "/cspell.config.yaml"
+      client.config.settings.cSpell.configFile = config_file
+      client.notify('workspace/didChangeConfiguration', { settings = client.config.settings })
+    end
+    return true
+  end,
+  -- Boost severity so we actually "see" the spell errors clearly (they default to Information)
+  handlers = {
+    ["textDocument/publishDiagnostics"] = function(err, result, ctx, config)
+      if result and result.diagnostics then
+        for _, diagnostic in ipairs(result.diagnostics) do
+          if diagnostic.source == "cSpell" then
+            -- Map to HINT so we can color it separately from code WARNings
+            diagnostic.severity = vim.diagnostic.severity.HINT
+          end
+        end
+      end
+      vim.lsp.handlers["textDocument/publishDiagnostics"](err, result, ctx, config)
+    end,
+  },
+  settings = {
+    cSpell = {
+      enabled = true,
+    }
+  },
+  on_attach = function(client, bufnr)
+    on_attach(client, bufnr)
+    -- Visual confirmation that cspell is handling this buffer
+    vim.notify("CSpell LSP Active (nospell)", vim.log.levels.INFO)
+    vim.opt_local.spell = false
+  end,
+})
+vim.lsp.enable('cspell')
+
 -- Custom Veridian setup (Verilog)
 vim.lsp.config('veridian', {
   cmd = { 'veridian' },
@@ -114,9 +182,10 @@ local lint = require("lint")
 lint.linters_by_ft = {
   python = { "pylint" },
   sh = { "shellcheck" },
-  rust = { "clippy", "cspell" },
+  rust = { "clippy" },
 }
-vim.api.nvim_create_autocmd({ "BufWritePost" }, {
+
+vim.api.nvim_create_autocmd({ "BufWritePost", "BufEnter" }, {
   callback = function()
     lint.try_lint()
   end,
@@ -135,6 +204,7 @@ vim.diagnostic.config({
 -- 7. Diagnostic & Spell Highlighting
 vim.api.nvim_set_hl(0, 'DiagnosticUnderlineError', { undercurl = true, sp = '#ff0000' })
 vim.api.nvim_set_hl(0, 'DiagnosticUnderlineWarn',  { undercurl = true, sp = '#ff8800' })
+vim.api.nvim_set_hl(0, 'DiagnosticUnderlineHint',  { undercurl = true, sp = '#ffff00' })
 vim.api.nvim_set_hl(0, 'SpellBad',   { undercurl = true, sp = '#ffff00' })
 vim.api.nvim_set_hl(0, 'SpellCap',   { undercurl = true, sp = '#ffff00' })
 vim.api.nvim_set_hl(0, 'SpellLocal', { undercurl = true, sp = '#ffff00' })