0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

feat(lsp): add code lens for debugging tests (#13138)

Closes: #13130
This commit is contained in:
Jesper van den Ende 2021-12-20 06:00:38 +01:00 committed by GitHub
parent e20682bd42
commit 0888ba7a8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 293 additions and 13 deletions

View file

@ -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,

View file

@ -15,7 +15,33 @@
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test a"
"test a",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 4,
"character": 5
},
"end": {
"line": 4,
"character": 9
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test a",
{
"inspect": true
}
]
}
},
@ -35,7 +61,33 @@
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test b"
"test b",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 5,
"character": 5
},
"end": {
"line": 5,
"character": 9
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test b",
{
"inspect": true
}
]
}
},
@ -55,7 +107,33 @@
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test c"
"test c",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 9,
"character": 0
},
"end": {
"line": 9,
"character": 4
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test c",
{
"inspect": true
}
]
}
},
@ -75,7 +153,33 @@
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test d"
"test d",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 13,
"character": 0
},
"end": {
"line": 13,
"character": 4
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test d",
{
"inspect": true
}
]
}
},
@ -95,7 +199,33 @@
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test e"
"test e",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 14,
"character": 0
},
"end": {
"line": 14,
"character": 5
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test e",
{
"inspect": true
}
]
}
},
@ -115,7 +245,33 @@
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test f"
"test f",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 18,
"character": 0
},
"end": {
"line": 18,
"character": 5
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test f",
{
"inspect": true
}
]
}
},
@ -135,7 +291,33 @@
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test g"
"test g",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 19,
"character": 0
},
"end": {
"line": 19,
"character": 5
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test g",
{
"inspect": true
}
]
}
},
@ -155,7 +337,33 @@
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test h"
"test h",
{
"inspect": false
}
]
}
},
{
"range": {
"start": {
"line": 23,
"character": 0
},
"end": {
"line": 23,
"character": 5
}
},
"command": {
"title": "Debug",
"command": "deno.test",
"arguments": [
"file:///a/file.ts",
"test h",
{
"inspect": true
}
]
}
}