Code review fixes
This commit is contained in:
parent
90fc329377
commit
734b95a1ac
@ -1058,41 +1058,44 @@ pub(crate) fn handle_code_action_resolve(
|
||||
.only
|
||||
.map(|it| it.into_iter().filter_map(from_proto::assist_kind).collect());
|
||||
|
||||
let assist_kind: AssistKind = match params.kind.parse() {
|
||||
Ok(kind) => kind,
|
||||
let (assist_index, assist_resolve) = match parse_action_id(¶ms.id) {
|
||||
Ok(parsed_data) => parsed_data,
|
||||
Err(e) => {
|
||||
return Err(LspError::new(
|
||||
ErrorCode::InvalidParams as i32,
|
||||
format!("For the assist to resolve, failed to parse the kind: {}", e),
|
||||
format!("Failed to parse action id string '{}': {}", params.id, e),
|
||||
)
|
||||
.into())
|
||||
}
|
||||
};
|
||||
|
||||
let expected_assist_id = assist_resolve.assist_id.clone();
|
||||
let expected_kind = assist_resolve.assist_kind;
|
||||
|
||||
let assists = snap.analysis.assists_with_fixes(
|
||||
&assists_config,
|
||||
&snap.config.diagnostics(),
|
||||
AssistResolveStrategy::Single(SingleResolve { assist_id: params.id.clone(), assist_kind }),
|
||||
AssistResolveStrategy::Single(assist_resolve),
|
||||
frange,
|
||||
)?;
|
||||
|
||||
let assist = match assists.get(params.index) {
|
||||
let assist = match assists.get(assist_index) {
|
||||
Some(assist) => assist,
|
||||
None => return Err(LspError::new(
|
||||
ErrorCode::InvalidParams as i32,
|
||||
format!(
|
||||
"Failed to find the assist for index {} provided by the resolve request. Expected assist id: {:?}",
|
||||
params.index, params.id,
|
||||
"Failed to find the assist for index {} provided by the resolve request. Resolve request assist id: {}",
|
||||
assist_index, params.id,
|
||||
),
|
||||
)
|
||||
.into())
|
||||
};
|
||||
if assist.id.0 != params.id || assist.id.1 != assist_kind {
|
||||
if assist.id.0 != expected_assist_id || assist.id.1 != expected_kind {
|
||||
return Err(LspError::new(
|
||||
ErrorCode::InvalidParams as i32,
|
||||
format!(
|
||||
"Failed to find exactly the same assist at index {} for the resolve parameters given. Expected id and kind: {}, {:?}, actual id: {:?}.",
|
||||
params.index, params.id, assist_kind, assist.id
|
||||
"Mismatching assist at index {} for the resolve parameters given. Resolve request assist id: {}, actual id: {:?}.",
|
||||
assist_index, params.id, assist.id
|
||||
),
|
||||
)
|
||||
.into());
|
||||
@ -1102,6 +1105,21 @@ pub(crate) fn handle_code_action_resolve(
|
||||
Ok(code_action)
|
||||
}
|
||||
|
||||
fn parse_action_id(action_id: &str) -> Result<(usize, SingleResolve), String> {
|
||||
let id_parts = action_id.split(':').collect_vec();
|
||||
match id_parts.as_slice() {
|
||||
&[assist_id_string, assist_kind_string, index_string] => {
|
||||
let assist_kind: AssistKind = assist_kind_string.parse()?;
|
||||
let index: usize = match index_string.parse() {
|
||||
Ok(index) => index,
|
||||
Err(e) => return Err(format!("Incorrect index string: {}", e)),
|
||||
};
|
||||
Ok((index, SingleResolve { assist_id: assist_id_string.to_string(), assist_kind }))
|
||||
}
|
||||
_ => Err("Action id contains incorrect number of segments".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn handle_code_lens(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_types::CodeLensParams,
|
||||
|
@ -303,8 +303,6 @@ pub struct CodeAction {
|
||||
pub struct CodeActionData {
|
||||
pub code_action_params: lsp_types::CodeActionParams,
|
||||
pub id: String,
|
||||
pub kind: String,
|
||||
pub index: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)]
|
||||
|
@ -897,10 +897,8 @@ pub(crate) fn code_action(
|
||||
(Some(it), _) => res.edit = Some(snippet_workspace_edit(snap, it)?),
|
||||
(None, Some((index, code_action_params))) => {
|
||||
res.data = Some(lsp_ext::CodeActionData {
|
||||
id: assist.id.0.to_string(),
|
||||
id: format!("{}:{}:{}", assist.id.0, assist.id.1.name(), index),
|
||||
code_action_params,
|
||||
kind: assist.id.1.name().to_string(),
|
||||
index,
|
||||
});
|
||||
}
|
||||
(None, None) => {
|
||||
|
@ -81,7 +81,6 @@ If this capability is set, `CodeAction` returned from the server contain an addi
|
||||
interface CodeAction {
|
||||
title: string;
|
||||
group?: string;
|
||||
data?: string;
|
||||
...
|
||||
}
|
||||
```
|
||||
@ -102,8 +101,6 @@ The set of actions `[ { title: "foo" }, { group: "frobnicate", title: "bar" }, {
|
||||
|
||||
Alternatively, selecting `frobnicate` could present a user with an additional menu to choose between `bar` and `baz`.
|
||||
|
||||
`data` field contains optional json data for deferred resolve of the action data that's slow to compute in the original request.
|
||||
|
||||
### Example
|
||||
|
||||
```rust
|
||||
|
Loading…
Reference in New Issue
Block a user