use rustyline::completion::Pair;
impl super::SqlCompleter {
pub(super) fn complete_debug(&self, text_before_cursor: &str) -> Option<Vec<Pair>> {
if !text_before_cursor.trim_start().starts_with(r"\debug ") {
return None;
}
let debug_start = text_before_cursor.find(r"\debug ").unwrap() + 7;
let partial_arg = &text_before_cursor[debug_start..].trim();
let mut completions = Vec::new();
if "state".starts_with(&partial_arg.to_lowercase()) {
completions.push(Pair {
display: "state".to_string(),
replacement: "state".to_string(),
});
}
if "refresh-schema".starts_with(&partial_arg.to_lowercase()) {
completions.push(Pair {
display: "refresh-schema".to_string(),
replacement: "refresh-schema".to_string(),
});
}
if "redactions".starts_with(&partial_arg.to_lowercase()) {
completions.push(Pair {
display: "redactions".to_string(),
replacement: "redactions".to_string(),
});
}
Some(completions)
}
}
#[cfg(test)]
mod tests {
use crate::completer::*;
#[test]
fn test_debug_command_completion() {
let completer = SqlCompleter::new(Theme::Dark);
let completions = completer.find_completions("\\", 1);
assert!(completions.iter().any(|c| c.display == "\\debug"));
}
#[test]
fn test_debug_state_argument_completion() {
let completer = SqlCompleter::new(Theme::Dark);
let input = "\\debug ";
let completions = completer.find_completions(input, input.len());
assert!(!completions.is_empty());
assert!(completions.iter().any(|c| c.display == "state"));
assert!(completions.iter().any(|c| c.display == "refresh-schema"));
assert!(completions.iter().any(|c| c.display == "redactions"));
let input = "\\debug st";
let completions = completer.find_completions(input, input.len());
assert!(!completions.is_empty());
assert!(completions.iter().any(|c| c.display == "state"));
let input = "\\debug ref";
let completions = completer.find_completions(input, input.len());
assert!(!completions.is_empty());
assert!(completions.iter().any(|c| c.display == "refresh-schema"));
let input = "\\debug state";
let completions = completer.find_completions(input, input.len());
assert!(!completions.is_empty());
assert!(completions.iter().any(|c| c.display == "state"));
}
}