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

Allow multiple language server with lsp-workspace-command #10176

Conversation

Schmiddiii
Copy link
Contributor

@Schmiddiii Schmiddiii commented Apr 6, 2024

This fix allows for multiple language servers at once which support workspace commands. This was previously broken as just the first language server supporting workspace commands was queried when listing allowed worspace commands.

The fix is in two parts. Firstly, querying all workspace commands from all language servers available and using them when actually running the command in lsp_workspace_command. Secondly, doing the same in completers::lsp_workspace_command such that completion still works as expected.

The fix has one remaining issue, which I am unsure how to handle in the best way possible, but which I also don't think should happen often: Multiple language servers may register commands with the same name. This will lead to that command being listed in the popup menu and in the completion list multiple times, which can be possibly confusing. One could disambigue them in the popover menu, but I am not sure the same can be done for completion. When running lsp-workspace-command with parameters, this behavior is "fixed" by displaying an error in that case. I am unsure if this is the best fix for this issue in that case, but could not find a better one.

Fixes #9017.

This fix allows for multiple language servers at once which support
workspace commands. This was previously broken as just the first
language server supporting workspace commands was queried when listing
allowed worspace commands.

The fix is in two parts. Firstly, querying all workspace commands from
all language servers available and using them when actually running the
command in `lsp_workspace_command`. Secondly, doing the same in
`completers::lsp_workspace_command` such that completion still works as
expected.

The fix has one remaining issue, which I am unsure how to handle in the
best way possible, but which I also don't think should happen often:
Multiple language servers may register commands with the same name. This
will lead to that command being listed in the popup menu and in the
completion list multiple times, which can be possibly confusing. One
could disambigue them in the popover menu, but I am not sure the same
can be done for completion. When running `lsp-workspace-command` with
parameters, this behavior is "fixed" by displaying an error in that
case. I am unsure if this is the best fix for this issue in that case,
but could not find a better one.
@@ -1406,21 +1420,32 @@ fn lsp_workspace_command(
cx.jobs.callback(callback);
} else {
let command = args.join(" ");
Copy link
Contributor Author

@Schmiddiii Schmiddiii Apr 6, 2024

Choose a reason for hiding this comment

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

I am unsure about this one. Is there some LSP which has a space in the command name? I would personally like this to be such that the first argument is the command and the remaining ones are arguments to that command. But I have kept it as it was for now.

@the-mikedavis the-mikedavis added A-language-server Area: Language server client S-waiting-on-review Status: Awaiting review from a maintainer. A-command Area: Commands labels Apr 6, 2024
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

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

lgtm but may want to delay after #9647 to avoid stalling that pr with endless conflicts

@Schmiddiii
Copy link
Contributor Author

That is fine by me. I will keep an eye on the PR and rebase when it is merged.

dhruvmanila added a commit to astral-sh/ruff that referenced this pull request 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:

```toml
[[language]]
name = "python"
# Ruff should come first until helix-editor/helix#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                                                                                                                          
  },
```

2. Helix should now display the commands to pick from when
`:lsp-workspace-command` is invoked:

<img width="832" alt="Screenshot 2024-06-13 at 08 47 14"
src="https://github.com/astral-sh/ruff/assets/67177269/09048ecd-c974-4e09-ab56-9482ff3d780b">
Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

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

The changes here a well self-contained - I shouldn't have trouble rebasing #9647 on this so let's merge this down. Thanks!

@the-mikedavis the-mikedavis merged commit 06d8fee into helix-editor:master Jul 6, 2024
6 checks passed
@Schmiddiii Schmiddiii deleted the lsp-workspace-command-allow-multiple-language-servers branch July 6, 2024 16:21
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
…or#10176)

This fix allows for multiple language servers at once which support
workspace commands. This was previously broken as just the first
language server supporting workspace commands was queried when listing
allowed worspace commands.

The fix is in two parts. Firstly, querying all workspace commands from
all language servers available and using them when actually running the
command in `lsp_workspace_command`. Secondly, doing the same in
`completers::lsp_workspace_command` such that completion still works as
expected.

The fix has one remaining issue, which I am unsure how to handle in the
best way possible, but which I also don't think should happen often:
Multiple language servers may register commands with the same name. This
will lead to that command being listed in the popup menu and in the
completion list multiple times, which can be possibly confusing. One
could disambigue them in the popover menu, but I am not sure the same
can be done for completion. When running `lsp-workspace-command` with
parameters, this behavior is "fixed" by displaying an error in that
case. I am unsure if this is the best fix for this issue in that case,
but could not find a better one.
mxxntype pushed a commit to mxxntype/helix that referenced this pull request Aug 14, 2024
…or#10176)

This fix allows for multiple language servers at once which support
workspace commands. This was previously broken as just the first
language server supporting workspace commands was queried when listing
allowed worspace commands.

The fix is in two parts. Firstly, querying all workspace commands from
all language servers available and using them when actually running the
command in `lsp_workspace_command`. Secondly, doing the same in
`completers::lsp_workspace_command` such that completion still works as
expected.

The fix has one remaining issue, which I am unsure how to handle in the
best way possible, but which I also don't think should happen often:
Multiple language servers may register commands with the same name. This
will lead to that command being listed in the popup menu and in the
completion list multiple times, which can be possibly confusing. One
could disambigue them in the popover menu, but I am not sure the same
can be done for completion. When running `lsp-workspace-command` with
parameters, this behavior is "fixed" by displaying an error in that
case. I am unsure if this is the best fix for this issue in that case,
but could not find a better one.
kyruzic pushed a commit to kyruzic/helix that referenced this pull request Sep 27, 2024
…or#10176)

This fix allows for multiple language servers at once which support
workspace commands. This was previously broken as just the first
language server supporting workspace commands was queried when listing
allowed worspace commands.

The fix is in two parts. Firstly, querying all workspace commands from
all language servers available and using them when actually running the
command in `lsp_workspace_command`. Secondly, doing the same in
`completers::lsp_workspace_command` such that completion still works as
expected.

The fix has one remaining issue, which I am unsure how to handle in the
best way possible, but which I also don't think should happen often:
Multiple language servers may register commands with the same name. This
will lead to that command being listed in the popup menu and in the
completion list multiple times, which can be possibly confusing. One
could disambigue them in the popover menu, but I am not sure the same
can be done for completion. When running `lsp-workspace-command` with
parameters, this behavior is "fixed" by displaying an error in that
case. I am unsure if this is the best fix for this issue in that case,
but could not find a better one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-command Area: Commands A-language-server Area: Language server client S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge workspace commands when using multiple language servers
3 participants