@@ -4,21 +4,45 @@ use serde_json::Value;
4
4
5
5
use crate :: lsp:: diagnostics:: DiagnosticsConfig ;
6
6
7
- pub struct Setting {
7
+ pub struct Setting < T > {
8
8
pub key : & ' static str ,
9
- pub set : fn ( & mut LspConfig , Value ) ,
9
+ pub set : fn ( & mut T , Value ) ,
10
10
}
11
11
12
- // List of LSP settings for which clients can send `didChangeConfiguration`
13
- // notifications. We register our interest in watching over these settings in
14
- // our `initialized` handler. The `set` methods convert from a json `Value` to
15
- // the expected type, using a default value if the conversion fails.
16
- pub static SETTINGS : & [ Setting ] = & [
12
+ /// List of LSP settings for which clients can send `didChangeConfiguration`
13
+ /// notifications. We register our interest in watching over these settings in
14
+ /// our `initialized` handler. The `set` methods convert from a json `Value` to
15
+ /// the expected type, using a default value if the conversion fails.
16
+ ///
17
+ /// This array is for global settings. If the setting should only affect a given
18
+ /// document URI, add it to `DOCUMENT_SETTINGS` instead.
19
+ pub static GLOBAL_SETTINGS : & [ Setting < LspConfig > ] = & [
20
+ Setting {
21
+ key : "positron.r.diagnostics.enable" ,
22
+ set : |cfg, v| {
23
+ cfg. diagnostics . enable = v
24
+ . as_bool ( )
25
+ . unwrap_or_else ( || DiagnosticsConfig :: default ( ) . enable )
26
+ } ,
27
+ } ,
28
+ Setting {
29
+ key : "positron.r.symbols.includeAssignmentsInBlocks" ,
30
+ set : |cfg, v| {
31
+ cfg. symbols . include_assignments_in_blocks = v
32
+ . as_bool ( )
33
+ . unwrap_or_else ( || SymbolsConfig :: default ( ) . include_assignments_in_blocks )
34
+ } ,
35
+ } ,
36
+ ] ;
37
+
38
+ /// These document settings are updated on a URI basis. Each document has its
39
+ /// own value of the setting.
40
+ pub static DOCUMENT_SETTINGS : & [ Setting < DocumentConfig > ] = & [
17
41
Setting {
18
42
key : "editor.insertSpaces" ,
19
43
set : |cfg, v| {
20
44
let default_style = IndentationConfig :: default ( ) . indent_style ;
21
- cfg. document . indent . indent_style = if v
45
+ cfg. indent . indent_style = if v
22
46
. as_bool ( )
23
47
. unwrap_or_else ( || default_style == IndentStyle :: Space )
24
48
{
@@ -31,7 +55,7 @@ pub static SETTINGS: &[Setting] = &[
31
55
Setting {
32
56
key : "editor.indentSize" ,
33
57
set : |cfg, v| {
34
- cfg. document . indent . indent_size = v
58
+ cfg. indent . indent_size = v
35
59
. as_u64 ( )
36
60
. map ( |n| n as usize )
37
61
. unwrap_or_else ( || IndentationConfig :: default ( ) . indent_size )
@@ -40,36 +64,19 @@ pub static SETTINGS: &[Setting] = &[
40
64
Setting {
41
65
key : "editor.tabSize" ,
42
66
set : |cfg, v| {
43
- cfg. document . indent . tab_width = v
67
+ cfg. indent . tab_width = v
44
68
. as_u64 ( )
45
69
. map ( |n| n as usize )
46
70
. unwrap_or_else ( || IndentationConfig :: default ( ) . tab_width )
47
71
} ,
48
72
} ,
49
- Setting {
50
- key : "positron.r.diagnostics.enable" ,
51
- set : |cfg, v| {
52
- cfg. diagnostics . enable = v
53
- . as_bool ( )
54
- . unwrap_or_else ( || DiagnosticsConfig :: default ( ) . enable )
55
- } ,
56
- } ,
57
- Setting {
58
- key : "positron.r.symbols.includeAssignmentsInBlocks" ,
59
- set : |cfg, v| {
60
- cfg. symbols . include_assignments_in_blocks = v
61
- . as_bool ( )
62
- . unwrap_or_else ( || SymbolsConfig :: default ( ) . include_assignments_in_blocks )
63
- } ,
64
- } ,
65
73
] ;
66
74
67
75
/// Configuration of the LSP
68
76
#[ derive( Clone , Default , Debug ) ]
69
77
pub ( crate ) struct LspConfig {
70
78
pub ( crate ) diagnostics : DiagnosticsConfig ,
71
79
pub ( crate ) symbols : SymbolsConfig ,
72
- pub ( crate ) document : DocumentConfig ,
73
80
}
74
81
75
82
#[ derive( Serialize , Deserialize , Clone , Debug ) ]
0 commit comments