Fix review comments
This commit is contained in:
parent
cb482e6351
commit
bacd0428fa
@ -111,7 +111,6 @@ impl Request for ResolveCodeActionRequest {
|
||||
pub struct ResolveCodeActionParams {
|
||||
pub code_action_params: lsp_types::CodeActionParams,
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
pub enum OnEnter {}
|
||||
|
@ -756,9 +756,13 @@ pub fn handle_code_action(
|
||||
handle_fixes(&world, ¶ms, &mut res)?;
|
||||
|
||||
if world.config.client_caps.resolve_code_action {
|
||||
for assist in world.analysis().unresolved_assists(&world.config.assist, frange)?.into_iter()
|
||||
for (index, assist) in world
|
||||
.analysis()
|
||||
.unresolved_assists(&world.config.assist, frange)?
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
res.push(to_proto::unresolved_code_action(&world, assist)?);
|
||||
res.push(to_proto::unresolved_code_action(&world, assist, index)?);
|
||||
}
|
||||
} else {
|
||||
for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() {
|
||||
@ -773,24 +777,19 @@ pub fn handle_resolve_code_action(
|
||||
world: WorldSnapshot,
|
||||
params: lsp_ext::ResolveCodeActionParams,
|
||||
) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> {
|
||||
if !world.config.client_caps.resolve_code_action {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let _p = profile("handle_resolve_code_action");
|
||||
let file_id = from_proto::file_id(&world, ¶ms.code_action_params.text_document.uri)?;
|
||||
let line_index = world.analysis().file_line_index(file_id)?;
|
||||
let range = from_proto::text_range(&line_index, params.code_action_params.range);
|
||||
let frange = FileRange { file_id, range };
|
||||
let mut res: Vec<lsp_ext::CodeAction> = Vec::new();
|
||||
|
||||
for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() {
|
||||
res.push(to_proto::resolved_code_action(&world, assist)?);
|
||||
}
|
||||
Ok(res
|
||||
.into_iter()
|
||||
.find(|action| action.id.clone().unwrap() == params.id && action.title == params.label)
|
||||
.and_then(|action| action.edit))
|
||||
let assists = world.analysis().resolved_assists(&world.config.assist, frange)?;
|
||||
let id_components = params.id.split(":").collect::<Vec<&str>>();
|
||||
let index = id_components.last().unwrap().parse::<usize>().unwrap();
|
||||
let id_string = id_components.first().unwrap();
|
||||
let assist = &assists[index];
|
||||
assert!(assist.assist.id.0 == *id_string);
|
||||
Ok(to_proto::resolved_code_action(&world, assist.clone())?.edit)
|
||||
}
|
||||
|
||||
pub fn handle_code_lens(
|
||||
|
@ -622,17 +622,12 @@ fn main() <fold>{
|
||||
pub(crate) fn unresolved_code_action(
|
||||
world: &WorldSnapshot,
|
||||
assist: Assist,
|
||||
index: usize,
|
||||
) -> Result<lsp_ext::CodeAction> {
|
||||
let res = lsp_ext::CodeAction {
|
||||
title: assist.label,
|
||||
id: Some(assist.id.0.to_owned()),
|
||||
group: assist.group.and_then(|it| {
|
||||
if world.config.client_caps.code_action_group {
|
||||
None
|
||||
} else {
|
||||
Some(it.0)
|
||||
}
|
||||
}),
|
||||
id: Some(format!("{}:{}", assist.id.0.to_owned(), index.to_string())),
|
||||
group: assist.group.filter(|_| world.config.client_caps.code_action_group).map(|gr| gr.0),
|
||||
kind: Some(String::new()),
|
||||
edit: None,
|
||||
command: None,
|
||||
@ -644,21 +639,14 @@ pub(crate) fn resolved_code_action(
|
||||
world: &WorldSnapshot,
|
||||
assist: ResolvedAssist,
|
||||
) -> Result<lsp_ext::CodeAction> {
|
||||
let res = lsp_ext::CodeAction {
|
||||
title: assist.assist.label,
|
||||
id: Some(assist.assist.id.0.to_owned()),
|
||||
group: assist.assist.group.and_then(|it| {
|
||||
if world.config.client_caps.code_action_group {
|
||||
None
|
||||
} else {
|
||||
Some(it.0)
|
||||
}
|
||||
}),
|
||||
kind: Some(String::new()),
|
||||
edit: Some(snippet_workspace_edit(world, assist.source_change)?),
|
||||
command: None,
|
||||
};
|
||||
Ok(res)
|
||||
let change = assist.source_change;
|
||||
unresolved_code_action(world, assist.assist, 0).and_then(|it| {
|
||||
Ok(lsp_ext::CodeAction {
|
||||
id: None,
|
||||
edit: Some(snippet_workspace_edit(world, change)?),
|
||||
..it
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn runnable(
|
||||
|
@ -61,8 +61,6 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient
|
||||
const id = (item as any).id;
|
||||
const resolveParams: ra.ResolveCodeActionParams = {
|
||||
id: id,
|
||||
// TODO: delete after discussions if needed
|
||||
label: item.title,
|
||||
codeActionParams: params
|
||||
};
|
||||
action.command = {
|
||||
|
@ -35,7 +35,6 @@ export const parentModule = new lc.RequestType<lc.TextDocumentPositionParams, lc
|
||||
|
||||
export interface ResolveCodeActionParams {
|
||||
id: string;
|
||||
label: string;
|
||||
codeActionParams: lc.CodeActionParams;
|
||||
}
|
||||
export const resolveCodeAction = new lc.RequestType<ResolveCodeActionParams, lc.WorkspaceEdit, unknown>('experimental/resolveCodeAction');
|
||||
|
Loading…
Reference in New Issue
Block a user