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