aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs42
1 files changed, 31 insertions, 11 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 6a678de1..f3761d7d 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1310,7 +1310,8 @@ fn global_search(cx: &mut Context) {
cx.push_layer(Box::new(prompt));
- let root = find_root(None).unwrap_or_else(|| PathBuf::from("./"));
+ let current_path = doc_mut!(cx.editor).path().cloned();
+
let show_picker = async move {
let all_matches: Vec<(usize, PathBuf)> =
UnboundedReceiverStream::new(all_matches_rx).collect().await;
@@ -1320,14 +1321,19 @@ fn global_search(cx: &mut Context) {
editor.set_status("No matches found".to_string());
return;
}
+
let picker = FilePicker::new(
all_matches,
move |(_line_num, path)| {
- path.strip_prefix(&root)
- .unwrap_or(path)
+ let relative_path = helix_core::path::get_relative_path(path)
.to_str()
.unwrap()
- .into()
+ .to_owned();
+ if current_path.as_ref().map(|p| p == path).unwrap_or(false) {
+ format!("{} (*)", relative_path).into()
+ } else {
+ relative_path.into()
+ }
},
move |editor: &mut Editor, (line_num, path), action| {
match editor.open(path.into(), action) {
@@ -4160,7 +4166,7 @@ fn remove_primary_selection(cx: &mut Context) {
doc.set_selection(view.id, selection);
}
-fn completion(cx: &mut Context) {
+pub fn completion(cx: &mut Context) {
// trigger on trigger char, or if user calls it
// (or on word char typing??)
// after it's triggered, if response marked is_incomplete, update on every subsequent keypress
@@ -4205,10 +4211,8 @@ fn completion(cx: &mut Context) {
};
let offset_encoding = language_server.offset_encoding();
- let cursor = doc
- .selection(view.id)
- .primary()
- .cursor(doc.text().slice(..));
+ let text = doc.text().slice(..);
+ let cursor = doc.selection(view.id).primary().cursor(text);
let pos = pos_to_lsp_pos(doc.text(), cursor, offset_encoding);
@@ -4216,6 +4220,15 @@ fn completion(cx: &mut Context) {
let trigger_offset = cursor;
+ // TODO: trigger_offset should be the cursor offset but we also need a starting offset from where we want to apply
+ // completion filtering. For example logger.te| should filter the initial suggestion list with "te".
+
+ use helix_core::chars;
+ let mut iter = text.chars_at(cursor);
+ iter.reverse();
+ let offset = iter.take_while(|ch| chars::char_is_word(*ch)).count();
+ let start_offset = cursor.saturating_sub(offset);
+
cx.callback(
future,
move |editor: &mut Editor,
@@ -4238,7 +4251,7 @@ fn completion(cx: &mut Context) {
};
if items.is_empty() {
- editor.set_error("No completion available".to_string());
+ // editor.set_error("No completion available".to_string());
return;
}
let size = compositor.size();
@@ -4246,7 +4259,14 @@ fn completion(cx: &mut Context) {
.find(std::any::type_name::<ui::EditorView>())
.unwrap();
if let Some(ui) = ui.as_any_mut().downcast_mut::<ui::EditorView>() {
- ui.set_completion(items, offset_encoding, trigger_offset, size);
+ ui.set_completion(
+ editor,
+ items,
+ offset_encoding,
+ start_offset,
+ trigger_offset,
+ size,
+ );
};
},
);