rez_lsp_server/config/
mod.rs1mod provider;
4
5pub use provider::RezConfigProvider;
6
7use crate::core::{ConfigError, Result};
8use std::path::PathBuf;
9
10#[derive(Debug, Clone)]
12pub struct Config {
13 pub packages_path: Vec<PathBuf>,
15 pub local_packages_path: Option<PathBuf>,
17 pub release_packages_path: Option<PathBuf>,
19 pub max_cache_size: usize,
21 pub cache_expiration_secs: u64,
23 pub debug_logging: bool,
25}
26
27impl Config {
28 pub fn new() -> Self {
30 Self {
31 packages_path: Vec::new(),
32 local_packages_path: None,
33 release_packages_path: None,
34 max_cache_size: 10000,
35 cache_expiration_secs: 3600, debug_logging: false,
37 }
38 }
39
40 pub fn validate(&self) -> Result<()> {
42 if self.packages_path.is_empty() {
43 return Err(ConfigError::NoValidPaths.into());
44 }
45
46 let mut valid_paths = 0;
47 for path in &self.packages_path {
48 if path.exists() && path.is_dir() {
49 valid_paths += 1;
50 }
51 }
52
53 if valid_paths == 0 {
54 return Err(ConfigError::NoValidPaths.into());
55 }
56
57 Ok(())
58 }
59
60 pub fn get_all_package_paths(&self) -> Vec<PathBuf> {
62 let mut all_paths = Vec::new();
63
64 if let Some(ref local_path) = self.local_packages_path {
66 all_paths.push(local_path.clone());
67 }
68
69 all_paths.extend(self.packages_path.iter().cloned());
71
72 if let Some(ref release_path) = self.release_packages_path {
74 all_paths.push(release_path.clone());
75 }
76
77 all_paths
78 }
79}
80
81impl Default for Config {
82 fn default() -> Self {
83 Self::new()
84 }
85}