Support workspace/executeCommand for actions' data (#26239)

Closes https://github.com/zed-industries/zed/issues/16746
Part of https://github.com/zed-extensions/deno/issues/2

Changes the action-related code so, that

* `lsp::Command` as actions are supported, if server replies with them
* actions with commands are filtered out based on servers'
`executeCommandOptions`
(https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#executeCommandOptions)
— commands that are not listed won't be executed and the corresponding
actions will be hidden in Zed

Release Notes:

- Added support of `workspace/executeCommand` for actions' data

---------

Co-authored-by: Peter Tripp <petertripp@gmail.com>
This commit is contained in:
Kirill Bulatov 2025-03-06 23:26:46 +02:00 committed by GitHub
parent 97c0a0a86e
commit af5af9d7c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 217 additions and 87 deletions

View file

@ -411,7 +411,48 @@ pub struct CodeAction {
/// The range of the buffer where this code action is applicable.
pub range: Range<Anchor>,
/// The raw code action provided by the language server.
pub lsp_action: lsp::CodeAction,
/// Can be either an action or a command.
pub lsp_action: ActionVariant,
}
/// An action sent back by a language server.
#[derive(Clone, Debug)]
pub enum ActionVariant {
/// An action with the full data, may have a command or may not.
/// May require resolving.
Action(Box<lsp::CodeAction>),
/// A command data to run as an action.
Command(lsp::Command),
}
impl ActionVariant {
pub fn title(&self) -> &str {
match self {
Self::Action(action) => &action.title,
Self::Command(command) => &command.title,
}
}
fn action_kind(&self) -> Option<lsp::CodeActionKind> {
match self {
Self::Action(action) => action.kind.clone(),
Self::Command(_) => Some(lsp::CodeActionKind::new("command")),
}
}
fn edit(&self) -> Option<&lsp::WorkspaceEdit> {
match self {
Self::Action(action) => action.edit.as_ref(),
Self::Command(_) => None,
}
}
fn command(&self) -> Option<&lsp::Command> {
match self {
Self::Action(action) => action.command.as_ref(),
Self::Command(command) => Some(command),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]