@@ -3,7 +3,7 @@ use crate::{
33    document:: { Mode ,  SCRATCH_BUFFER_NAME } , 
44    graphics:: { CursorKind ,  Rect } , 
55    info:: Info , 
6-     input:: KeyEvent , 
6+     input:: { set_config_error ,   KeyEvent } , 
77    theme:: { self ,  Theme } , 
88    tree:: { self ,  Tree } , 
99    Document ,  DocumentId ,  View ,  ViewId , 
@@ -40,6 +40,20 @@ use helix_dap as dap;
4040
4141use  serde:: { ser:: SerializeMap ,  Deserialize ,  Deserializer ,  Serialize } ; 
4242
43+ pub  fn  ok_or_default < ' a ,  T ,  D > ( deserializer :  D )  -> Result < T ,  D :: Error > 
44+ where 
45+     T :  Deserialize < ' a >  + Default , 
46+     D :  Deserializer < ' a > , 
47+ { 
48+     let  result = T :: deserialize ( deserializer) ; 
49+     if  let  Err ( ref  error)  = result { 
50+         // FIXME: the error message does not contain the key or the position. 
51+         eprintln ! ( "Bad config for value: {}" ,  error) ; 
52+         set_config_error ( ) ; 
53+     } 
54+     Ok ( result. unwrap_or_default ( ) ) 
55+ } 
56+ 
4357fn  deserialize_duration_millis < ' de ,  D > ( deserializer :  D )  -> Result < Duration ,  D :: Error > 
4458where 
4559    D :  serde:: Deserializer < ' de > , 
4963} 
5064
5165#[ derive( Debug ,  Clone ,  PartialEq ,  Serialize ,  Deserialize ) ]  
52- #[ serde( rename_all = "kebab-case" ,  default ,  deny_unknown_fields ) ]  
66+ #[ serde( rename_all = "kebab-case" ,  default ) ]  
5367pub  struct  FilePickerConfig  { 
5468    /// IgnoreOptions 
5569/// Enables ignoring hidden files. 
@@ -88,45 +102,61 @@ impl Default for FilePickerConfig {
88102    } 
89103} 
90104
105+ // NOTE: The fields in this struct use the deserializer ok_or_default to continue parsing when 
106+ // there is an error. In that case, it will use the default value. 
91107#[ derive( Debug ,  Clone ,  PartialEq ,  Serialize ,  Deserialize ) ]  
92- #[ serde( rename_all = "kebab-case" ,  default ,  deny_unknown_fields ) ]  
108+ #[ serde( rename_all = "kebab-case" ,  default ) ]  
93109pub  struct  Config  { 
94110    /// Padding to keep between the edge of the screen and the cursor when scrolling. Defaults to 5. 
111+ #[ serde( deserialize_with = "ok_or_default" ) ]  
95112    pub  scrolloff :  usize , 
96113    /// Number of lines to scroll at once. Defaults to 3 
114+ #[ serde( deserialize_with = "ok_or_default" ) ]  
97115    pub  scroll_lines :  isize , 
98116    /// Mouse support. Defaults to true. 
117+ #[ serde( deserialize_with = "ok_or_default" ) ]  
99118    pub  mouse :  bool , 
100119    /// Shell to use for shell commands. Defaults to ["cmd", "/C"] on Windows and ["sh", "-c"] otherwise. 
120+ #[ serde( deserialize_with = "ok_or_default" ) ]  
101121    pub  shell :  Vec < String > , 
102122    /// Line number mode. 
123+ #[ serde( deserialize_with = "ok_or_default" ) ]  
103124    pub  line_number :  LineNumber , 
104125    /// Middle click paste support. Defaults to true. 
126+ #[ serde( deserialize_with = "ok_or_default" ) ]  
105127    pub  middle_click_paste :  bool , 
106128    /// Automatic insertion of pairs to parentheses, brackets, 
107129/// etc. Optionally, this can be a list of 2-tuples to specify a 
108130/// global list of characters to pair. Defaults to true. 
131+ #[ serde( deserialize_with = "ok_or_default" ) ]  
109132    pub  auto_pairs :  AutoPairConfig , 
110133    /// Automatic auto-completion, automatically pop up without user trigger. Defaults to true. 
134+ #[ serde( deserialize_with = "ok_or_default" ) ]  
111135    pub  auto_completion :  bool , 
112136    /// Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. Defaults to 400ms. 
113137#[ serde( skip_serializing,  deserialize_with = "deserialize_duration_millis" ) ]  
114138    pub  idle_timeout :  Duration , 
139+     #[ serde( deserialize_with = "ok_or_default" ) ]  
115140    pub  completion_trigger_len :  u8 , 
116141    /// Whether to display infoboxes. Defaults to true. 
142+ #[ serde( deserialize_with = "ok_or_default" ) ]  
117143    pub  auto_info :  bool , 
144+     #[ serde( deserialize_with = "ok_or_default" ) ]  
118145    pub  file_picker :  FilePickerConfig , 
119146    /// Shape for cursor in each mode 
147+ #[ serde( deserialize_with = "ok_or_default" ) ]  
120148    pub  cursor_shape :  CursorShapeConfig , 
121149    /// Set to `true` to override automatic detection of terminal truecolor support in the event of a false negative. Defaults to `false`. 
150+ #[ serde( deserialize_with = "ok_or_default" ) ]  
122151    pub  true_color :  bool , 
123152    /// Search configuration. 
124153#[ serde( default ) ]  
154+     #[ serde( deserialize_with = "ok_or_default" ) ]  
125155    pub  search :  SearchConfig , 
126156} 
127157
128158#[ derive( Debug ,  Clone ,  PartialEq ,  Serialize ,  Deserialize ) ]  
129- #[ serde( rename_all = "kebab-case" ,  default ,  deny_unknown_fields ) ]  
159+ #[ serde( rename_all = "kebab-case" ,  default ) ]  
130160pub  struct  SearchConfig  { 
131161    /// Smart case: Case insensitive searching unless pattern contains upper case characters. Defaults to true. 
132162pub  smart_case :  bool , 
@@ -199,6 +229,12 @@ pub enum LineNumber {
199229Relative , 
200230} 
201231
232+ impl  Default  for  LineNumber  { 
233+     fn  default ( )  -> Self  { 
234+         Self :: Absolute 
235+     } 
236+ } 
237+ 
202238impl  std:: str:: FromStr  for  LineNumber  { 
203239    type  Err  = anyhow:: Error ; 
204240
0 commit comments