Skip to content

Commit 13729a4

Browse files
martskinsautozimu
authored andcommitted
Multiple correctness fixes
1 parent 1c7a3b0 commit 13729a4

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

autoload/LanguageClient.vim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ function! s:useVirtualText() abort
123123
return l:use
124124
endif
125125

126-
return exists('*nvim_buf_set_virtual_text')
126+
if exists('*nvim_buf_set_virtual_text')
127+
return 'All'
128+
else
129+
return 'No'
130+
endif
127131
endfunction
128132

129133
function! s:IsTrue(v) abort
@@ -1313,15 +1317,15 @@ function! LanguageClient#java_classFileContents(...) abort
13131317
return LanguageClient#Call('java/classFileContents', l:params, l:Callback)
13141318
endfunction
13151319

1316-
function! LanguageClient#codeLensAction(...) abort
1320+
function! LanguageClient#handleCodeLensAction(...) abort
13171321
let l:Callback = get(a:000, 1, v:null)
13181322
let l:params = {
13191323
\ 'filename': LSP#filename(),
13201324
\ 'line': LSP#line(),
13211325
\ 'character': LSP#character(),
13221326
\ }
13231327
call extend(l:params, get(a:000, 0, {}))
1324-
return LanguageClient#Call('LanguageClient_CodeLensAction', l:params, l:Callback)
1328+
return LanguageClient#Call('LanguageClient/handleCodeLensAction', l:params, l:Callback)
13251329
endfunction
13261330

13271331
function! LanguageClient_contextMenuItems() abort

doc/LanguageClient.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ Default: >
344344

345345
Specify whether to use virtual text to display diagnostics.
346346

347-
Default: "CodeLens" whenever virtual text is supported.
347+
Default: "All" whenever virtual text is supported.
348348
Valid Options: "All" | "No" | "CodeLens" | "Diagnostics"
349349

350350
2.26 g:LanguageClient_useFloatingHover *g:LanguageClient_useFloatingHover*
@@ -499,7 +499,7 @@ Computes and displays the codeLens for the currently open file.
499499
*LanguageClient_textDocument_codeLensAction()*
500500
Signature: LanguageClient#textDocument_codeLensAction(...)
501501

502-
Runs the action associated with the codeLens at the current line. If does
502+
Runs the action associated with the codeLens at the current line. It does
503503
nothing if the codeLens is not actionable.
504504

505505
*LanguageClient#textDocument_documentSymbol()*

src/language_server_protocol.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -851,14 +851,20 @@ impl LanguageClient {
851851
}
852852
}
853853
"rust-analyzer.runSingle" | "rust-analyzer.run" => {
854+
let has_term: i32 = self.vim()?.eval("exists(':terminal')")?;
855+
if has_term == 0 {
856+
bail!("Terminal support is required for this action");
857+
}
858+
854859
if let Some(ref args) = cmd.arguments {
855-
let args = args[0].clone();
856-
let bin: String =
857-
try_get("bin", &args)?.ok_or_else(|| err_msg("no bin found"))?;
858-
let arguments: Vec<String> = try_get("args", &args)?.unwrap_or_else(|| vec![]);
859-
let cmd = format!("term {} {}", bin, arguments.join(" "));
860-
let cmd = cmd.replace('"', "");
861-
self.vim()?.command(cmd)?;
860+
if let Some(args) = args.first().cloned() {
861+
let bin: String =
862+
try_get("bin", &args)?.ok_or_else(|| err_msg("no bin found"))?;
863+
let arguments: Vec<String> = try_get("args", &args)?.unwrap_or_default();
864+
let cmd = format!("term {} {}", bin, arguments.join(" "));
865+
let cmd = cmd.replace('"', "");
866+
self.vim()?.command(cmd)?;
867+
}
862868
}
863869
}
864870
// TODO: implement all other rust-analyzer actions
@@ -1781,7 +1787,13 @@ impl LanguageClient {
17811787
let mut code_lens: Vec<CodeLens> =
17821788
self.get(|state| state.code_lens.get(filename.as_str()).cloned().unwrap())?;
17831789
code_lens.retain(|cl| cl.range.start.line == line);
1784-
if code_lens.len() != 1 {
1790+
if code_lens.is_empty() {
1791+
warn!("No actions associated with this codeLens");
1792+
return Ok(Value::Null);
1793+
}
1794+
1795+
if code_lens.len() > 1 {
1796+
warn!("Mulitple actions associated with this codeLens");
17851797
return Ok(Value::Null);
17861798
}
17871799

@@ -2619,25 +2631,17 @@ impl LanguageClient {
26192631
// code lens
26202632
if UseVirtualText::All == use_virtual_text || UseVirtualText::CodeLens == use_virtual_text {
26212633
let filename = self.vim()?.get_filename(params)?;
2622-
let code_lenses = self.get(|state| {
2623-
state
2624-
.code_lens
2625-
.get(&filename)
2626-
.cloned()
2627-
.unwrap_or_else(|| vec![])
2628-
})?;
2634+
let code_lenses =
2635+
self.get(|state| state.code_lens.get(&filename).cloned().unwrap_or_default())?;
26292636

26302637
for cl in code_lenses {
2631-
if cl.command.is_none() {
2632-
continue;
2638+
if let Some(command) = cl.command {
2639+
virtual_texts.push(VirtualText {
2640+
line: cl.range.start.line,
2641+
text: command.title,
2642+
hl_group: "Comment".into(),
2643+
})
26332644
}
2634-
let command = cl.command.unwrap();
2635-
2636-
virtual_texts.push(VirtualText {
2637-
line: cl.range.start.line,
2638-
text: command.title,
2639-
hl_group: "Comment".into(),
2640-
})
26412645
}
26422646
}
26432647

src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub const REQUEST__NCM2OnComplete: &str = "LanguageClient_NCM2OnComplete";
3232
pub const REQUEST__ExplainErrorAtPoint: &str = "languageClient/explainErrorAtPoint";
3333
pub const REQUEST__FindLocations: &str = "languageClient/findLocations";
3434
pub const REQUEST__DebugInfo: &str = "languageClient/debugInfo";
35-
pub const REQUEST__CodeLensAction: &str = "LanguageClient_CodeLensAction";
35+
pub const REQUEST__CodeLensAction: &str = "LanguageClient/handleCodeLensAction";
3636
pub const NOTIFICATION__HandleBufNewFile: &str = "languageClient/handleBufNewFile";
3737
pub const NOTIFICATION__HandleFileType: &str = "languageClient/handleFileType";
3838
pub const NOTIFICATION__HandleTextChanged: &str = "languageClient/handleTextChanged";
@@ -243,7 +243,7 @@ impl State {
243243
wait_output_timeout: Duration::from_secs(10),
244244
hoverPreview: HoverPreviewOption::default(),
245245
completionPreferTextEdit: false,
246-
use_virtual_text: UseVirtualText::CodeLens,
246+
use_virtual_text: UseVirtualText::All,
247247
echo_project_root: true,
248248
loggingFile: None,
249249
loggingLevel: log::LevelFilter::Warn,

0 commit comments

Comments
 (0)