From 0888ba7a8db33ee01f57679308e7e8c4eea108e9 Mon Sep 17 00:00:00 2001 From: Jesper van den Ende Date: Mon, 20 Dec 2021 06:00:38 +0100 Subject: feat(lsp): add code lens for debugging tests (#13138) Closes: #13130 --- cli/lsp/code_lens.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 5 deletions(-) (limited to 'cli/lsp') diff --git a/cli/lsp/code_lens.rs b/cli/lsp/code_lens.rs index 635f34916..42c9123fb 100644 --- a/cli/lsp/code_lens.rs +++ b/cli/lsp/code_lens.rs @@ -80,14 +80,32 @@ impl DenoTestCollector { } } - fn add_code_lens>(&mut self, name: N, span: &Span) { + fn add_code_lenses>(&mut self, name: N, span: &Span) { let range = span_to_range(span, &self.parsed_source); + self.add_code_lens(&name, range, "▶\u{fe0e} Run Test", false); + self.add_code_lens(&name, range, "Debug", true); + } + + fn add_code_lens>( + &mut self, + name: &N, + range: lsp::Range, + title: &str, + inspect: bool, + ) { + let options = json!({ + "inspect": inspect, + }); self.code_lenses.push(lsp::CodeLens { range, command: Some(lsp::Command { - title: "▶\u{fe0e} Run Test".to_string(), + title: title.to_string(), command: "deno.test".to_string(), - arguments: Some(vec![json!(self.specifier), json!(name.as_ref())]), + arguments: Some(vec![ + json!(self.specifier), + json!(name.as_ref()), + options, + ]), }), data: None, }); @@ -106,7 +124,7 @@ impl DenoTestCollector { key_value_prop.value.as_ref() { let name = lit_str.value.to_string(); - self.add_code_lens(name, span); + self.add_code_lenses(name, span); } } } @@ -116,7 +134,7 @@ impl DenoTestCollector { } ast::Expr::Lit(ast::Lit::Str(lit_str)) => { let name = lit_str.value.to_string(); - self.add_code_lens(name, span); + self.add_code_lenses(name, span); } _ => (), } @@ -581,6 +599,33 @@ mod tests { arguments: Some(vec![ json!("https://deno.land/x/mod.ts"), json!("test a"), + json!({ + "inspect": false, + }), + ]) + }), + data: None, + }, + lsp::CodeLens { + range: lsp::Range { + start: lsp::Position { + line: 1, + character: 11 + }, + end: lsp::Position { + line: 1, + character: 15 + } + }, + command: Some(lsp::Command { + title: "Debug".to_string(), + command: "deno.test".to_string(), + arguments: Some(vec![ + json!("https://deno.land/x/mod.ts"), + json!("test a"), + json!({ + "inspect": true, + }), ]) }), data: None, @@ -602,6 +647,33 @@ mod tests { arguments: Some(vec![ json!("https://deno.land/x/mod.ts"), json!("test b"), + json!({ + "inspect": false, + }), + ]) + }), + data: None, + }, + lsp::CodeLens { + range: lsp::Range { + start: lsp::Position { + line: 6, + character: 11 + }, + end: lsp::Position { + line: 6, + character: 15 + } + }, + command: Some(lsp::Command { + title: "Debug".to_string(), + command: "deno.test".to_string(), + arguments: Some(vec![ + json!("https://deno.land/x/mod.ts"), + json!("test b"), + json!({ + "inspect": true, + }), ]) }), data: None, -- cgit v1.2.3