diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..47978cf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +language: node_js +node_js: +- '8' +sudo: false +os: +- linux +before_install: +- if [ $TRAVIS_OS_NAME == "linux" ]; then export CXX="g++-4.9" CC="gcc-4.9" DISPLAY=:99.0; + sh -e /etc/init.d/xvfb start; sleep 3; fi +install: +- npm install +- "./node_modules/.bin/vsce package" +script: +- npm test --silent +deploy: + provider: releases + api_key: + secure: Cubt88tWEdFNNIcY3yfcyOJiKFGkKzuDtZukRSGoubKZ40iHEXL0T5tbuMQ7AL+Gy43JjhymXjmLXnQ1avks99KJ2v30V7b82JaamGlK6jxvC4dD5CmkcT5wfpbVItwVnK4l/LrsAmEvhi8sUfLfS8p22eVTUITQk9zlxxkWw5NOCYbMzsNSGTsbsGf5KWAxKEWBseLztZsNQQq3Xfm5rK+pTd6cG1I3uOFZnGt225ztTQf3rjB4CqSO0mjMTh186jghQatAhYGhId0lMg9hK9TpugDCGbhZqGErs5YRAi4/3Bx+f3rHBUV3QfewGS4IxfqM7AeWhcaaWa5pbKSXFZkBbrWWQMLIhBtuljxuaCD/52HucA72RK02nkUXqXnP+slKbXyeP7xfsJz8yG7FUWg/uhFbXz73uI0nG2dE7uSSjRYnHR4qjYarR16QMTwjgPSjI11aRKYiEPx6zVMV1JA+LR2DhIIl33jJXOKRLPuuWLFpNnB4jS4caQY61Ha+FDCNf5pOrieEAv6DoYVnjfN5Jks8KlDlHXtsBV4q6McY68RpgbCun7sme9+9O7LlQG0vJJ3k6pNQP8ishQBBOmE+3abbRYE17ja1Nhp2NTsOYWUpvajPO2HPfIuOq26PRjQcg3c5vXiKl0hTEiJ95GpW95WL8p0aGtZy1UyufSA= + file_glob: true + file: rust-test-lens-*.vsix + on: + repo: hdevalke/rust-test-lens + tags: true + skip_cleanup: true + diff --git a/CHANGELOG.md b/CHANGELOG.md index 4288323..76a9c4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ 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.1.0 + +- Adds a Debug codelens to the main function in binaries and examples. + ## 0.0.5 - Solves the problem if there are still multiple binaries found. E.g. integration tests. diff --git a/README.md b/README.md index 18007ce..946ed46 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Rust Test Lens +[![Build Status](https://travis-ci.org/hdevalke/rust-test-lens.svg?branch=master)](https://travis-ci.org/hdevalke/rust-test-lens) + A code lens to debug test in rust source files. ![test lens](images/test_codelens.png) diff --git a/package.json b/package.json index 9ac0886..2f58f83 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "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.5", + "version": "0.1.0", "publisher": "hdevalke", "engines": { "vscode": "^1.30.2" diff --git a/src/RustCodeLensProvider.ts b/src/RustCodeLensProvider.ts index e1a5a2c..0d39472 100644 --- a/src/RustCodeLensProvider.ts +++ b/src/RustCodeLensProvider.ts @@ -16,11 +16,32 @@ export class RustCodeLensProvider implements CodeLensProvider { return this._onDidChange.event; } - public async provideCodeLenses(doc: TextDocument, - token: CancellationToken): Promise { + public async provideCodeLenses(doc: TextDocument, + token: CancellationToken): Promise { if (token.isCancellationRequested) { return []; } + + let lenses: CodeLens[] = this.testMethodLenses(doc); + lenses.push(...this.mainMethodLenses(doc)); + return lenses; + } + + private mainMethodLenses(doc: TextDocument): any { + const text = doc.getText(); + const reFnMain = /fn\s+(main)\s*\(\s*\)/g; + const match = reFnMain.exec(text); + let lenses: CodeLens[] = []; + if (match !== null) { + const codelens = this.makeLens(reFnMain.lastIndex, match[1], doc); + if (codelens !== undefined) { + lenses.push(codelens); + } + } + return lenses; + } + + private testMethodLenses(doc: TextDocument) { const text = doc.getText(); const reTest = /#\[test\]/g; const reFnTest = /fn\s+(.+)\s*\(\s*\)/g; @@ -30,37 +51,50 @@ export class RustCodeLensProvider implements CodeLensProvider { const match = reFnTest.exec(text); const fn = match === null ? null : match[1]; if (fn) { - const startIdx = reFnTest.lastIndex - fn.length - 3; - const start = doc.positionAt(startIdx); - const end = doc.positionAt(reFnTest.lastIndex); - const range = new Range(start, end); - const debugConfig = this.createDebugConfig(fn, doc.fileName); - if (debugConfig) { - lenses.push(new CodeLens(range, { - title: 'Debug test', - command: "extension.debugTest", - tooltip: 'Debug Test', - arguments: [debugConfig] - })); + const codelens = this.makeLens(reFnTest.lastIndex, fn, doc); + if (codelens !== undefined) { + lenses.push(codelens); } } } return lenses; } + private makeLens(index: number, fn: string, doc: TextDocument) { + const startIdx = index - fn.length; + const start = doc.positionAt(startIdx); + const end = doc.positionAt(index); + const range = new Range(start, end); + const debugConfig = this.createDebugConfig(fn, doc.fileName); + if (debugConfig) { + return new CodeLens(range, { + title: 'Debug', + command: "extension.debugTest", + tooltip: 'Debug', + arguments: [debugConfig] + }); + } + } + createDebugConfig(fn: string, uri: string): DebugConfiguration | undefined { const pkg = this.rustTests.getPackage(fn, uri); if (pkg) { + const args = fn === "main" + ? [ + "build", + `--package=${pkg.name}` + ] + : [ + "test", + "--no-run", + `--package=${pkg.name}` + ]; const debugConfig = { type: "lldb", request: "launch", name: `Debug ${fn} in ${basename(uri)}`, cargo: { - args: [ - "test", - "--no-run", - `--package=${pkg.name}` - ], + args: args, filter: {} as any, }, args: [fn],