Skip to content
This repository was archived by the owner on May 9, 2021. It is now read-only.

Commit ffb9172

Browse files
committed
Fixes issue #3 by matching the longest prefix of a target path
1 parent 1fd559a commit ffb9172

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ All notable changes to the "rust-test-lens" extension will be documented in this
44

55
Check [Keep a Changelog](https://keepachangelog.com/) for recommendations on how to structure this file.
66

7+
## 0.1.2
8+
9+
- Fixes issue [#3](https://github.com/hdevalke/rust-test-lens/issues/3) where there is more than one target created.
10+
711
## 0.1.1
812

9-
- Fixes issue [#3](https://github.com/hdevalke/rust-test-lens/issues/3) where tests in binary crate were not launched.
13+
- Fixes issue [#3](https://github.com/hdevalke/rust-test-lens/issues/3) where tests in binary crate are not launched.
1014

1115
## 0.1.0
1216

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "rust-test-lens",
33
"displayName": "Rust Test Lens",
44
"description": "Adds a code lens to quickly run or debug a single test for your Rust code.",
5-
"version": "0.1.1",
5+
"version": "0.1.2",
66
"publisher": "hdevalke",
77
"engines": {
88
"vscode": "^1.30.2"

src/RustTests.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,21 @@ export class RustTests {
5959
// fast path
6060
if (targets.length === 1) {
6161
target = targets[0];
62-
}
63-
// slow path
64-
for (const t of pkg.targets) {
65-
if (t.src_path === uri) {
66-
target = t;
67-
break;
62+
} else {
63+
// slow path
64+
// sort in order to find longest path.
65+
targets.sort((a, b) => {
66+
return b.src_path.length - a.src_path.length;
67+
});
68+
for (const t of pkg.targets) {
69+
let target_dir = dirname(t.src_path);
70+
if (uri.startsWith(target_dir)) {
71+
target = t;
72+
break;
73+
}
6874
}
6975
}
76+
7077
let kind = undefined;
7178
let name = undefined;
7279
if (target === undefined) {

0 commit comments

Comments
 (0)