Help wanted, trying to use ltex-ls server with nvim-lsp, code actions did not execute correctly I think

Hello, I’m trying to use ltex-ls with nvim-lsp, the diagnostic works fine. Unfortunately code actions aren’t working as expected, I’m getting the following messages in lsp.log

[ DEBUG ] 2021-04-15T09:29:06-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp.lua:881 ]        "LSP[ltex_ls]"  "client.request"        1       "workspace/executeCommand"      {  arguments = { {      uri = "fil
e:///home/lbiaggi/hd/projects/papers/defesa-final/teste.tex",      words = {        ["pt-BR"] = { "Testu" }      }    } },  command = "ltex.addToDictionary",  title = "Add 'Testu' to dictionary"}     <function
1>      1
[ DEBUG ] 2021-04-15T09:29:06-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:390 ]    "rpc.send.payload"      {  id = 14,  jsonrpc = "2.0",  method = "workspace/executeCommand",  params = {    argumen
ts = { {        uri = "file:///home/lbiaggi/hd/projects/papers/defesa-final/teste.tex",        words = {          ["pt-BR"] = { "Testu" }        }      } },    command = "ltex.addToDictionary",    title = "Add
'Testu' to dictionary"  }}
[ DEBUG ] 2021-04-15T09:29:06-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:491 ]    "decoded"       {  id = 14,  jsonrpc = "2.0",  result = {    errorMessage = "Unknown command 'ltex.addToDictionary
', ignoring",    success = false  }}
[ DEBUG ] 2021-04-15T09:29:06-0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/handlers.lua:442 ]       "default_handler"       "workspace/executeCommand"      {  bufnr = 1,  client_id = 1,  params = {    error
Message = "Unknown command 'ltex.addToDictionary', ignoring",    success = false  }}

my config is defined as:

local lspconfig = require'lspconfig'
local configs = require'lspconfig/configs'
local util = require 'lspconfig/util'

if not lspconfig.ltex_ls then
  configs.ltex_ls = {
        default_config = {
            cmd = {"ltex-ls"};
            filetypes = {'tex', 'bib', 'md'};
            root_dir = function(filename)
                return util.path.dirname(filename)
            end;
            settings = {
                ltex = {
                   enabled= {"latex", "tex", "bib", "md"},
                   configurationTarget = {
                       dictionary = "userExternalFile",
                   },
                   dictionary=":~/.nvim/dictionary.txt",
                   checkFrequency="save",
                   language="pt-BR",
                   diagnosticSeverity="information",
                   setenceCacheSize=5000,
                   additionalRules = {
                       enablePickyRules = true,
                       motherTongue= "pt-BR",
                    },
                }
            };
        };
  }
end
lspconfig.ltex_ls.setup{}

Can anyone give some pointers what is missing? I don’t mind trying to program the missing part, but I still don’t get what is missing.
Regards,
Lucas

1 Like

@lbiaggi Sorry not a solution but a followup question. Did you manage to let the server read the local dictionary? If so, could you please post your relevant snippet?
I have tried these things

                    configurationTarget = {
                        dictionary = "userExternalFile",
                    },
                    dictionary = { ["en"] = { ":/usr/share/words.txt" } },

I have also tried using dictionary directly pointing to file like in your example with dictionary = ":/path/to/whatever"
Nothing works

Found a solution for that.
From what I understand ltex for dictionary only accepts list of words instead of a file. So I just wrote a quick lua utility to conact lines from a file.

something like this

local utils = {}
utils.concat_fileLines = function(file)
    local dictionary = {}
    for line in io.lines(file) do
        table.insert(dictionary, line)
    end
    return dictionary
end
return utils

and then in ltex

settings = { ltex = { dictionary = { ["yourLang"] = callTheFunctionWith(yourDictFile)}}}