diff --git a/CHANGELOG.md b/CHANGELOG.md index 61bcb54..4288323 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to the "rust-test-lens" extension will be documented in this Check [Keep a Changelog](https://keepachangelog.com/) for recommendations on how to structure this file. +## 0.0.5 + +- Solves the problem if there are still multiple binaries found. E.g. integration tests. +- Sets the current working directory to the package root instead of the workspace root. + ## 0.0.4 - Works now if the package contains multiple binaries. diff --git a/package.json b/package.json index b57af65..9ac0886 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,10 @@ "name": "rust-test-lens", "displayName": "Rust Test Lens", "description": "Adds a code lens to quickly run or debug a single test for your Rust code.", - "version": "0.0.4", + "version": "0.0.5", "publisher": "hdevalke", "engines": { - "vscode": "^1.30.1" + "vscode": "^1.30.2" }, "categories": [ "Other", @@ -37,10 +37,10 @@ "devDependencies": { "@types/mocha": "^5.2.5", "@types/node": "^10.12.18", - "tslint": "^5.12.0", - "typescript": "^2.9.2", + "tslint": "^5.12.1", + "typescript": "^3.2.4", "vsce": "^1.54.0", - "vscode": "^1.1.26" + "vscode": "^1.1.27" }, "extensionDependencies": [ "vadimcn.vscode-lldb" diff --git a/src/RustCodeLensProvider.ts b/src/RustCodeLensProvider.ts index fe4b0eb..e1a5a2c 100644 --- a/src/RustCodeLensProvider.ts +++ b/src/RustCodeLensProvider.ts @@ -4,7 +4,7 @@ import { Range, TextDocument, DebugConfiguration } from 'vscode'; import { RustTests } from './RustTests'; -import { basename } from 'path'; +import { basename, dirname } from 'path'; export class RustCodeLensProvider implements CodeLensProvider { @@ -60,15 +60,21 @@ export class RustCodeLensProvider implements CodeLensProvider { "test", "--no-run", `--package=${pkg.name}` - ] + ], + filter: {} as any, }, args: [fn], - cwd: "${workspaceFolder}" + cwd: `${dirname(pkg.manifest_path)}` }; const bin = this.rustTests.getBin(uri, pkg); if (bin !== undefined) { debugConfig.cargo.args.push(`--bin=${bin}`); } + const kind = this.rustTests.getKind(uri, pkg); + if (kind !== undefined) { + debugConfig.cargo.filter.kind = kind; + } + return debugConfig; } } diff --git a/src/RustTests.ts b/src/RustTests.ts index d0c969f..7988062 100644 --- a/src/RustTests.ts +++ b/src/RustTests.ts @@ -49,4 +49,21 @@ export class RustTests { } return undefined; } + + /// Get the kind of the target to select. + /// For example + getKind(uri: string, pkg: Package) : String { + const targets = pkg.targets; + // fast path + if (targets.length === 1) { + return targets[0].kind[0]; + } + // slow path + for( const target of pkg.targets) { + if (target.src_path === uri) { + return target.kind[0]; + } + } + return "lib"; + } } diff --git a/src/cargo.ts b/src/cargo.ts index d17fd66..052c45e 100644 --- a/src/cargo.ts +++ b/src/cargo.ts @@ -6,6 +6,7 @@ import { spawn, SpawnOptions } from "child_process"; export interface Target { name: string; src_path: string; + kind: string[]; } export interface Package {