use std::process::Command;

use log::info;

use crate::server::LspServer;

pub fn is_command_valid(
    command: &str,
    server: &LspServer
) -> bool {
    let cache_info = server.cache.cache_info.read().unwrap();
        
    let cwd = match &cache_info.linter_cache {
        Some(pc) => pc,
        None => {
            info!("缓存系统尚未完成初始化，获取命令有效性取消");
            return false;
        }
    };

    // 尝试执行命令
    match Command::new(command)
        .current_dir(cwd)
        .output() {
        Ok(_) => true,
        Err(_) => false,
    }
}
