From 69ad4918e563e2d821538fb95567beae667c9dd1 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 3 Jan 2024 16:34:21 +0000 Subject: [PATCH] fix(lsp): support test code lens for Deno.test.{ignore,only}() (#21775) --- cli/lsp/code_lens.rs | 119 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/cli/lsp/code_lens.rs b/cli/lsp/code_lens.rs index f2ac248408..3625c10a15 100644 --- a/cli/lsp/code_lens.rs +++ b/cli/lsp/code_lens.rs @@ -152,10 +152,25 @@ impl Visit for DenoTestCollector { } ast::Expr::Member(member_expr) => { if let ast::MemberProp::Ident(ns_prop_ident) = &member_expr.prop { + let mut member_expr = member_expr; + let mut ns_prop_ident = ns_prop_ident; + let range = ns_prop_ident.range(); + if matches!(ns_prop_ident.sym.as_str(), "ignore" | "only") { + let ast::Expr::Member(member_expr_) = member_expr.obj.as_ref() + else { + return; + }; + member_expr = member_expr_; + let ast::MemberProp::Ident(ns_prop_ident_) = &member_expr.prop + else { + return; + }; + ns_prop_ident = ns_prop_ident_; + } if ns_prop_ident.sym == "test" { if let ast::Expr::Ident(ident) = member_expr.obj.as_ref() { if ident.sym == "Deno" { - self.check_call_expr(node, &ns_prop_ident.range()); + self.check_call_expr(node, &range); } } } @@ -528,6 +543,10 @@ mod tests { Deno.test(function useFnName() {}); Deno.test("test b", function anotherTest() {}); + + Deno.test.ignore("test ignore", () => {}); + + Deno.test.only("test only", () => {}); "#; let parsed_module = deno_ast::parse_module(deno_ast::ParseParams { specifier: specifier.to_string(), @@ -687,7 +706,103 @@ mod tests { ]) }), data: None, - } + }, + lsp::CodeLens { + range: lsp::Range { + start: lsp::Position { + line: 10, + character: 16, + }, + end: lsp::Position { + line: 10, + character: 22, + }, + }, + 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 ignore"), + json!({ + "inspect": false, + }), + ]), + }), + data: None, + }, + lsp::CodeLens { + range: lsp::Range { + start: lsp::Position { + line: 10, + character: 16, + }, + end: lsp::Position { + line: 10, + character: 22, + }, + }, + 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 ignore"), + json!({ + "inspect": true, + }), + ]), + }), + data: None, + }, + lsp::CodeLens { + range: lsp::Range { + start: lsp::Position { + line: 12, + character: 16, + }, + end: lsp::Position { + line: 12, + character: 20, + }, + }, + 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 only"), + json!({ + "inspect": false, + }), + ]), + }), + data: None, + }, + lsp::CodeLens { + range: lsp::Range { + start: lsp::Position { + line: 12, + character: 16, + }, + end: lsp::Position { + line: 12, + character: 20, + }, + }, + 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 only"), + json!({ + "inspect": true, + }), + ]), + }), + data: None, + }, ] ); }