use crate::ported::bindings::vim::create_ruby_dpowerline;
use serde_json::{json, Value};
use std::collections::HashSet;
use std::sync::OnceLock;
static INITIALIZED: OnceLock<bool> = OnceLock::new();
pub fn initialize() {
INITIALIZED.get_or_init(|| {
create_ruby_dpowerline();
true
});
}
pub fn finder(_pl: &()) -> Vec<Value> {
initialize();
vec![json!({
"highlight_groups": ["commandt:finder"],
"contents": ""
})]
}
#[allow(non_snake_case)]
pub fn FINDERS_WITHOUT_PATH() -> &'static HashSet<&'static str> {
static S: OnceLock<HashSet<&'static str>> = OnceLock::new();
S.get_or_init(|| {
let mut s = HashSet::new();
s.insert("CommandT::MRUBufferFinder");
s.insert("CommandT::BufferFinder");
s.insert("CommandT::TagFinder");
s.insert("CommandT::JumpFinder");
s.insert("CommandT::Finder::MRUBufferFinder");
s.insert("CommandT::Finder::BufferFinder");
s.insert("CommandT::Finder::TagFinder");
s.insert("CommandT::Finder::JumpFinder");
s
})
}
pub fn path(_pl: &()) -> Option<Vec<Value>> {
initialize();
let finder = "";
if FINDERS_WITHOUT_PATH().contains(finder) {
return None;
}
Some(vec![json!({
"highlight_groups": ["commandt:path"],
"contents": ""
})])
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn finders_without_path_includes_buffer_finder() {
let s = FINDERS_WITHOUT_PATH();
assert!(s.contains("CommandT::BufferFinder"));
assert!(s.contains("CommandT::Finder::TagFinder"));
assert_eq!(s.len(), 8);
}
#[test]
fn finder_returns_one_segment_with_empty_contents() {
let r = finder(&());
assert_eq!(r.len(), 1);
}
#[test]
fn path_returns_some_when_finder_not_excluded() {
let r = path(&());
assert!(r.is_some());
}
#[test]
fn initialize_is_idempotent() {
initialize();
initialize();
}
}