mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 10:42:08 +00:00
Refactor closure to extract async
This commit is contained in:
parent
7d128e81aa
commit
4dad2eb7d7
1 changed files with 45 additions and 18 deletions
|
@ -3485,11 +3485,18 @@ impl Project {
|
||||||
Default::default()
|
Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
source_buffer_handle.read_with(&cx, |this, _| {
|
struct PartialCompletion<F: Future<Output = Option<CodeLabel>>> {
|
||||||
|
pub old_range: Range<Anchor>,
|
||||||
|
pub new_text: String,
|
||||||
|
pub label: Option<F>,
|
||||||
|
pub lsp_completion: lsp::CompletionItem,
|
||||||
|
}
|
||||||
|
|
||||||
|
let partial_completions = source_buffer_handle.read_with(&cx, |this, _| {
|
||||||
let snapshot = this.snapshot();
|
let snapshot = this.snapshot();
|
||||||
let clipped_position = this.clip_point_utf16(position, Bias::Left);
|
let clipped_position = this.clip_point_utf16(position, Bias::Left);
|
||||||
let mut range_for_token = None;
|
let mut range_for_token = None;
|
||||||
let result = Vec::new();
|
let mut partial_completions = Vec::new();
|
||||||
|
|
||||||
for lsp_completion in completions.into_iter() {
|
for lsp_completion in completions.into_iter() {
|
||||||
// For now, we can only handle additional edits if they are returned
|
// For now, we can only handle additional edits if they are returned
|
||||||
|
@ -3601,29 +3608,49 @@ impl Project {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let completion = Completion {
|
let label = match language.as_ref() {
|
||||||
|
Some(l) => Some(l.label_for_completion(&lsp_completion)),
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let partial_completion = PartialCompletion {
|
||||||
old_range,
|
old_range,
|
||||||
new_text,
|
new_text,
|
||||||
label: {
|
label,
|
||||||
match language.as_ref() {
|
lsp_completion,
|
||||||
Some(l) => l.label_for_completion(&lsp_completion).await,
|
};
|
||||||
|
|
||||||
|
partial_completions.push(partial_completion);
|
||||||
|
}
|
||||||
|
partial_completions
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut result = Vec::new();
|
||||||
|
|
||||||
|
for pc in partial_completions.into_iter() {
|
||||||
|
let label = match pc.label {
|
||||||
|
Some(label) => label.await,
|
||||||
None => None,
|
None => None,
|
||||||
}
|
}
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
CodeLabel::plain(
|
CodeLabel::plain(
|
||||||
lsp_completion.label.clone(),
|
pc.lsp_completion.label.clone(),
|
||||||
lsp_completion.filter_text.as_deref(),
|
pc.lsp_completion.filter_text.as_deref(),
|
||||||
)
|
)
|
||||||
})
|
});
|
||||||
},
|
|
||||||
lsp_completion,
|
let completion = Completion {
|
||||||
|
old_range: pc.old_range,
|
||||||
|
new_text: pc.new_text,
|
||||||
|
label,
|
||||||
|
lsp_completion: pc.lsp_completion,
|
||||||
};
|
};
|
||||||
|
|
||||||
result.push(completion);
|
result.push(completion);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
} else if let Some(project_id) = self.remote_id() {
|
} else if let Some(project_id) = self.remote_id() {
|
||||||
let rpc = self.client.clone();
|
let rpc = self.client.clone();
|
||||||
let message = proto::GetCompletions {
|
let message = proto::GetCompletions {
|
||||||
|
|
Loading…
Reference in a new issue