1
1
mod server_command;
2
2
3
- pub use server_command:: * ;
4
-
5
3
use crate :: {
6
4
types:: {
7
5
CodeLensDisplay , DiagnosticsDisplay , DiagnosticsList , DocumentHighlightDisplay ,
@@ -12,6 +10,7 @@ use crate::{
12
10
use anyhow:: { anyhow, Result } ;
13
11
use lsp_types:: { DiagnosticSeverity , MarkupKind , MessageType , TraceOption } ;
14
12
use serde:: Deserialize ;
13
+ pub use server_command:: * ;
15
14
use std:: collections:: HashMap ;
16
15
use std:: { path:: PathBuf , str:: FromStr , time:: Duration } ;
17
16
@@ -32,6 +31,26 @@ impl LoggerConfig {
32
31
}
33
32
}
34
33
34
+ #[ derive( Debug , Clone , Deserialize , PartialEq ) ]
35
+ #[ serde( rename_all = "camelCase" ) ]
36
+ pub struct SemanticTokenMapping {
37
+ pub name : String ,
38
+ #[ serde( default ) ]
39
+ pub modifiers : Vec < String > ,
40
+ pub highlight_group : String ,
41
+ }
42
+
43
+ impl SemanticTokenMapping {
44
+ #[ allow( dead_code) ]
45
+ pub fn new ( name : & str , modifiers : & [ & str ] , highlight_group : & str ) -> Self {
46
+ Self {
47
+ name : name. to_owned ( ) ,
48
+ modifiers : modifiers. iter ( ) . map ( |i| i. to_string ( ) ) . collect ( ) ,
49
+ highlight_group : highlight_group. to_owned ( ) ,
50
+ }
51
+ }
52
+ }
53
+
35
54
#[ derive( Debug ) ]
36
55
pub struct Config {
37
56
pub auto_start : bool ,
@@ -59,22 +78,32 @@ pub struct Config {
59
78
pub selection_ui_auto_open : bool ,
60
79
pub use_virtual_text : UseVirtualText ,
61
80
pub echo_project_root : bool ,
62
- pub semantic_highlight_maps : HashMap < String , HashMap < String , String > > ,
63
- pub semantic_scope_separator : String ,
64
81
pub apply_completion_text_edits : bool ,
65
82
pub preferred_markup_kind : Option < Vec < MarkupKind > > ,
66
83
pub hide_virtual_texts_on_insert : bool ,
67
84
pub enable_extensions : Option < HashMap < String , bool > > ,
68
85
pub restart_on_crash : bool ,
69
86
pub max_restart_retries : u8 ,
87
+ /// semantic_token_mappings is a vec of SemanticTokenMappings, where a SemanticTokenMapping
88
+ /// defines the token type by it's name, the modifiers and the highlight group to be applied to
89
+ /// it.
90
+ ///
91
+ /// If no modifiers are configured for a type it will apply for all tokens of that type.
92
+ ///
93
+ /// For example:
94
+ ///
95
+ /// [
96
+ /// { "name": "function", "modifiers": ["async"], "highlightGroup": "Function" }
97
+ /// { "name": "type", "modifiers": [], "highlightGroup": "Type" }
98
+ /// ]
99
+ pub semantic_token_mappings : Vec < SemanticTokenMapping > ,
100
+ pub semantic_highlighting_enabled : bool ,
70
101
}
71
102
72
103
impl Default for Config {
73
104
fn default ( ) -> Self {
74
105
Self {
75
106
server_commands : HashMap :: new ( ) ,
76
- semantic_highlight_maps : HashMap :: new ( ) ,
77
- semantic_scope_separator : ":" . into ( ) ,
78
107
auto_start : true ,
79
108
selection_ui : SelectionUI :: LocationList ,
80
109
selection_ui_auto_open : true ,
@@ -105,6 +134,8 @@ impl Default for Config {
105
134
is_nvim : false ,
106
135
restart_on_crash : true ,
107
136
max_restart_retries : 5 ,
137
+ semantic_token_mappings : vec ! [ ] ,
138
+ semantic_highlighting_enabled : false ,
108
139
}
109
140
}
110
141
}
@@ -135,15 +166,15 @@ struct DeserializableConfig {
135
166
selection_ui_auto_open : u8 ,
136
167
use_virtual_text : UseVirtualText ,
137
168
echo_project_root : u8 ,
138
- semantic_highlight_maps : HashMap < String , HashMap < String , String > > ,
139
- semantic_scope_separator : String ,
140
169
apply_completion_text_edits : u8 ,
141
170
preferred_markup_kind : Option < Vec < MarkupKind > > ,
142
171
hide_virtual_texts_on_insert : u8 ,
143
172
enable_extensions : Option < HashMap < String , bool > > ,
144
173
code_lens_display : Option < CodeLensDisplay > ,
145
174
restart_on_crash : u8 ,
146
175
max_restart_retries : u8 ,
176
+ semantic_token_mappings : Vec < SemanticTokenMapping > ,
177
+ semantic_highlighting_enabled : u8 ,
147
178
}
148
179
149
180
impl Config {
@@ -172,8 +203,6 @@ impl Config {
172
203
"selection_ui_auto_open": !!s:GetVar('LanguageClient_selectionUI_autoOpen', 1),
173
204
"use_virtual_text": s:useVirtualText(),
174
205
"echo_project_root": !!s:GetVar('LanguageClient_echoProjectRoot', 1),
175
- "semantic_highlight_maps": s:GetVar('LanguageClient_semanticHighlightMaps', {}),
176
- "semantic_scope_separator": s:GetVar('LanguageClient_semanticScopeSeparator', ':'),
177
206
"apply_completion_text_edits": get(g:, 'LanguageClient_applyCompletionAdditionalTextEdits', 1),
178
207
"preferred_markup_kind": get(g:, 'LanguageClient_preferredMarkupKind', v:null),
179
208
"hide_virtual_texts_on_insert": s:GetVar('LanguageClient_hideVirtualTextsOnInsert', 0),
@@ -182,10 +211,11 @@ impl Config {
182
211
"restart_on_crash": get(g:, 'LanguageClient_restartOnCrash', 1),
183
212
"max_restart_retries": get(g:, 'LanguageClient_maxRestartRetries', 5),
184
213
"server_stderr": get(g:, 'LanguageClient_serverStderr', v:null),
214
+ "semantic_token_mappings": get(g:, 'LanguageClient_semanticTokenMappings', []),
215
+ "semantic_highlighting_enabled": get(g:, 'LanguageClient_semanticHighlightingEnabled', 0),
185
216
}"# ;
186
217
187
218
let res: DeserializableConfig = vim. eval ( req. replace ( "\n " , "" ) ) ?;
188
-
189
219
let loaded_fzf = vim. eval :: < _ , i64 > ( "get(g:, 'loaded_fzf')" ) ? == 1 ;
190
220
let selection_ui = match res. selection_ui {
191
221
Some ( s) => SelectionUI :: from_str ( & s) ?,
@@ -238,14 +268,14 @@ impl Config {
238
268
selection_ui_auto_open : res. selection_ui_auto_open == 1 ,
239
269
use_virtual_text : res. use_virtual_text ,
240
270
echo_project_root : res. echo_project_root == 1 ,
241
- semantic_highlight_maps : res. semantic_highlight_maps ,
242
- semantic_scope_separator : res. semantic_scope_separator ,
243
271
apply_completion_text_edits : res. apply_completion_text_edits == 1 ,
244
272
preferred_markup_kind : res. preferred_markup_kind ,
245
273
hide_virtual_texts_on_insert : res. hide_virtual_texts_on_insert == 1 ,
246
274
enable_extensions : res. enable_extensions ,
247
275
restart_on_crash : res. restart_on_crash == 1 ,
248
276
max_restart_retries : res. max_restart_retries ,
277
+ semantic_token_mappings : res. semantic_token_mappings ,
278
+ semantic_highlighting_enabled : res. semantic_highlighting_enabled == 1 ,
249
279
} )
250
280
}
251
281
}
0 commit comments