Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: client.settings is nil #58

Open
RaphaelNeubert opened this issue Aug 15, 2024 · 4 comments
Open

Error: client.settings is nil #58

RaphaelNeubert opened this issue Aug 15, 2024 · 4 comments

Comments

@RaphaelNeubert
Copy link

I have ltex installed using mason.
I configure it the following way:

mason_lspconfig.setup_handlers {
  function(server_name)
    require('lspconfig')[server_name].setup {
      capabilities = capabilities,
      on_attach = on_attach,
      settings = servers[server_name],
      filetypes = (servers[server_name] or {}).filetypes,
    }
  end,
}

the list servers has an entry ltex:

local servers = { ...
 ltex = {
      enabled = { "latex", "tex", "bib", "markdown" },
      language = "auto",
      diagnosticSeverity = "information",
      sentenceCacheSize = 2000,
      additionalRules = {
        enablePickyRules = true,
        motherTongue = "de",
      },
      disabledRules = {
        fr = { "APOS_TYP", "FRENCH_WHITESPACE" },
      },
      dictionary = {
        ['de-DE'] = {'MuZero', 'anotherword'},
      },
      ...

When opening a .tex file i get the following error:

Error executing vim.schedule lua callback: vim/shared.lua:0: after the second argument: expected table, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_deep_extend'
        .../share/nvim/lazy/ltex_extra.nvim/lua/ltex_extra/init.lua:80: in function 'SetLtexSettings'
        .../share/nvim/lazy/ltex_extra.nvim/lua/ltex_extra/init.lua:59: in function 'SetLtexClient'
        .../share/nvim/lazy/ltex_extra.nvim/lua/ltex_extra/init.lua:115: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Inside the function SetLtexSettings found in this plugins init.lua (dev branch) the line that causes the error is:
LtexExtra.internal_settings = vim.tbl_deep_extend("force", client.settings, settings)
The reason is that client.settings simply does not exists. Lsp client settings appear to be stored at client.config.settings.

I don't know much about lua or neovim so i'm wondering if i did a mistake in configuring ltex or if this is a bug and the line needs to be changed.

@barreiroleo
Copy link
Owner

Hi Raphael,
Based on your mason config, I don't think client.settings doesn't exist. It's just a reference to your server settings and it looks ok.
Could you provide your ltex_extra config? Maybe is an issue with configured languages

@RaphaelNeubert
Copy link
Author

Thanks for the quick response. I basically copied the ltex_extra config from the readme and changed the language:

	config = function()
		require("ltex_extra").setup({
			load_langs = { 'de-DE', 'en-US' }, -- Which languages do you want to load on init.
			path = ".ltex",                    -- Path to your ltex files
		})
	end

If i print the first level of the client table using:

local function print_first_level(tbl)
    for key, value in pairs(tbl) do
        if type(value) == "table" then
            print(key .. " = <table>")
        else
            print(key .. " = " .. tostring(value))
        end
    end
end

function LtexExtra:SetLtexSettings(settings)
    local client = LtexExtra:GetLtexClient()
    assert(client, "Client not available")

    print_first_level(client)
    LtexExtra.internal_settings = vim.tbl_deep_extend("force", client.settings, settings)
    LtexExtra:SyncInternalState()
end

it prints:

id = 2
cancel_request = function: 0x7f388c34a928
handlers = <table>
request_sync = function: 0x7f388c34d4c8
rpc = <table>
commands = <table>
is_stopped = function: 0x7f388c34a9c0
offset_encoding = utf-16
workspace_did_change_configuration = function: 0x7f388c395e70
name = ltex
_on_attach = function: 0x7f388c34a9f8
attached_buffers = <table>
server_capabilities = <table>
workspace_folders = <table>
config = <table>
requests = <table>
stop = function: 0x7f388c34a978
supports_method = function: 0x7f388bbb3af0
messages = <table>
request = function: 0x7f388c34b330
initialized = true
notify = function: 0x7f388c34a8e0

No settings entry. If i do
print_first_level(client.config) i get:

single_file_support = true
on_attach = function: 0x7f88e9788050
workspace_folders = <table>
log_level = 2
on_exit = function: 0x7f88e9787680
init_options = <table>
name = ltex
get_language_id = function: 0x7f88e990a4a0
message_level = 2
capabilities = <table>
flags = <table>
cmd_cwd = /home/raphael/htw/bachelorthesis/doc
cmd = <table>
filetypes = <table>
root_dir = /home/raphael/htw/bachelorthesis/doc
settings = <table>
handlers = <table>
autostart = true
_on_attach = function: 0x7f88e9c679c8
on_init = function: 0x7f88e9790358

settings entry exists.

I've noticed that

function LtexExtra:SyncInternalState()
    local client = LtexExtra:GetLtexClient()
    assert(client ~= nil, "Error to sync setings. Client not available")
    client.settings.ltex = LtexExtra:GetLtexSettings().ltex
    return client.notify("workspace/didChangeConfiguration", LtexExtra:GetLtexSettings())

seems to expect settings to have a .ltex entry which wasn't the case in the config i provided in the original post.
For that reason i have changed it to:

 ltex = {
       ltex = {
        enabled = { "latex", "tex", "bib", "markdown" },
        language = "auto",
        diagnosticSeverity = "information",
        sentenceCacheSize = 2000,
        additionalRules = {
          enablePickyRules = true,
          motherTongue = "de",
        },
        disabledRules = {
          fr = { "APOS_TYP", "FRENCH_WHITESPACE" },
        },
        dictionary = {
          ['de-DE'] = {'MuZero', 'anotherword'},
        },
    },
  },

(additional ltex nesting)

If i change client.settings to client.config.settings (in SetLtexSettings and SyncInternalState),
everything works as expected.

I'm on neovim-0.9.5.

@barreiroleo
Copy link
Owner

Yeah, I forgot about that peculiarity of ltex server. settings["ltex"] entry is needed because the specs.
Mine for example:

{
    filetypes = { 'bib', 'markdown', 'org', 'plaintex', 'rst', 'rnoweb', 'tex' },
    settings = {
        ltex = {
            checkFrequency = 'save',
            language = { "en-US", 'es-AR' },
            additionalRules = {
                enablePickyRules = true,
                motherTongue = 'es-AR',
            },
        },
    },
}

@RaphaelNeubert
Copy link
Author

Could you show me your client table and your client.config table?
You can use the the print_first_level(table) function i've provided earlier to make the output non-recursive and therefore shorter.

The path to my actual settings is now client.config.settings.ltex so i still need to change the code of this plugin to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants