summaryrefslogtreecommitdiff
path: root/cli/lsp/code_lens.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-01-05 12:04:33 +0000
committerGitHub <noreply@github.com>2024-01-05 12:04:33 +0000
commitbac51f66aa89dd9b79a3c4e844423c3a3399ea13 (patch)
tree766166d271722d892f7e8fcc09dfb849d2f86529 /cli/lsp/code_lens.rs
parentaadcd640651383d606678928c10b637345b57beb (diff)
fix(lsp): show test code lens for template literal names (#21798)
Diffstat (limited to 'cli/lsp/code_lens.rs')
-rw-r--r--cli/lsp/code_lens.rs69
1 files changed, 64 insertions, 5 deletions
diff --git a/cli/lsp/code_lens.rs b/cli/lsp/code_lens.rs
index 3625c10a1..707ff0946 100644
--- a/cli/lsp/code_lens.rs
+++ b/cli/lsp/code_lens.rs
@@ -108,11 +108,16 @@ impl DenoTestCollector {
&key_value_prop.key
{
if sym == "name" {
- if let ast::Expr::Lit(ast::Lit::Str(lit_str)) =
- key_value_prop.value.as_ref()
- {
- let name = lit_str.value.to_string();
- self.add_code_lenses(name, range);
+ match key_value_prop.value.as_ref() {
+ ast::Expr::Lit(ast::Lit::Str(lit_str)) => {
+ let name = lit_str.value.to_string();
+ self.add_code_lenses(name, range);
+ }
+ ast::Expr::Tpl(tpl) if tpl.quasis.len() == 1 => {
+ let name = tpl.quasis.first().unwrap().raw.to_string();
+ self.add_code_lenses(name, range);
+ }
+ _ => {}
}
}
}
@@ -130,6 +135,10 @@ impl DenoTestCollector {
let name = lit_str.value.to_string();
self.add_code_lenses(name, range);
}
+ ast::Expr::Tpl(tpl) if tpl.quasis.len() == 1 => {
+ let name = tpl.quasis.first().unwrap().raw.to_string();
+ self.add_code_lenses(name, range);
+ }
_ => (),
}
}
@@ -547,6 +556,8 @@ mod tests {
Deno.test.ignore("test ignore", () => {});
Deno.test.only("test only", () => {});
+
+ Deno.test(`test template literal name`, () => {});
"#;
let parsed_module = deno_ast::parse_module(deno_ast::ParseParams {
specifier: specifier.to_string(),
@@ -803,6 +814,54 @@ mod tests {
}),
data: None,
},
+ lsp::CodeLens {
+ range: lsp::Range {
+ start: lsp::Position {
+ line: 14,
+ character: 11,
+ },
+ end: lsp::Position {
+ line: 14,
+ character: 15,
+ },
+ },
+ command: Some(lsp::Command {
+ title: "▶\u{fe0e} Run Test".to_string(),
+ command: "deno.test".to_string(),
+ arguments: Some(vec![
+ json!("https://deno.land/x/mod.ts"),
+ json!("test template literal name"),
+ json!({
+ "inspect": false,
+ }),
+ ]),
+ }),
+ data: None,
+ },
+ lsp::CodeLens {
+ range: lsp::Range {
+ start: lsp::Position {
+ line: 14,
+ character: 11,
+ },
+ end: lsp::Position {
+ line: 14,
+ 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 template literal name"),
+ json!({
+ "inspect": true,
+ }),
+ ]),
+ }),
+ data: None,
+ },
]
);
}