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

Add supported commands in server capabilities #11850

Merged
merged 1 commit into from
Jun 13, 2024
Merged

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Jun 13, 2024

Summary

This PR updates the server capabilities to include the commands that Ruff supports. This is similar to how there's a list of possible code actions supported by the server.

I noticed this when I was trying to find whether Helix supported workspace commands or not based on Jane's comment (#11831 (comment)) and I found the :lsp-workspace-command in the editor but it didn't show up anything in the picker.

So, I looked at the implementation in Helix (https://github.com/helix-editor/helix/blob/9c479e6d2de3bca9dec304f9182cee2b1c0ad766/helix-term/src/commands/typed.rs#L1372-L1384) which made me realize that Ruff doesn't provide this in its capabilities. Currently, this does require ruff to be first in the list of language servers in the user config but that should be resolved by helix-editor/helix#10176. So, the following config should work:

[[language]]
name = "python"
# Ruff should come first until https://github.com/helix-editor/helix/pull/10176 is released
language-servers = ["ruff", "pyright"]

Test Plan

  1. Neovim's server capabilities output should include the supported commands:
  executeCommandProvider = {                                                                                                                          
    commands = { "ruff.applyFormat", "ruff.applyAutofix", "ruff.applyOrganizeImports", "ruff.printDebugInformation" },                                
    workDoneProgress = false                                                                                                                          
  },
  1. Helix should now display the commands to pick from when :lsp-workspace-command is invoked:
Screenshot 2024-06-13 at 08 47 14

@dhruvmanila dhruvmanila added the server Related to the LSP server label Jun 13, 2024
@dhruvmanila
Copy link
Member Author

dhruvmanila commented Jun 13, 2024

I think I'll re-order them to display the "printDebugInformation" at the end.

Edit: Done

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Comment on lines +367 to +373
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) enum SupportedCommand {
Debug,
Format,
FixAll,
OrganizeImports,
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this from Command to SupportedCommand to match SupportedCodeAction and also moved it from the execute_command.rs module. Feel free to disagree on anything.

Copy link
Contributor

@snowsignal snowsignal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

It's unfortunate that Helix isn't able to forward the URI for these commands - maybe that's something we should try contributing upstream eventually.

@dhruvmanila
Copy link
Member Author

It's unfortunate that Helix isn't able to forward the URI for these commands - maybe that's something we should try contributing upstream eventually.

Yeah, we can start by opening an issue / discussion to let them know about this limitation. I also think this can be solved by a custom plugin but I don't think Helix supports them yet.

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

Successfully merging this pull request may close these issues.

2 participants