Manually refresh code action when data
is not present
This commit is contained in:
parent
9ce3b1adf2
commit
aedf31e2d8
1 changed files with 33 additions and 13 deletions
|
@ -1167,13 +1167,13 @@ impl Project {
|
||||||
|
|
||||||
pub fn apply_code_action(
|
pub fn apply_code_action(
|
||||||
&self,
|
&self,
|
||||||
buffer: ModelHandle<Buffer>,
|
buffer_handle: ModelHandle<Buffer>,
|
||||||
mut action: CodeAction<language::Anchor>,
|
mut action: CodeAction<language::Anchor>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<HashMap<ModelHandle<Buffer>, Vec<(Range<language::Anchor>, clock::Local)>>>>
|
) -> Task<Result<HashMap<ModelHandle<Buffer>, Vec<(Range<language::Anchor>, clock::Local)>>>>
|
||||||
{
|
{
|
||||||
if self.is_local() {
|
if self.is_local() {
|
||||||
let buffer = buffer.read(cx);
|
let buffer = buffer_handle.read(cx);
|
||||||
let lang_name = if let Some(lang) = buffer.language() {
|
let lang_name = if let Some(lang) = buffer.language() {
|
||||||
lang.name().to_string()
|
lang.name().to_string()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1196,21 +1196,41 @@ impl Project {
|
||||||
.and_then(|d| d.get_mut("range"))
|
.and_then(|d| d.get_mut("range"))
|
||||||
{
|
{
|
||||||
*range = serde_json::to_value(&lsp::Range::new(position, position)).unwrap();
|
*range = serde_json::to_value(&lsp::Range::new(position, position)).unwrap();
|
||||||
action = CodeAction {
|
action.lsp_action = lang_server
|
||||||
position: action.position,
|
.request::<lsp::request::CodeActionResolveRequest>(action.lsp_action)
|
||||||
lsp_action: lang_server
|
.await?;
|
||||||
.request::<lsp::request::CodeActionResolveRequest>(action.lsp_action)
|
} else {
|
||||||
.await?,
|
let actions = buffer_handle
|
||||||
}
|
.update(&mut cx, |buffer, cx| {
|
||||||
|
buffer.code_actions(action.position.clone(), cx)
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
action.lsp_action = actions
|
||||||
|
.into_iter()
|
||||||
|
.find(|a| a.lsp_action.title == action.lsp_action.title)
|
||||||
|
.ok_or_else(|| anyhow!("code action is outdated"))?
|
||||||
|
.lsp_action;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut operations = Vec::new();
|
let mut operations = Vec::new();
|
||||||
match action.lsp_action.edit.and_then(|e| e.document_changes) {
|
if let Some(edit) = action.lsp_action.edit {
|
||||||
Some(lsp::DocumentChanges::Edits(edits)) => {
|
if let Some(document_changes) = edit.document_changes {
|
||||||
operations.extend(edits.into_iter().map(lsp::DocumentChangeOperation::Edit))
|
match document_changes {
|
||||||
|
lsp::DocumentChanges::Edits(edits) => operations
|
||||||
|
.extend(edits.into_iter().map(lsp::DocumentChangeOperation::Edit)),
|
||||||
|
lsp::DocumentChanges::Operations(ops) => operations = ops,
|
||||||
|
}
|
||||||
|
} else if let Some(changes) = edit.changes {
|
||||||
|
operations.extend(changes.into_iter().map(|(uri, edits)| {
|
||||||
|
lsp::DocumentChangeOperation::Edit(lsp::TextDocumentEdit {
|
||||||
|
text_document: lsp::OptionalVersionedTextDocumentIdentifier {
|
||||||
|
uri,
|
||||||
|
version: None,
|
||||||
|
},
|
||||||
|
edits: edits.into_iter().map(lsp::OneOf::Left).collect(),
|
||||||
|
})
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
Some(lsp::DocumentChanges::Operations(ops)) => operations = ops,
|
|
||||||
None => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut edited_buffers = HashMap::default();
|
let mut edited_buffers = HashMap::default();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue