Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit b36840e

Browse files
authored
Merge pull request #1740 from arthurlm/extended-test-match
Update regex use to match test for external librairies
2 parents da2aec0 + 7ec3d36 commit b36840e

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

rls/src/actions/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn collect_run_actions(ctx: &InitActionContext, file: &Path) -> Vec<RunActio
2323
}
2424

2525
lazy_static! {
26-
/// __(a):__ `\#\[test\]` matches `#[test]`
26+
/// __(a):__ `\#\[([\w]+::)*test\]` matches `#[test]`, `#[async_executor::test]` or `#[async_lib::module::test]`.
2727
///
2828
/// __(b):__ `^[^\/]*?fn\s+(?P<name>\w+)` matches any line which contains `fn name` before any comment is started and captures the word after fn.
2929
/// The laziness of the quantifier is there to make the regex quicker (about 5 times less steps)
@@ -42,7 +42,7 @@ pub fn collect_run_actions(ctx: &InitActionContext, file: &Path) -> Vec<RunActio
4242
/// fn right_function() {}
4343
/// ```
4444
static ref TEST_FN_RE: Regex =
45-
Regex::new(r"(?m)#\[test\](\n|.)*?^[^/]*?fn\s+(?P<name>\w+)").unwrap();
45+
Regex::new(r"(?m)#\[([\w]+::)*test\](\n|.)*?^[^/]*?fn\s+(?P<name>\w+)").unwrap();
4646
}
4747

4848
let line_index = LineIndex::new(&text);

tests/client.rs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -989,24 +989,42 @@ fn client_lens_run() {
989989
},
990990
);
991991

992-
let expected = CodeLens {
993-
command: Some(Command {
994-
command: "rls.run".to_string(),
995-
title: "Run test".to_string(),
996-
arguments: Some(vec![json!({
997-
"args": [ "test", "--", "--nocapture", "test_foo" ],
998-
"binary": "cargo",
999-
"env": { "RUST_BACKTRACE": "short" }
1000-
})]),
1001-
}),
1002-
data: None,
1003-
range: Range {
1004-
start: Position { line: 4, character: 3 },
1005-
end: Position { line: 4, character: 11 },
992+
let expected = vec![
993+
CodeLens {
994+
command: Some(Command {
995+
command: "rls.run".to_string(),
996+
title: "Run test".to_string(),
997+
arguments: Some(vec![json!({
998+
"args": [ "test", "--", "--nocapture", "test_foo" ],
999+
"binary": "cargo",
1000+
"env": { "RUST_BACKTRACE": "short" }
1001+
})]),
1002+
}),
1003+
data: None,
1004+
range: Range {
1005+
start: Position { line: 4, character: 3 },
1006+
end: Position { line: 4, character: 11 },
1007+
},
10061008
},
1007-
};
1009+
CodeLens {
1010+
command: Some(Command {
1011+
command: "rls.run".to_string(),
1012+
title: "Run test".to_string(),
1013+
arguments: Some(vec![json!({
1014+
"args": [ "test", "--", "--nocapture", "test_bar"],
1015+
"binary": "cargo",
1016+
"env": { "RUST_BACKTRACE": "short" }
1017+
})]),
1018+
}),
1019+
data: None,
1020+
range: Range {
1021+
start: Position { line: 9, character: 3 },
1022+
end: Position { line: 9, character: 11 },
1023+
},
1024+
},
1025+
];
10081026

1009-
assert_eq!(lens, Some(vec![expected]));
1027+
assert_eq!(lens, Some(expected));
10101028
}
10111029

10121030
#[test]

tests/fixtures/lens_run/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ pub fn main() {
55
fn test_foo() {
66

77
}
8+
9+
#[tokio::test]
10+
fn test_bar() {
11+
12+
}
13+
14+
#[dummy_ext]
15+
fn test_baz() {
16+
17+
}

0 commit comments

Comments
 (0)