Start work on code actions
Just print out the returned code actions for now Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
co-authored by
Nathan Sobo
parent
4900019e9b
commit
83d4fe8e3a
@@ -124,6 +124,7 @@ action!(FoldSelectedRanges);
|
||||
action!(Scroll, Vector2F);
|
||||
action!(Select, SelectPhase);
|
||||
action!(ShowCompletions);
|
||||
action!(ShowCodeActions);
|
||||
action!(ConfirmCompletion, Option<usize>);
|
||||
|
||||
pub fn init(cx: &mut MutableAppContext, path_openers: &mut Vec<Box<dyn PathOpener>>) {
|
||||
@@ -239,6 +240,7 @@ pub fn init(cx: &mut MutableAppContext, path_openers: &mut Vec<Box<dyn PathOpene
|
||||
Binding::new("alt-cmd-]", Unfold, Some("Editor")),
|
||||
Binding::new("alt-cmd-f", FoldSelectedRanges, Some("Editor")),
|
||||
Binding::new("ctrl-space", ShowCompletions, Some("Editor")),
|
||||
Binding::new("cmd-.", ShowCodeActions, Some("Editor")),
|
||||
]);
|
||||
|
||||
cx.add_action(Editor::open_new);
|
||||
@@ -303,6 +305,7 @@ pub fn init(cx: &mut MutableAppContext, path_openers: &mut Vec<Box<dyn PathOpene
|
||||
cx.add_action(Editor::unfold);
|
||||
cx.add_action(Editor::fold_selected_ranges);
|
||||
cx.add_action(Editor::show_completions);
|
||||
cx.add_action(Editor::show_code_actions);
|
||||
cx.add_action(
|
||||
|editor: &mut Editor, &ConfirmCompletion(ix): &ConfirmCompletion, cx| {
|
||||
if let Some(task) = editor.confirm_completion(ix, cx) {
|
||||
@@ -1721,6 +1724,22 @@ impl Editor {
|
||||
self.completion_tasks.push((id, task));
|
||||
}
|
||||
|
||||
fn show_code_actions(&mut self, _: &ShowCodeActions, cx: &mut ViewContext<Self>) {
|
||||
let position = if let Some(selection) = self.newest_anchor_selection() {
|
||||
selection.head()
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
let actions = self
|
||||
.buffer
|
||||
.update(cx, |buffer, cx| buffer.code_actions(position.clone(), cx));
|
||||
cx.spawn(|this, cx| async move {
|
||||
dbg!(actions.await.unwrap());
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
fn hide_completions(&mut self, cx: &mut ViewContext<Self>) -> Option<CompletionState> {
|
||||
cx.notify();
|
||||
self.completion_tasks.clear();
|
||||
|
||||
@@ -860,6 +860,21 @@ impl MultiBuffer {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn code_actions<T>(
|
||||
&self,
|
||||
position: T,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Vec<lsp::CodeAction>>>
|
||||
where
|
||||
T: ToOffset,
|
||||
{
|
||||
let anchor = self.read(cx).anchor_before(position);
|
||||
let buffer = self.buffers.borrow()[&anchor.buffer_id].buffer.clone();
|
||||
let code_actions =
|
||||
buffer.update(cx, |buffer, cx| buffer.code_actions(anchor.text_anchor, cx));
|
||||
cx.spawn(|this, cx| async move { code_actions.await })
|
||||
}
|
||||
|
||||
pub fn completions<T>(
|
||||
&self,
|
||||
position: T,
|
||||
|
||||
Reference in New Issue
Block a user