Parcourir la source

fix cspell dictionaries

Noah Vogt il y a 11 heures
Parent
commit
db01a24eca
1 fichiers modifiés avec 14 ajouts et 5 suppressions
  1. 14 5
      dot-config/nvim/lua/lsp.lua

+ 14 - 5
dot-config/nvim/lua/lsp.lua

@@ -83,13 +83,13 @@ end
 
 -- cspell LSP integration (using the arch package cspell-lsp)
 vim.lsp.config('cspell', {
-  cmd = { 'cspell-lsp', '--stdio' },
+  cmd = { 'env', 'NODE_PATH=' .. vim.fn.expand('~/.local/share/npm/lib/node_modules'), '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' },
+  root_markers = { 'cspell.config.yaml', 'cspell.json', '.cspell.json' },
   capabilities = capabilities,
   -- initializationOptions often helps where 'settings' fails
   initializationOptions = {
@@ -99,9 +99,18 @@ vim.lsp.config('cspell', {
   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 })
+      local config_file
+      if vim.fn.filereadable(root .. "/cspell.json") == 1 then
+        config_file = root .. "/cspell.json"
+      elseif vim.fn.filereadable(root .. "/cspell.config.yaml") == 1 then
+        config_file = root .. "/cspell.config.yaml"
+      elseif vim.fn.filereadable(root .. "/.cspell.json") == 1 then
+        config_file = root .. "/.cspell.json"
+      end
+      if config_file then
+        client.config.settings.cSpell.configFile = config_file
+        client.notify('workspace/didChangeConfiguration', { settings = client.config.settings })
+      end
     end
     return true
   end,