This commit is contained in:
Antonio Scandurra
2022-01-31 19:12:35 +01:00
parent bd2527e691
commit 03bcbdc33d
3 changed files with 122 additions and 0 deletions
+12
View File
@@ -117,6 +117,7 @@ action!(Unfold);
action!(FoldSelectedRanges);
action!(Scroll, Vector2F);
action!(Select, SelectPhase);
action!(ShowAutocomplete);
pub fn init(cx: &mut MutableAppContext, path_openers: &mut Vec<Box<dyn PathOpener>>) {
path_openers.push(Box::new(items::BufferOpener));
@@ -224,6 +225,7 @@ pub fn init(cx: &mut MutableAppContext, path_openers: &mut Vec<Box<dyn PathOpene
Binding::new("alt-cmd-[", Fold, Some("Editor")),
Binding::new("alt-cmd-]", Unfold, Some("Editor")),
Binding::new("alt-cmd-f", FoldSelectedRanges, Some("Editor")),
Binding::new("ctrl-shift-A", ShowAutocomplete, Some("Editor")),
]);
cx.add_action(Editor::open_new);
@@ -287,6 +289,7 @@ pub fn init(cx: &mut MutableAppContext, path_openers: &mut Vec<Box<dyn PathOpene
cx.add_action(Editor::fold);
cx.add_action(Editor::unfold);
cx.add_action(Editor::fold_selected_ranges);
cx.add_action(Editor::show_autocomplete);
}
trait SelectionExt {
@@ -1495,6 +1498,15 @@ impl Editor {
}
}
fn show_autocomplete(&mut self, _: &ShowAutocomplete, cx: &mut ViewContext<Self>) {
let position = self
.newest_selection::<usize>(&self.buffer.read(cx).read(cx))
.head();
self.buffer
.update(cx, |buffer, cx| buffer.completions(position, cx))
.detach_and_log_err(cx);
}
pub fn clear(&mut self, cx: &mut ViewContext<Self>) {
self.start_transaction(cx);
self.select_all(&SelectAll, cx);
+13
View File
@@ -5,6 +5,7 @@ use anyhow::Result;
use clock::ReplicaId;
use collections::{HashMap, HashSet};
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
pub use language::Completion;
use language::{
Buffer, BufferChunks, BufferSnapshot, Chunk, DiagnosticEntry, Event, File, Language, Outline,
OutlineItem, Selection, ToOffset as _, ToPoint as _, TransactionId,
@@ -847,6 +848,18 @@ impl MultiBuffer {
})
}
pub fn completions<T>(
&self,
position: T,
cx: &mut ModelContext<Self>,
) -> Task<Result<Vec<Completion>>>
where
T: ToOffset,
{
let (buffer, text_anchor) = self.text_anchor_for_position(position, cx);
buffer.update(cx, |buffer, cx| buffer.completions(text_anchor, cx))
}
pub fn language<'a>(&self, cx: &'a AppContext) -> Option<&'a Arc<Language>> {
self.buffers
.borrow()