Skip to content

Commit 0888ba7

Browse files
authored
feat(lsp): add code lens for debugging tests (#13138)
Closes: #13130
1 parent e20682b commit 0888ba7

File tree

2 files changed

+293
-13
lines changed

2 files changed

+293
-13
lines changed

cli/lsp/code_lens.rs

+77-5
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,32 @@ impl DenoTestCollector {
8080
}
8181
}
8282

83-
fn add_code_lens<N: AsRef<str>>(&mut self, name: N, span: &Span) {
83+
fn add_code_lenses<N: AsRef<str>>(&mut self, name: N, span: &Span) {
8484
let range = span_to_range(span, &self.parsed_source);
85+
self.add_code_lens(&name, range, "▶\u{fe0e} Run Test", false);
86+
self.add_code_lens(&name, range, "Debug", true);
87+
}
88+
89+
fn add_code_lens<N: AsRef<str>>(
90+
&mut self,
91+
name: &N,
92+
range: lsp::Range,
93+
title: &str,
94+
inspect: bool,
95+
) {
96+
let options = json!({
97+
"inspect": inspect,
98+
});
8599
self.code_lenses.push(lsp::CodeLens {
86100
range,
87101
command: Some(lsp::Command {
88-
title: "▶\u{fe0e} Run Test".to_string(),
102+
title: title.to_string(),
89103
command: "deno.test".to_string(),
90-
arguments: Some(vec![json!(self.specifier), json!(name.as_ref())]),
104+
arguments: Some(vec![
105+
json!(self.specifier),
106+
json!(name.as_ref()),
107+
options,
108+
]),
91109
}),
92110
data: None,
93111
});
@@ -106,7 +124,7 @@ impl DenoTestCollector {
106124
key_value_prop.value.as_ref()
107125
{
108126
let name = lit_str.value.to_string();
109-
self.add_code_lens(name, span);
127+
self.add_code_lenses(name, span);
110128
}
111129
}
112130
}
@@ -116,7 +134,7 @@ impl DenoTestCollector {
116134
}
117135
ast::Expr::Lit(ast::Lit::Str(lit_str)) => {
118136
let name = lit_str.value.to_string();
119-
self.add_code_lens(name, span);
137+
self.add_code_lenses(name, span);
120138
}
121139
_ => (),
122140
}
@@ -581,6 +599,33 @@ mod tests {
581599
arguments: Some(vec![
582600
json!("https://deno.land/x/mod.ts"),
583601
json!("test a"),
602+
json!({
603+
"inspect": false,
604+
}),
605+
])
606+
}),
607+
data: None,
608+
},
609+
lsp::CodeLens {
610+
range: lsp::Range {
611+
start: lsp::Position {
612+
line: 1,
613+
character: 11
614+
},
615+
end: lsp::Position {
616+
line: 1,
617+
character: 15
618+
}
619+
},
620+
command: Some(lsp::Command {
621+
title: "Debug".to_string(),
622+
command: "deno.test".to_string(),
623+
arguments: Some(vec![
624+
json!("https://deno.land/x/mod.ts"),
625+
json!("test a"),
626+
json!({
627+
"inspect": true,
628+
}),
584629
])
585630
}),
586631
data: None,
@@ -602,6 +647,33 @@ mod tests {
602647
arguments: Some(vec![
603648
json!("https://deno.land/x/mod.ts"),
604649
json!("test b"),
650+
json!({
651+
"inspect": false,
652+
}),
653+
])
654+
}),
655+
data: None,
656+
},
657+
lsp::CodeLens {
658+
range: lsp::Range {
659+
start: lsp::Position {
660+
line: 6,
661+
character: 11
662+
},
663+
end: lsp::Position {
664+
line: 6,
665+
character: 15
666+
}
667+
},
668+
command: Some(lsp::Command {
669+
title: "Debug".to_string(),
670+
command: "deno.test".to_string(),
671+
arguments: Some(vec![
672+
json!("https://deno.land/x/mod.ts"),
673+
json!("test b"),
674+
json!({
675+
"inspect": true,
676+
}),
605677
])
606678
}),
607679
data: None,

0 commit comments

Comments
 (0)