Consolidate all code actions logic into Project
This commit is contained in:
parent
e0fe8b5a7c
commit
722c84c976
6 changed files with 136 additions and 169 deletions
|
@ -119,8 +119,8 @@ pub struct Completion<T> {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CodeAction<T> {
|
||||
pub position: T,
|
||||
pub struct CodeAction {
|
||||
pub position: Anchor,
|
||||
pub lsp_action: lsp::CodeAction,
|
||||
}
|
||||
|
||||
|
@ -216,13 +216,6 @@ pub trait File {
|
|||
cx: &mut MutableAppContext,
|
||||
) -> Task<Result<Option<Transaction>>>;
|
||||
|
||||
fn code_actions(
|
||||
&self,
|
||||
buffer_id: u64,
|
||||
position: Anchor,
|
||||
cx: &mut MutableAppContext,
|
||||
) -> Task<Result<Vec<CodeAction<Anchor>>>>;
|
||||
|
||||
fn buffer_updated(&self, buffer_id: u64, operation: Operation, cx: &mut MutableAppContext);
|
||||
|
||||
fn buffer_removed(&self, buffer_id: u64, cx: &mut MutableAppContext);
|
||||
|
@ -311,15 +304,6 @@ impl File for FakeFile {
|
|||
Task::ready(Ok(Default::default()))
|
||||
}
|
||||
|
||||
fn code_actions(
|
||||
&self,
|
||||
_: u64,
|
||||
_: Anchor,
|
||||
_: &mut MutableAppContext,
|
||||
) -> Task<Result<Vec<CodeAction<Anchor>>>> {
|
||||
Task::ready(Ok(Default::default()))
|
||||
}
|
||||
|
||||
fn buffer_updated(&self, _: u64, _: Operation, _: &mut MutableAppContext) {}
|
||||
|
||||
fn buffer_removed(&self, _: u64, _: &mut MutableAppContext) {}
|
||||
|
@ -1861,72 +1845,6 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn code_actions<T>(
|
||||
&self,
|
||||
position: T,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Vec<CodeAction<Anchor>>>>
|
||||
where
|
||||
T: ToPointUtf16,
|
||||
{
|
||||
let file = if let Some(file) = self.file.as_ref() {
|
||||
file
|
||||
} else {
|
||||
return Task::ready(Ok(Default::default()));
|
||||
};
|
||||
let position = position.to_point_utf16(self);
|
||||
let anchor = self.anchor_after(position);
|
||||
|
||||
if let Some(file) = file.as_local() {
|
||||
let server = if let Some(language_server) = self.language_server.as_ref() {
|
||||
language_server.server.clone()
|
||||
} else {
|
||||
return Task::ready(Ok(Default::default()));
|
||||
};
|
||||
let abs_path = file.abs_path(cx);
|
||||
|
||||
cx.foreground().spawn(async move {
|
||||
let actions = server
|
||||
.request::<lsp::request::CodeActionRequest>(lsp::CodeActionParams {
|
||||
text_document: lsp::TextDocumentIdentifier::new(
|
||||
lsp::Url::from_file_path(abs_path).unwrap(),
|
||||
),
|
||||
range: lsp::Range::new(
|
||||
position.to_lsp_position(),
|
||||
position.to_lsp_position(),
|
||||
),
|
||||
work_done_progress_params: Default::default(),
|
||||
partial_result_params: Default::default(),
|
||||
context: lsp::CodeActionContext {
|
||||
diagnostics: Default::default(),
|
||||
only: Some(vec![
|
||||
lsp::CodeActionKind::QUICKFIX,
|
||||
lsp::CodeActionKind::REFACTOR,
|
||||
lsp::CodeActionKind::REFACTOR_EXTRACT,
|
||||
]),
|
||||
},
|
||||
})
|
||||
.await?
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.filter_map(|entry| {
|
||||
if let lsp::CodeActionOrCommand::CodeAction(lsp_action) = entry {
|
||||
Some(CodeAction {
|
||||
position: anchor.clone(),
|
||||
lsp_action,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
Ok(actions)
|
||||
})
|
||||
} else {
|
||||
file.code_actions(self.remote_id(), anchor, cx.as_mut())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_additional_edits_for_completion(
|
||||
&mut self,
|
||||
completion: Completion<Anchor>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue