mcpls_core/config/
server.rs

1//! LSP server configuration types.
2
3use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7/// Configuration for a single LSP server.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(deny_unknown_fields)]
10pub struct LspServerConfig {
11    /// Language identifier (e.g., "rust", "python", "typescript").
12    pub language_id: String,
13
14    /// Command to start the LSP server.
15    pub command: String,
16
17    /// Arguments to pass to the LSP server command.
18    #[serde(default)]
19    pub args: Vec<String>,
20
21    /// Environment variables for the LSP server process.
22    #[serde(default)]
23    pub env: HashMap<String, String>,
24
25    /// File patterns this server handles (glob patterns).
26    #[serde(default)]
27    pub file_patterns: Vec<String>,
28
29    /// LSP initialization options (server-specific).
30    #[serde(default)]
31    pub initialization_options: Option<serde_json::Value>,
32
33    /// Request timeout in seconds.
34    #[serde(default = "default_timeout")]
35    pub timeout_seconds: u64,
36}
37
38const fn default_timeout() -> u64 {
39    30
40}
41
42impl LspServerConfig {
43    /// Create a default configuration for rust-analyzer.
44    #[must_use]
45    pub fn rust_analyzer() -> Self {
46        Self {
47            language_id: "rust".to_string(),
48            command: "rust-analyzer".to_string(),
49            args: vec![],
50            env: HashMap::new(),
51            file_patterns: vec!["**/*.rs".to_string()],
52            initialization_options: None,
53            timeout_seconds: default_timeout(),
54        }
55    }
56
57    /// Create a default configuration for pyright.
58    #[must_use]
59    pub fn pyright() -> Self {
60        Self {
61            language_id: "python".to_string(),
62            command: "pyright-langserver".to_string(),
63            args: vec!["--stdio".to_string()],
64            env: HashMap::new(),
65            file_patterns: vec!["**/*.py".to_string()],
66            initialization_options: None,
67            timeout_seconds: default_timeout(),
68        }
69    }
70
71    /// Create a default configuration for TypeScript language server.
72    #[must_use]
73    pub fn typescript() -> Self {
74        Self {
75            language_id: "typescript".to_string(),
76            command: "typescript-language-server".to_string(),
77            args: vec!["--stdio".to_string()],
78            env: HashMap::new(),
79            file_patterns: vec!["**/*.ts".to_string(), "**/*.tsx".to_string()],
80            initialization_options: None,
81            timeout_seconds: default_timeout(),
82        }
83    }
84}