1use schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8
9pub mod context_keys {
12 pub const LINE_NUMBERS: &str = "line_numbers";
13 pub const LINE_WRAP: &str = "line_wrap";
14 pub const COMPOSE_MODE: &str = "compose_mode";
15 pub const FILE_EXPLORER: &str = "file_explorer";
16 pub const MENU_BAR: &str = "menu_bar";
17 pub const FILE_EXPLORER_FOCUSED: &str = "file_explorer_focused";
18 pub const MOUSE_CAPTURE: &str = "mouse_capture";
19 pub const MOUSE_HOVER: &str = "mouse_hover";
20 pub const LSP_AVAILABLE: &str = "lsp_available";
21 pub const FILE_EXPLORER_SHOW_HIDDEN: &str = "file_explorer_show_hidden";
22 pub const FILE_EXPLORER_SHOW_GITIGNORED: &str = "file_explorer_show_gitignored";
23 pub const HAS_SELECTION: &str = "has_selection";
24 pub const FORMATTER_AVAILABLE: &str = "formatter_available";
25 pub const INLAY_HINTS: &str = "inlay_hints";
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
30pub struct ProcessLimits {
31 #[serde(default)]
34 pub max_memory_percent: Option<u32>,
35
36 #[serde(default)]
39 pub max_cpu_percent: Option<u32>,
40
41 #[serde(default = "default_true")]
43 pub enabled: bool,
44}
45
46fn default_true() -> bool {
47 true
48}
49
50impl Default for ProcessLimits {
51 fn default() -> Self {
52 Self {
53 max_memory_percent: Some(50), max_cpu_percent: Some(90), enabled: cfg!(target_os = "linux"), }
57 }
58}
59
60impl ProcessLimits {
61 pub fn unlimited() -> Self {
63 Self {
64 max_memory_percent: None,
65 max_cpu_percent: None,
66 enabled: false,
67 }
68 }
69
70 pub fn default_cpu_limit_percent() -> u32 {
72 90
73 }
74}
75
76#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema)]
78#[schemars(extend("x-display-field" = "/command"))]
79pub struct LspServerConfig {
80 #[serde(default)]
83 pub command: String,
84
85 #[serde(default)]
87 pub args: Vec<String>,
88
89 #[serde(default = "default_true")]
91 pub enabled: bool,
92
93 #[serde(default)]
96 pub auto_start: bool,
97
98 #[serde(default)]
100 pub process_limits: ProcessLimits,
101
102 #[serde(default)]
105 pub initialization_options: Option<serde_json::Value>,
106}
107
108impl LspServerConfig {
109 pub fn merge_with_defaults(self, defaults: &LspServerConfig) -> LspServerConfig {
114 LspServerConfig {
115 command: if self.command.is_empty() {
116 defaults.command.clone()
117 } else {
118 self.command
119 },
120 args: if self.args.is_empty() {
121 defaults.args.clone()
122 } else {
123 self.args
124 },
125 enabled: self.enabled,
126 auto_start: self.auto_start,
127 process_limits: self.process_limits,
128 initialization_options: self
129 .initialization_options
130 .or_else(|| defaults.initialization_options.clone()),
131 }
132 }
133}