11mod server_command;
22
3- pub use server_command:: * ;
4-
53use crate :: {
64 types:: {
75 CodeLensDisplay , DiagnosticsDisplay , DiagnosticsList , DocumentHighlightDisplay ,
@@ -12,6 +10,7 @@ use crate::{
1210use anyhow:: { anyhow, Result } ;
1311use lsp_types:: { DiagnosticSeverity , MarkupKind , MessageType , TraceOption } ;
1412use serde:: Deserialize ;
13+ pub use server_command:: * ;
1514use std:: collections:: HashMap ;
1615use std:: { path:: PathBuf , str:: FromStr , time:: Duration } ;
1716
@@ -32,6 +31,26 @@ impl LoggerConfig {
3231 }
3332}
3433
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+
3554#[ derive( Debug ) ]
3655pub struct Config {
3756 pub auto_start : bool ,
@@ -59,22 +78,32 @@ pub struct Config {
5978 pub selection_ui_auto_open : bool ,
6079 pub use_virtual_text : UseVirtualText ,
6180 pub echo_project_root : bool ,
62- pub semantic_highlight_maps : HashMap < String , HashMap < String , String > > ,
63- pub semantic_scope_separator : String ,
6481 pub apply_completion_text_edits : bool ,
6582 pub preferred_markup_kind : Option < Vec < MarkupKind > > ,
6683 pub hide_virtual_texts_on_insert : bool ,
6784 pub enable_extensions : Option < HashMap < String , bool > > ,
6885 pub restart_on_crash : bool ,
6986 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 ,
70101}
71102
72103impl Default for Config {
73104 fn default ( ) -> Self {
74105 Self {
75106 server_commands : HashMap :: new ( ) ,
76- semantic_highlight_maps : HashMap :: new ( ) ,
77- semantic_scope_separator : ":" . into ( ) ,
78107 auto_start : true ,
79108 selection_ui : SelectionUI :: LocationList ,
80109 selection_ui_auto_open : true ,
@@ -105,6 +134,8 @@ impl Default for Config {
105134 is_nvim : false ,
106135 restart_on_crash : true ,
107136 max_restart_retries : 5 ,
137+ semantic_token_mappings : vec ! [ ] ,
138+ semantic_highlighting_enabled : false ,
108139 }
109140 }
110141}
@@ -135,15 +166,15 @@ struct DeserializableConfig {
135166 selection_ui_auto_open : u8 ,
136167 use_virtual_text : UseVirtualText ,
137168 echo_project_root : u8 ,
138- semantic_highlight_maps : HashMap < String , HashMap < String , String > > ,
139- semantic_scope_separator : String ,
140169 apply_completion_text_edits : u8 ,
141170 preferred_markup_kind : Option < Vec < MarkupKind > > ,
142171 hide_virtual_texts_on_insert : u8 ,
143172 enable_extensions : Option < HashMap < String , bool > > ,
144173 code_lens_display : Option < CodeLensDisplay > ,
145174 restart_on_crash : u8 ,
146175 max_restart_retries : u8 ,
176+ semantic_token_mappings : Vec < SemanticTokenMapping > ,
177+ semantic_highlighting_enabled : u8 ,
147178}
148179
149180impl Config {
@@ -172,8 +203,6 @@ impl Config {
172203 "selection_ui_auto_open": !!s:GetVar('LanguageClient_selectionUI_autoOpen', 1),
173204 "use_virtual_text": s:useVirtualText(),
174205 "echo_project_root": !!s:GetVar('LanguageClient_echoProjectRoot', 1),
175- "semantic_highlight_maps": s:GetVar('LanguageClient_semanticHighlightMaps', {}),
176- "semantic_scope_separator": s:GetVar('LanguageClient_semanticScopeSeparator', ':'),
177206 "apply_completion_text_edits": get(g:, 'LanguageClient_applyCompletionAdditionalTextEdits', 1),
178207 "preferred_markup_kind": get(g:, 'LanguageClient_preferredMarkupKind', v:null),
179208 "hide_virtual_texts_on_insert": s:GetVar('LanguageClient_hideVirtualTextsOnInsert', 0),
@@ -182,10 +211,11 @@ impl Config {
182211 "restart_on_crash": get(g:, 'LanguageClient_restartOnCrash', 1),
183212 "max_restart_retries": get(g:, 'LanguageClient_maxRestartRetries', 5),
184213 "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),
185216 }"# ;
186217
187218 let res: DeserializableConfig = vim. eval ( req. replace ( "\n " , "" ) ) ?;
188-
189219 let loaded_fzf = vim. eval :: < _ , i64 > ( "get(g:, 'loaded_fzf')" ) ? == 1 ;
190220 let selection_ui = match res. selection_ui {
191221 Some ( s) => SelectionUI :: from_str ( & s) ?,
@@ -238,14 +268,14 @@ impl Config {
238268 selection_ui_auto_open : res. selection_ui_auto_open == 1 ,
239269 use_virtual_text : res. use_virtual_text ,
240270 echo_project_root : res. echo_project_root == 1 ,
241- semantic_highlight_maps : res. semantic_highlight_maps ,
242- semantic_scope_separator : res. semantic_scope_separator ,
243271 apply_completion_text_edits : res. apply_completion_text_edits == 1 ,
244272 preferred_markup_kind : res. preferred_markup_kind ,
245273 hide_virtual_texts_on_insert : res. hide_virtual_texts_on_insert == 1 ,
246274 enable_extensions : res. enable_extensions ,
247275 restart_on_crash : res. restart_on_crash == 1 ,
248276 max_restart_retries : res. max_restart_retries ,
277+ semantic_token_mappings : res. semantic_token_mappings ,
278+ semantic_highlighting_enabled : res. semantic_highlighting_enabled == 1 ,
249279 } )
250280 }
251281}
0 commit comments