Skip to main content

rez_lsp_server/config/
mod.rs

1//! Configuration management for the Rez LSP server.
2
3mod provider;
4
5pub use provider::RezConfigProvider;
6
7use crate::core::{ConfigError, Result};
8use std::path::PathBuf;
9
10/// Configuration for the Rez LSP server.
11#[derive(Debug, Clone)]
12pub struct Config {
13    /// Package search paths
14    pub packages_path: Vec<PathBuf>,
15    /// Local packages path
16    pub local_packages_path: Option<PathBuf>,
17    /// Release packages path
18    pub release_packages_path: Option<PathBuf>,
19    /// Maximum number of packages to cache
20    pub max_cache_size: usize,
21    /// Cache expiration time in seconds
22    pub cache_expiration_secs: u64,
23    /// Enable debug logging
24    pub debug_logging: bool,
25}
26
27impl Config {
28    /// Create a new configuration with default values.
29    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, // 1 hour
36            debug_logging: false,
37        }
38    }
39
40    /// Validate the configuration.
41    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    /// Get all package search paths in priority order.
61    pub fn get_all_package_paths(&self) -> Vec<PathBuf> {
62        let mut all_paths = Vec::new();
63
64        // Local packages have highest priority
65        if let Some(ref local_path) = self.local_packages_path {
66            all_paths.push(local_path.clone());
67        }
68
69        // Then the main packages path
70        all_paths.extend(self.packages_path.iter().cloned());
71
72        // Release packages have lowest priority
73        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}