ltex-ls.nvim icon indicating copy to clipboard operation
ltex-ls.nvim copied to clipboard

Help with setup

Open juanolon opened this issue 1 year ago • 2 comments

Hi, I have been using ltex with mason and mason-lspconfig.nvim. Now, i want to use this repository to have the (long waited) support for dictionaries, but i don't get it to work. As this is a wrapper on lspconfig i'm confused where to put it, because mason-lspconfig is also a wrapper for lspconfig.

I put require 'ltex-ls'.setup below the mason-lspconfig (require('mason-lspconfig').setup) line. LtexServerStatus says, the server is started but when i run LtexCheckDocument, i don't get any new diagnostics.

Maybe has someone a working template for mason-lspconfig?

Thanks

juanolon avatar Sep 16 '24 17:09 juanolon

Hi @juanolon,

did you figure it out by chance?

NicolasHaeffner avatar Dec 13 '24 07:12 NicolasHaeffner

For me the setup with mason-lspconfig works great when registering the setup function of ltex-ls.nvim as a custom handler using the setup_handlers api. What I have in my config is approximately equivalent to this:

local mason = require 'mason'
local mason_lspconfig = require 'mason-lspconfig'
local lspconfig = require 'lspconfig'

local make_opts = function(server_name)
  return vim.tbl_extend('keep', {
    on_attach = on_attach, -- custom on_attach (mainly for keymaps)
    capabilities = capabilities, -- custom capabilities (for completion)
  }, server_opts[server_name] or {})  -- custom configuration per server
end

local default_handler = function(server_name)
  server_name = vim.split(server_name, '@')[1]
  lspconfig[server_name].setup(make_opts(server_name))
end

mason.setup({...})  -- setup mason as usual

mason_lspconfig.setup()
mason_lspconfig.setup_handlers({
  default_handler,
  ['ltex'] = function()
    local server_name = 'ltex'
    if pcall(require, 'ltex-ls') then
      require('ltex-ls').setup(make_opts(server_name))
    else
      default_handler(server_name)
    end
  end,
})

Puerling avatar Dec 15 '24 21:12 Puerling