editor: Add Organize Imports Action (#25793)

Closes #10004

This PR adds support for the organize imports action. Previously, you
had to manually configure it in the settings and then use format to run
it.

Note: Default key binding will be `alt-shift-o` which is similar to
VSCode's organize import. Also, because `cmd-shift-o` is taken by
outline picker.

Todo:

- [x] Initial working
- [x] Handle remote
- [x] Handle multi buffer
- [x] Can we make it generic for executing any code action?

Release Notes:

- Added `editor:OrganizeImports` action to organize imports (sort,
remove unused, etc) for supported LSPs. You can trigger it by using the
`alt-shift-o` key binding.
This commit is contained in:
smit 2025-02-28 11:29:09 -08:00 committed by GitHub
parent e4e758db3a
commit fad4df5e70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 408 additions and 4 deletions

View file

@ -327,7 +327,10 @@ message Envelope {
Fetch fetch = 305;
GetRemotes get_remotes = 306;
GetRemotesResponse get_remotes_response = 307;
Pull pull = 308; // current max
Pull pull = 308;
ApplyCodeActionKind apply_code_action_kind = 309;
ApplyCodeActionKindResponse apply_code_action_kind_response = 310; // current max
}
reserved 87 to 88;
@ -916,6 +919,16 @@ message ChannelBufferVersion {
uint64 epoch = 3;
}
message ApplyCodeActionKind {
uint64 project_id = 1;
string kind = 2;
repeated uint64 buffer_ids = 3;
}
message ApplyCodeActionKindResponse {
ProjectTransaction transaction = 1;
}
enum FormatTrigger {
Save = 0;
Manual = 1;

View file

@ -236,6 +236,8 @@ messages!(
(ExpandAllForProjectEntryResponse, Foreground),
(Follow, Foreground),
(FollowResponse, Foreground),
(ApplyCodeActionKind, Foreground),
(ApplyCodeActionKindResponse, Foreground),
(FormatBuffers, Foreground),
(FormatBuffersResponse, Foreground),
(FuzzySearchUsers, Foreground),
@ -472,6 +474,7 @@ request_messages!(
(ExpandProjectEntry, ExpandProjectEntryResponse),
(ExpandAllForProjectEntry, ExpandAllForProjectEntryResponse),
(Follow, FollowResponse),
(ApplyCodeActionKind, ApplyCodeActionKindResponse),
(FormatBuffers, FormatBuffersResponse),
(FuzzySearchUsers, UsersResponse),
(GetCachedEmbeddings, GetCachedEmbeddingsResponse),
@ -610,6 +613,7 @@ entity_messages!(
ExpandProjectEntry,
ExpandAllForProjectEntry,
FindSearchCandidates,
ApplyCodeActionKind,
FormatBuffers,
GetCodeActions,
GetCompletions,