diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-05-23 16:39:04 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-23 16:39:04 +0200 |
| commit | f4f5fca10175b8d5fdfa36563c103f81b2b0acd3 (patch) | |
| tree | 456d16e30fb799f82f71cff4c7aa91b0248c0220 /editors/code/src | |
| parent | 4cc2ff6e390b6d8015ed1d266425459268f6e0b0 (diff) | |
| parent | 1797b665a4dd82ba176b319c850a8875df327a5d (diff) | |
| download | rust-f4f5fca10175b8d5fdfa36563c103f81b2b0acd3.tar.gz rust-f4f5fca10175b8d5fdfa36563c103f81b2b0acd3.zip | |
Merge pull request #4538 from vsrs/vscode_tests
vscode client side tests
Diffstat (limited to 'editors/code/src')
| -rw-r--r-- | editors/code/src/cargo.ts | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/editors/code/src/cargo.ts b/editors/code/src/cargo.ts index 6a41873d006..a55b2f860f6 100644 --- a/editors/code/src/cargo.ts +++ b/editors/code/src/cargo.ts @@ -12,14 +12,44 @@ interface CompilationArtifact { isTest: boolean; } +export interface ArtifactSpec { + cargoArgs: string[]; + filter?: (artifacts: CompilationArtifact[]) => CompilationArtifact[]; +} + +export function artifactSpec(args: readonly string[]): ArtifactSpec { + const cargoArgs = [...args, "--message-format=json"]; + + // arguments for a runnable from the quick pick should be updated. + // see crates\rust-analyzer\src\main_loop\handlers.rs, handle_code_lens + switch (cargoArgs[0]) { + case "run": cargoArgs[0] = "build"; break; + case "test": { + if (!cargoArgs.includes("--no-run")) { + cargoArgs.push("--no-run"); + } + break; + } + } + + const result: ArtifactSpec = { cargoArgs: cargoArgs }; + if (cargoArgs[0] === "test") { + // for instance, `crates\rust-analyzer\tests\heavy_tests\main.rs` tests + // produce 2 artifacts: {"kind": "bin"} and {"kind": "test"} + result.filter = (artifacts) => artifacts.filter(it => it.isTest); + } + + return result; +} + export class Cargo { constructor(readonly rootFolder: string, readonly output: OutputChannel) { } - private async artifactsFromArgs(cargoArgs: string[]): Promise<CompilationArtifact[]> { + private async getArtifacts(spec: ArtifactSpec): Promise<CompilationArtifact[]> { const artifacts: CompilationArtifact[] = []; try { - await this.runCargo(cargoArgs, + await this.runCargo(spec.cargoArgs, message => { if (message.reason === 'compiler-artifact' && message.executable) { const isBinary = message.target.crate_types.includes('bin'); @@ -43,30 +73,11 @@ export class Cargo { throw new Error(`Cargo invocation has failed: ${err}`); } - return artifacts; + return spec.filter?.(artifacts) ?? artifacts; } async executableFromArgs(args: readonly string[]): Promise<string> { - const cargoArgs = [...args, "--message-format=json"]; - - // arguments for a runnable from the quick pick should be updated. - // see crates\rust-analyzer\src\main_loop\handlers.rs, handle_code_lens - switch (cargoArgs[0]) { - case "run": cargoArgs[0] = "build"; break; - case "test": { - if (cargoArgs.indexOf("--no-run") === -1) { - cargoArgs.push("--no-run"); - } - break; - } - } - - let artifacts = await this.artifactsFromArgs(cargoArgs); - if (cargoArgs[0] === "test") { - // for instance, `crates\rust-analyzer\tests\heavy_tests\main.rs` tests - // produce 2 artifacts: {"kind": "bin"} and {"kind": "test"} - artifacts = artifacts.filter(a => a.isTest); - } + const artifacts = await this.getArtifacts(artifactSpec(args)); if (artifacts.length === 0) { throw new Error('No compilation artifacts'); |
