/ltex-ls.nvim

Enhanced integration of ltex-ls for neovim

Primary LanguageLuaBSD 2-Clause "Simplified" LicenseBSD-2-Clause

ltex-ls.nvim

Enhanced integration of ltex-ls for neovim.

Features:

  • Integration with nvim options:
    • spellfile
  • Working code-actions for:
    • Add to dictionnary
    • Disable rule
    • Hide false positive
  • External files support
  • See TODO section for the planned work

Installation

Install this plugin using your favorite package manager. Remember that this plugin requires using nvim-lspconfig.


-- ltex-ls works without nvim-lspconfig
use { 'vigoux/ltex-ls.nvim' }

-- If you want to use nvim-lspconfig
use { 'vigoux/ltex-ls.nvim', requires = 'neovim/nvim-lspconfig' }

Note the the same feature set is provided with and without lspconfig, so I'd advise not specifying this dependency.

Usage

As this plugin is a wrapper around lspconfig here how to run it:

require'ltex-ls'.setup {
  use_spellfile = false, -- Uses the value of 'spellfile' as an external file when checking the document
  window_border = 'single', -- How the border should be rendered
  -- Put your lsp config here, just like with nvim-lspconfig
}

The plugin exposes multiple commands to help to interact with the server:

  • LtexCheckDocument: checks the current buffer
  • LtexClearCache: using a simple ui, clears parts of or all the local config
  • [range]LtexDisableHere: disables ltex for this range of text.
  • LtexServerStatus: very simple status report of the server, useful for debugging

For example (with my own config):

require 'ltex-ls'.setup {
  on_attach = on_attach,
  capabilities = capabilities,
  use_spellfile = false,
  filetypes = { "latex", "tex", "bib", "markdown", "gitcommit", "text" },
  settings = {
    ltex = {
      enabled = { "latex", "tex", "bib", "markdown", },
      language = "auto",
      diagnosticSeverity = "information",
      sentenceCacheSize = 2000,
      additionalRules = {
        enablePickyRules = true,
        motherTongue = "fr",
      },
      disabledRules = {
        fr = { "APOS_TYP", "FRENCH_WHITESPACE" }
      },
      dictionary = (function()
        -- For dictionary, search for files in the runtime to have
        -- and include them as externals the format for them is
        -- dict/{LANG}.txt
        --
        -- Also add dict/default.txt to all of them
        local files = {}
        for _, file in ipairs(vim.api.nvim_get_runtime_file("dict/*", true)) do
          local lang = vim.fn.fnamemodify(file, ":t:r")
          local fullpath = vim.fs.normalize(file, ":p")
          files[lang] = { ":" .. fullpath }
        end

        if files.default then
          for lang, _ in pairs(files) do
            if lang ~= "default" then
              vim.list_extend(files[lang], files.default)
            end
          end
          files.default = nil
        end
        return files
      end)(),
    },
  },
}

TODOs

  • Integrate spelllang into ltex.language
  • Integrate spellfile into ltex.dictionnary
  • Support custom commands
    • _ltex.addToDictionary
    • _ltex.disableRules
    • _ltex.hideFalsePositives
    • _ltex.checkDocument
      • Expose with :LtexCheckDocument
    • _ltex.getServerStatus
      • Expose :LtexServerStatus
  • Workspace configuration with ltex/workspaceSpecificConfiguration
  • Allow to clear the cache