diff options
author | Jesper van den Ende <jespertheend@users.noreply.github.com> | 2021-12-20 06:00:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-20 16:00:38 +1100 |
commit | 0888ba7a8db33ee01f57679308e7e8c4eea108e9 (patch) | |
tree | eaf2933b846b5805973cc529aef3b10332e7a37d /cli/lsp/code_lens.rs | |
parent | e20682bd428bc2abb15817bb9762d9c02fb3cdd1 (diff) |
feat(lsp): add code lens for debugging tests (#13138)
Closes: #13130
Diffstat (limited to 'cli/lsp/code_lens.rs')
-rw-r--r-- | cli/lsp/code_lens.rs | 82 |
1 files changed, 77 insertions, 5 deletions
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<N: AsRef<str>>(&mut self, name: N, span: &Span) { + fn add_code_lenses<N: AsRef<str>>(&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<N: AsRef<str>>( + &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, |