@@ -814,6 +814,7 @@ mod cmd {
814814 use std::collections::HashMap;
815815
816816 use helix_view::editor::Action;
817+ use ui::completers::{self, Completer};
817818
818819 #[derive(Clone)]
819820 pub struct Command {
@@ -822,6 +823,7 @@ mod cmd {
822823 pub doc: &'static str,
823824 // params, flags, helper, completer
824825 pub fun: fn(&mut Editor, &[&str], PromptEvent),
826+ pub completer: Option<Completer>,
825827 }
826828
827829 fn quit(editor: &mut Editor, args: &[&str], event: PromptEvent) {
@@ -878,30 +880,35 @@ mod cmd {
878880 alias: Some("q"),
879881 doc: "Close the current view.",
880882 fun: quit,
883+ completer: None,
881884 },
882885 Command {
883886 name: "quit!",
884887 alias: Some("q!"),
885888 doc: "Close the current view.",
886889 fun: force_quit,
890+ completer: None,
887891 },
888892 Command {
889893 name: "open",
890894 alias: Some("o"),
891895 doc: "Open a file from disk into the current view.",
892896 fun: open,
897+ completer: Some(completers::filename),
893898 },
894899 Command {
895900 name: "write",
896901 alias: Some("w"),
897902 doc: "Write changes to disk.",
898903 fun: write,
904+ completer: Some(completers::filename),
899905 },
900906 Command {
901907 name: "new",
902908 alias: Some("n"),
903909 doc: "Create a new scratch buffer.",
904910 fun: new_file,
911+ completer: Some(completers::filename),
905912 },
906913 ];
907914
@@ -920,14 +927,17 @@ mod cmd {
920927}
921928
922929pub fn command_mode(cx: &mut Context) {
930+ // TODO: completion items should have a info section that would get displayed in
931+ // a popup above the prompt when items are tabbed over
932+
923933 let prompt = Prompt::new(
924934 ":".to_owned(),
925935 |input: &str| {
926936 // we use .this over split_ascii_whitespace() because we care about empty segments
927937 let parts = input.split(' ').collect::<Vec<&str>>();
928938
929− // simple heuristic: if there's no space, complete command.
930− // if there's a space, file completion kicks in. We should specialize by command later.
939+ // simple heuristic: if there's no just one part, complete command name.
940+ // if there's a space, per command completion kicks in.
931941 if parts.len() <= 1 {
932942 use std::{borrow::Cow, ops::Range};
933943 let end = 0..;
@@ -938,19 +948,24 @@ pub fn command_mode(cx: &mut Context) {
938948 .collect()
939949 } else {
940950 let part = parts.last().unwrap();
941− ui::completers::filename(part)
942− .into_iter()
943− .map(|(range, file)| {
944− // offset ranges to input
945− let offset = input.len() - part.len();
946− let range = (range.start + offset)..;
947− (range, file)
948− })
949− .collect()
950951
951− // TODO
952− // additionally, completion items could have a info section that would get
953− // displayed in a popup above the prompt when items are tabbed over
952+ if let Some(cmd::Command {
953+ completer: Some(completer),
954+ ..
955+ }) = cmd::COMMANDS.get(parts[0])
956+ {
957+ completer(part)
958+ .into_iter()
959+ .map(|(range, file)| {
960+ // offset ranges to input
961+ let offset = input.len() - part.len();
962+ let range = (range.start + offset)..;
963+ (range, file)
964+ })
965+ .collect()
966+ } else {
967+ Vec::new()
968+ }
954969 }
955970 }, // completion
956971 move |editor: &mut Editor, input: &str, event: PromptEvent| {