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

Client commands table validation does not match what is expected by lsp core. #2632

Open
asmodeus812 opened this issue May 24, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@asmodeus812
Copy link

asmodeus812 commented May 24, 2023

Description

The issue is that lspconfig requires the command table for a client config that is passed to the lspconfig .setup method call to be of type table, where the key is the command name and the value is array table of two values which requires the first value to be a function, and the second optional one to be a description. That however does not match what lsp core expects for the client.config.commands, which for the commands table is simple key - function mapping. Lspconfig does not transform the commands' table when passing it to start the lspclient

For some inexplicable, reason, lspconfig is creating those commands as user commands, which is useless, since those commands are not meant to be used like that anyway.

Here is how it is actually used to produce some user commands

      util.create_module_commands(config_name, M.commands)

Here is the validation that lspconfig does, at configs.lua:46

    for k, v in pairs(config_def.commands) do
      validate {
        ['command.name'] = { k, 's' },
        ['command.fn'] = { v[1], 'f' },
      }
    end

Here is how the lsp core is using client.commands , at lsp/buf.lua:807

      local fn = client.commands[command.command] or vim.lsp.commands[command.command]

Pretty much obvious where the issue is, property name either should change to user_commands, since it is confusing, or transform it to match what core expects, so it is actually correct.

Neovim version

NVIM 9.0.0

Nvim-lspconfig version

master

Operating system and version

Ubuntu 22

Affected language servers

all

Steps to reproduce

  1. Invoke .setup with {commands = { ["command.name"] = function() ..... end }
  2. Observe that the validation fails since it expects the value against the key to be array of two values function and description.

Actual behavior

Commands table is not propagated to the lsp.core which has an explicit handle when executing commands, instead it just sets them as UserCommands.

At the moment the workaround is to set it to the globals commands table @ vim.lsp.commands, or force override the lsp_configs[server_name] which will bypass the validation, instead of passing to .setup which tries to validate the passed in user_config.

Expected behavior

Either rename this commands, because it does not respect the interface expected by lsp core and client.config.commands , property or handle it correctly, i.e correct the validation, or transform the table to match the lsp core specs.

Minimal config

Not applicable

LSP log

not applicable

@asmodeus812 asmodeus812 added the bug Something isn't working label May 24, 2023
@asmodeus812
Copy link
Author

The workaround above however breaks, because there is an autocmd in lspconfig which still tries to read the passed in commands table, and create the user commands. Ideally that should not exist, but it is quite annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant