mcpls_core/config/
server.rs1use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(deny_unknown_fields)]
10pub struct LspServerConfig {
11 pub language_id: String,
13
14 pub command: String,
16
17 #[serde(default)]
19 pub args: Vec<String>,
20
21 #[serde(default)]
23 pub env: HashMap<String, String>,
24
25 #[serde(default)]
27 pub file_patterns: Vec<String>,
28
29 #[serde(default)]
31 pub initialization_options: Option<serde_json::Value>,
32
33 #[serde(default = "default_timeout")]
35 pub timeout_seconds: u64,
36}
37
38const fn default_timeout() -> u64 {
39 30
40}
41
42impl LspServerConfig {
43 #[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 #[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 #[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}