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

Code Action Groups #994

Open
matklad opened this issue May 22, 2020 · 8 comments
Open

Code Action Groups #994

matklad opened this issue May 22, 2020 · 8 comments
Labels
code actions feature-request Request for new features or functionality
Milestone

Comments

@matklad
Copy link
Contributor

matklad commented May 22, 2020

Another general protocol extension poached from rust-analyzer

CodeAction Groups

Client Capability: { "codeActionGroup": boolean }

If this capability is set, CodeAction returned from the server contain an additional field, group:

interface CodeAction {
    title: string;
    group?: string;
    ...
}

All code-actions with the same group should be grouped under single (extendable) entry in lightbulb menu.
The set of actions [ { title: "foo" }, { group: "frobnicate", title: "bar" }, { group: "frobnicate", title: "baz" }] should be rendered as

💡
  +-------------+
  | foo         |
  +-------------+-----+
  | frobnicate >| bar |
  +-------------+-----+
                | baz |
                +-----+

Alternatively, selecting frobnicate could present a user with an additional menu to choose between bar and baz.

Example

fn main() {
    let x: Entry/*cursor here*/ = todo!();
}

Invoking code action at this position will yield two code actions for importing Entry from either collections::HashMap or collection::BTreeMap, grouped under a single "import" group.

Unresolved Questions

  • Is a fixed two-level structure enough?
  • Should we devise a general way to encode custom interaction protocols for GUI refactorings?

group

IntelliJ variation:

import

@puremourning
Copy link

What's the motivation for this over just having frobicate Bar and frobnicate Baz as options?

@matklad
Copy link
Contributor Author

matklad commented May 22, 2020

Just having two options wouldn't be too bad, and that's what clients not supporting groups get!

However, grouping has two benefits:

  • it keeps the total number of available code actions lower (and that's important because the number of available actions would be pretty large for mature servers).
  • it makes it easier to the user to choose the right action, because they are presented with sub-choices only after they decided that they want this action in the first place.

@kjeremy
Copy link
Contributor

kjeremy commented May 22, 2020

I almost feel like this could be solved using some clever display logic around the hierarchical nature of CodeActionKind.

@dbaeumer
Copy link
Member

@kjeremy good point. VS Code for example allows triggering Source and Refactor actions via a separate menu action.

However making this explicit most of the time results in better UI in the longer term.

@dbaeumer dbaeumer added the feature-request Request for new features or functionality label May 27, 2020
@dbaeumer dbaeumer added this to the Backlog milestone May 27, 2020
@michaelmesser
Copy link
Contributor

michaelmesser commented Apr 26, 2022

Would the second level be resolved only once the user accesses it?

@michaelmesser
Copy link
Contributor

michaelmesser commented May 21, 2022

I propose adding the ability for servers to:

  • request the user enter arbitrary text with a modal
  • request the user pick an option with a modal

Then a code action command would trigger the server ask the user for an option.
This seems more flexible than code action groups.

@heejaechang
Copy link

VS already supports code action group. it would be nice to include this in LSP so that we can use group at least in VS. and ask for group support in vscode.

image

for example, LSP has streaming support that we use in VS, but vscode doesn't support it yet (except in a few places I believe)

@heejaechang
Copy link

by the way, here is how API looks like in VS - https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.language.intellisense.isuggestedaction?view=visualstudiosdk-2022

basically, each code action can be invoked (executed) or/and can return nested actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code actions feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

6 participants