Skip to content

Commit bacd042

Browse files
committed
Fix review comments
1 parent cb482e6 commit bacd042

File tree

5 files changed

+24
-41
lines changed

5 files changed

+24
-41
lines changed

crates/rust-analyzer/src/lsp_ext.rs

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ impl Request for ResolveCodeActionRequest {
111111
pub struct ResolveCodeActionParams {
112112
pub code_action_params: lsp_types::CodeActionParams,
113113
pub id: String,
114-
pub label: String,
115114
}
116115

117116
pub enum OnEnter {}

crates/rust-analyzer/src/main_loop/handlers.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,13 @@ pub fn handle_code_action(
756756
handle_fixes(&world, &params, &mut res)?;
757757

758758
if world.config.client_caps.resolve_code_action {
759-
for assist in world.analysis().unresolved_assists(&world.config.assist, frange)?.into_iter()
759+
for (index, assist) in world
760+
.analysis()
761+
.unresolved_assists(&world.config.assist, frange)?
762+
.into_iter()
763+
.enumerate()
760764
{
761-
res.push(to_proto::unresolved_code_action(&world, assist)?);
765+
res.push(to_proto::unresolved_code_action(&world, assist, index)?);
762766
}
763767
} else {
764768
for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() {
@@ -773,24 +777,19 @@ pub fn handle_resolve_code_action(
773777
world: WorldSnapshot,
774778
params: lsp_ext::ResolveCodeActionParams,
775779
) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> {
776-
if !world.config.client_caps.resolve_code_action {
777-
return Ok(None);
778-
}
779-
780780
let _p = profile("handle_resolve_code_action");
781781
let file_id = from_proto::file_id(&world, &params.code_action_params.text_document.uri)?;
782782
let line_index = world.analysis().file_line_index(file_id)?;
783783
let range = from_proto::text_range(&line_index, params.code_action_params.range);
784784
let frange = FileRange { file_id, range };
785-
let mut res: Vec<lsp_ext::CodeAction> = Vec::new();
786785

787-
for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() {
788-
res.push(to_proto::resolved_code_action(&world, assist)?);
789-
}
790-
Ok(res
791-
.into_iter()
792-
.find(|action| action.id.clone().unwrap() == params.id && action.title == params.label)
793-
.and_then(|action| action.edit))
786+
let assists = world.analysis().resolved_assists(&world.config.assist, frange)?;
787+
let id_components = params.id.split(":").collect::<Vec<&str>>();
788+
let index = id_components.last().unwrap().parse::<usize>().unwrap();
789+
let id_string = id_components.first().unwrap();
790+
let assist = &assists[index];
791+
assert!(assist.assist.id.0 == *id_string);
792+
Ok(to_proto::resolved_code_action(&world, assist.clone())?.edit)
794793
}
795794

796795
pub fn handle_code_lens(

crates/rust-analyzer/src/to_proto.rs

+11-23
Original file line numberDiff line numberDiff line change
@@ -622,17 +622,12 @@ fn main() <fold>{
622622
pub(crate) fn unresolved_code_action(
623623
world: &WorldSnapshot,
624624
assist: Assist,
625+
index: usize,
625626
) -> Result<lsp_ext::CodeAction> {
626627
let res = lsp_ext::CodeAction {
627628
title: assist.label,
628-
id: Some(assist.id.0.to_owned()),
629-
group: assist.group.and_then(|it| {
630-
if world.config.client_caps.code_action_group {
631-
None
632-
} else {
633-
Some(it.0)
634-
}
635-
}),
629+
id: Some(format!("{}:{}", assist.id.0.to_owned(), index.to_string())),
630+
group: assist.group.filter(|_| world.config.client_caps.code_action_group).map(|gr| gr.0),
636631
kind: Some(String::new()),
637632
edit: None,
638633
command: None,
@@ -644,21 +639,14 @@ pub(crate) fn resolved_code_action(
644639
world: &WorldSnapshot,
645640
assist: ResolvedAssist,
646641
) -> Result<lsp_ext::CodeAction> {
647-
let res = lsp_ext::CodeAction {
648-
title: assist.assist.label,
649-
id: Some(assist.assist.id.0.to_owned()),
650-
group: assist.assist.group.and_then(|it| {
651-
if world.config.client_caps.code_action_group {
652-
None
653-
} else {
654-
Some(it.0)
655-
}
656-
}),
657-
kind: Some(String::new()),
658-
edit: Some(snippet_workspace_edit(world, assist.source_change)?),
659-
command: None,
660-
};
661-
Ok(res)
642+
let change = assist.source_change;
643+
unresolved_code_action(world, assist.assist, 0).and_then(|it| {
644+
Ok(lsp_ext::CodeAction {
645+
id: None,
646+
edit: Some(snippet_workspace_edit(world, change)?),
647+
..it
648+
})
649+
})
662650
}
663651

664652
pub(crate) fn runnable(

editors/code/src/client.ts

-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient
6161
const id = (item as any).id;
6262
const resolveParams: ra.ResolveCodeActionParams = {
6363
id: id,
64-
// TODO: delete after discussions if needed
65-
label: item.title,
6664
codeActionParams: params
6765
};
6866
action.command = {

editors/code/src/lsp_ext.ts

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export const parentModule = new lc.RequestType<lc.TextDocumentPositionParams, lc
3535

3636
export interface ResolveCodeActionParams {
3737
id: string;
38-
label: string;
3938
codeActionParams: lc.CodeActionParams;
4039
}
4140
export const resolveCodeAction = new lc.RequestType<ResolveCodeActionParams, lc.WorkspaceEdit, unknown>('experimental/resolveCodeAction');

0 commit comments

Comments
 (0)