fix: `.starter` tab completion (#709)

pull/710/head
sigoden 3 months ago committed by GitHub
parent cfcf624e3b
commit 3360cfaf23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1149,9 +1149,16 @@ impl Config {
.or_else(|| env::var("VISUAL").ok().or_else(|| env::var("EDITOR").ok()))
}
pub fn repl_complete(&self, cmd: &str, args: &[&str]) -> Vec<(String, Option<String>)> {
let (values, filter) = if args.len() == 1 {
let values = match cmd {
pub fn repl_complete(
&self,
cmd: &str,
args: &[&str],
line: &str,
) -> Vec<(String, Option<String>)> {
let mut values: Vec<(String, Option<String>)> = vec![];
let mut filter = "";
if args.len() == 1 {
values = match cmd {
".role" => self
.roles
.iter()
@ -1203,9 +1210,9 @@ impl Config {
.collect(),
_ => vec![],
};
(values, args[0])
} else if args.len() == 2 && cmd == ".set" {
let values = match args[0] {
filter = args[0]
} else if cmd == ".set" && args.len() == 2 {
let candidates = match args[0] {
"max_output_tokens" => match self.model.max_output_tokens() {
Some(v) => vec![v.to_string()],
None => vec![],
@ -1242,9 +1249,16 @@ impl Config {
"highlight" => complete_bool(self.highlight),
_ => vec![],
};
(values.into_iter().map(|v| (v, None)).collect(), args[1])
} else {
return vec![];
values = candidates.into_iter().map(|v| (v, None)).collect();
filter = args[1];
} else if cmd == ".starter" && args.len() >= 2 {
if let Some(agent) = &self.agent {
values = agent
.conversation_staters()
.iter()
.filter_map(|v| v.strip_prefix(line).map(|x| (x.to_string(), None)))
.collect()
}
};
values
.into_iter()

@ -48,13 +48,18 @@ impl Completer for ReplCompleter {
if parts_len > 1 {
let span = Span::new(parts[parts_len - 1].1, pos);
let args_line = &line[parts[1].1..];
let args: Vec<&str> = parts.iter().skip(1).map(|(v, _)| *v).collect();
suggestions.extend(self.config.read().repl_complete(cmd, &args).iter().map(
|(value, description)| {
let description = description.as_deref().unwrap_or_default();
create_suggestion(value, description, span)
},
))
suggestions.extend(
self.config
.read()
.repl_complete(cmd, &args, args_line)
.iter()
.map(|(value, description)| {
let description = description.as_deref().unwrap_or_default();
create_suggestion(value, description, span)
}),
)
}
if suggestions.is_empty() {

Loading…
Cancel
Save