fix(lsp): show test code lens for template literal names (#21798)

This commit is contained in:
Nayeem Rahman 2024-01-05 12:04:33 +00:00 committed by GitHub
parent aadcd64065
commit bac51f66aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,
},
]
);
}