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

feat: filter user commands #2127

Closed
wants to merge 1 commit into from
Closed

Conversation

tiagovla
Copy link
Contributor

@tiagovla tiagovla commented Sep 9, 2022

This patch allows the usage of server commands without passing them using on_init or before_init (which might be overridden by a user). This is especially useful for custom servers. Therefore this is now possible:

local function custom_command(command, ctx)
    -- do something
end

local configs = require "lspconfig.configs"
if not configs["custom"] then
    configs["custom"] = {
        -- ...
        default_config = {
            -- ...
            commands = {
                ["custom.aCustomCommand"] = custom_command,
            },
        },
    }
end

These commands can be consumed by e.g. code actions.

@glepnir
Copy link
Member

glepnir commented Sep 9, 2022

command field will remove in future. I do not recommend any customization on this field. It is deeply bound to the server configuration. This is not a good direction. if you want make some commands only work for some servers .create it on on_attach field

@tiagovla
Copy link
Contributor Author

tiagovla commented Sep 9, 2022

command field will remove in future. I do not recommend any customization on this field. It is deeply bound to the server configuration. This is not a good direction. if you want make some commands only work for some servers .create it on on_attach field

In my use case scenario, I have a server that I need to adapt its server.extractMethod command triggered by a code action.

So, I need to change the client.commands anyway because that's the only way to do it. I can't do something like this since there's no 'textDocument/codeAction' handler, this method is just ignored.

And since I'm already using on_attach, on_init, and before_init it made more sense to put it in my custom server's default configuration instead of wrapping it on setup like this. The problem is that lspconfig tries to create user commands for all commands.

I can just hack my way with it, but it would be nicer if it was supported.

@glepnir
Copy link
Member

glepnir commented Sep 9, 2022

check #1937 It would be great if we could bypass the server configuration and get some desired parameters and pass them through the api.

@tiagovla
Copy link
Contributor Author

tiagovla commented Sep 9, 2022

check #1937 It would be great if we could bypass the server configuration and get some desired parameters and pass them through the api.

I think the problem is that UserCommands and server commands (the ones used by code actions, e.g. python.extractMethod) have the same client.commands key. If I understood this correctly, removing UserCommands is not related to removing server commands. And as it is, I can't add those in the default configuration because lspconfig tries to create UserCommands out of them, which it can't since the first letter is not uppercase.

@tiagovla
Copy link
Contributor Author

tiagovla commented Sep 9, 2022

Just to be clear, if UserCommands were to be removed, this patch wouldn't be needed. Lspconfig is using the client.commands key to do something different from what neovim expects.

@glepnir
Copy link
Member

glepnir commented Sep 9, 2022

yeah. So I am planning to make a lsp plugin template. Based on this template anyone can make an lsp plugin for their language. That way it will have more possibilities.

@tiagovla tiagovla closed this Sep 15, 2022
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

Successfully merging this pull request may close these issues.

2 participants