Skip to content

Commit 17a579d

Browse files
authored
Use LCN defined highlights and introduce CodeLensDisplay config (#1144)
1 parent 5887f98 commit 17a579d

File tree

4 files changed

+75
-27
lines changed

4 files changed

+75
-27
lines changed

autoload/LanguageClient.vim

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,35 @@ let s:POPUP_WINDOW_AVAILABLE = exists('*popup_atcursor')
1414
" timers to control throttling
1515
let s:timers = {}
1616

17+
if !hlexists('LanguageClientCodeLens')
18+
hi link LanguageClientCodeLens Title
19+
endif
20+
21+
if !hlexists('LanguageClientWarningSign')
22+
hi link LanguageClientWarningSign todo
23+
endif
24+
25+
if !hlexists('LanguageClientWarning')
26+
hi link LanguageClientWarning SpellCap
27+
endif
28+
29+
if !hlexists('LanguageClientInfoSign')
30+
hi link LanguageClientInfoSign LanguageClientWarningSign
31+
endif
32+
33+
if !hlexists('LanguageClientInfo')
34+
hi link LanguageClientInfo LanguageClientWarning
35+
endif
36+
37+
if !hlexists('LanguageClientErrorSign')
38+
hi link LanguageClientErrorSign error
39+
endif
40+
41+
if !hlexists('LanguageClientError')
42+
hi link LanguageClientError SpellBad
43+
endif
44+
45+
1746
function! s:AddPrefix(message) abort
1847
return '[LC] ' . a:message
1948
endfunction

doc/LanguageClient.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,30 +103,30 @@ Default: >
103103
{
104104
1: {
105105
"name": "Error",
106-
"texthl": "ALEError",
106+
"texthl": "LanguageClientError",
107107
"signText": "✖",
108-
"signTexthl": "ALEErrorSign",
108+
"signTexthl": "LanguageClientErrorSign",
109109
"virtualTexthl": "Error",
110110
},
111111
2: {
112112
"name": "Warning",
113-
"texthl": "ALEWarning",
113+
"texthl": "LanguageClientWarning",
114114
"signText": "⚠",
115-
"signTexthl": "ALEWarningSign",
115+
"signTexthl": "LanguageClientWarningSign",
116116
"virtualTexthl": "Todo",
117117
},
118118
3: {
119119
"name": "Information",
120-
"texthl": "ALEInfo",
120+
"texthl": "LanguageClientInfo",
121121
"signText": "ℹ",
122-
"signTexthl": "ALEInfoSign",
122+
"signTexthl": "LanguageClientInfoSign",
123123
"virtualTexthl": "Todo",
124124
},
125125
4: {
126126
"name": "Hint",
127-
"texthl": "ALEInfo",
127+
"texthl": "LanguageClientInfo",
128128
"signText": "➤",
129-
"signTexthl": "ALEInfoSign",
129+
"signTexthl": "LanguageClientInfoSign",
130130
"virtualTexthl": "Todo",
131131
},
132132
}
@@ -629,11 +629,14 @@ The default value for this config, or the absence of this config, enables extens
629629

630630
Default: v:null
631631

632-
2.41 g:LanguageClient_codeLensHighlightGroup *g:LanguageClient_codeLensHighlightGroup*
632+
2.41 g:LanguageClient_codeLensDisplay *g:LanguageClient_codeLensDisplay*
633633

634-
Highlight group to be used for code lens.
634+
Control how code lenses are displayed.
635635

636-
Default: 'Comment'
636+
Default: >
637+
{
638+
"virtualTexthl": "LanguageClientCodeLens",
639+
}
637640
638641
2.42 g:LanguageClient_hoverMarginSize *g:LanguageClient_hoverMarginSize*
639642

src/language_server_protocol.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl LanguageClient {
179179
preferred_markup_kind,
180180
hide_virtual_texts_on_insert,
181181
enable_extensions,
182-
code_lens_hl_group,
182+
code_lens_display,
183183
): (
184184
Option<usize>,
185185
String,
@@ -194,7 +194,7 @@ impl LanguageClient {
194194
Option<Vec<MarkupKind>>,
195195
u8,
196196
Option<HashMap<String, bool>>,
197-
String,
197+
Value,
198198
) = self.vim()?.eval(
199199
[
200200
"get(g:, 'LanguageClient_diagnosticsSignsMax', v:null)",
@@ -210,7 +210,7 @@ impl LanguageClient {
210210
"get(g:, 'LanguageClient_preferredMarkupKind', v:null)",
211211
"s:GetVar('LanguageClient_hideVirtualTextsOnInsert', 0)",
212212
"get(g:, 'LanguageClient_enableExtensions', v:null)",
213-
"get(g:, 'LanguageClient_codeLensHighlightGroup', 'Comment')",
213+
"get(g:, 'LanguageClient_codeLensDisplay', v:null)",
214214
]
215215
.as_ref(),
216216
)?;
@@ -337,7 +337,9 @@ impl LanguageClient {
337337
state.is_nvim = is_nvim;
338338
state.preferred_markup_kind = preferred_markup_kind;
339339
state.enable_extensions = enable_extensions;
340-
state.code_lens_hl_group = code_lens_hl_group;
340+
state.code_lens_display = serde_json::from_value(
341+
serde_json::to_value(&state.code_lens_display)?.combine(&code_lens_display),
342+
)?;
341343
state.max_restart_retries = max_restart_retries;
342344
state.restart_on_crash = restart_on_crash == 1;
343345

@@ -3208,7 +3210,7 @@ impl LanguageClient {
32083210
let mut virtual_texts = vec![];
32093211
let code_lenses =
32103212
self.get(|state| state.code_lens.get(filename).cloned().unwrap_or_default())?;
3211-
let code_lens_hl_group = self.get(|state| state.code_lens_hl_group.clone())?;
3213+
let code_lens_display = self.get(|state| state.code_lens_display.clone())?;
32123214

32133215
for cl in code_lenses {
32143216
if let Some(command) = cl.command {
@@ -3225,7 +3227,7 @@ impl LanguageClient {
32253227
None => virtual_texts.push(VirtualText {
32263228
line,
32273229
text,
3228-
hl_group: code_lens_hl_group.clone(),
3230+
hl_group: code_lens_display.virtual_texthl.clone(),
32293231
}),
32303232
}
32313233
}

src/types.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub struct State {
155155
pub diagnostics: HashMap<String, Vec<Diagnostic>>,
156156
// filename => codeLens.
157157
pub code_lens: HashMap<String, Vec<CodeLens>>,
158-
pub code_lens_hl_group: String,
158+
pub code_lens_display: CodeLensDisplay,
159159
#[serde(skip_serializing)]
160160
pub line_diagnostics: HashMap<(String, u64), String>,
161161
pub namespace_ids: HashMap<String, i64>,
@@ -291,7 +291,7 @@ impl State {
291291
server_stderr: None,
292292
preferred_markup_kind: None,
293293
enable_extensions: None,
294-
code_lens_hl_group: "Comment".into(),
294+
code_lens_display: CodeLensDisplay::default(),
295295
restart_on_crash: true,
296296
max_restart_retries: 5,
297297

@@ -401,6 +401,20 @@ impl FromStr for DiagnosticsList {
401401
}
402402
}
403403

404+
#[derive(Debug, Clone, Serialize, Deserialize)]
405+
#[serde(rename_all = "camelCase")]
406+
pub struct CodeLensDisplay {
407+
pub virtual_texthl: String,
408+
}
409+
410+
impl Default for CodeLensDisplay {
411+
fn default() -> Self {
412+
CodeLensDisplay {
413+
virtual_texthl: "LanguageClientCodeLens".into(),
414+
}
415+
}
416+
}
417+
404418
#[derive(Debug, Clone, Serialize, Deserialize)]
405419
#[serde(rename_all = "camelCase")]
406420
pub struct DiagnosticsDisplay {
@@ -418,39 +432,39 @@ impl DiagnosticsDisplay {
418432
1,
419433
Self {
420434
name: "Error".to_owned(),
421-
texthl: "ALEError".to_owned(),
435+
texthl: "LanguageClientError".to_owned(),
422436
sign_text: "✖".to_owned(),
423-
sign_texthl: "ALEErrorSign".to_owned(),
437+
sign_texthl: "LanguageClientErrorSign".to_owned(),
424438
virtual_texthl: "Error".to_owned(),
425439
},
426440
);
427441
map.insert(
428442
2,
429443
Self {
430444
name: "Warning".to_owned(),
431-
texthl: "ALEWarning".to_owned(),
445+
texthl: "LanguageClientWarning".to_owned(),
432446
sign_text: "⚠".to_owned(),
433-
sign_texthl: "ALEWarningSign".to_owned(),
447+
sign_texthl: "LanguageClientWarningSign".to_owned(),
434448
virtual_texthl: "Todo".to_owned(),
435449
},
436450
);
437451
map.insert(
438452
3,
439453
Self {
440454
name: "Information".to_owned(),
441-
texthl: "ALEInfo".to_owned(),
455+
texthl: "LanguageClientInfo".to_owned(),
442456
sign_text: "ℹ".to_owned(),
443-
sign_texthl: "ALEInfoSign".to_owned(),
457+
sign_texthl: "LanguageClientInfoSign".to_owned(),
444458
virtual_texthl: "Todo".to_owned(),
445459
},
446460
);
447461
map.insert(
448462
4,
449463
Self {
450464
name: "Hint".to_owned(),
451-
texthl: "ALEInfo".to_owned(),
465+
texthl: "LanguageClientInfo".to_owned(),
452466
sign_text: "➤".to_owned(),
453-
sign_texthl: "ALEInfoSign".to_owned(),
467+
sign_texthl: "LanguageClientInfoSign".to_owned(),
454468
virtual_texthl: "Todo".to_owned(),
455469
},
456470
);

0 commit comments

Comments
 (0)