@@ -3,7 +3,7 @@ import * as os from "os";
33import * as path from "path" ;
44import * as readline from "readline" ;
55import * as vscode from "vscode" ;
6- import { execute , log , memoizeAsync , unwrapNullable , unwrapUndefinable } from "./util" ;
6+ import { log , memoizeAsync , unwrapUndefinable } from "./util" ;
77import type { CargoRunnableArgs } from "./lsp_ext" ;
88
99interface CompilationArtifact {
@@ -55,7 +55,10 @@ export class Cargo {
5555 return result ;
5656 }
5757
58- private async getArtifacts ( spec : ArtifactSpec ) : Promise < CompilationArtifact [ ] > {
58+ private async getArtifacts (
59+ spec : ArtifactSpec ,
60+ env ?: Record < string , string > ,
61+ ) : Promise < CompilationArtifact [ ] > {
5962 const artifacts : CompilationArtifact [ ] = [ ] ;
6063
6164 try {
@@ -78,6 +81,7 @@ export class Cargo {
7881 }
7982 } ,
8083 ( stderr ) => this . output . append ( stderr ) ,
84+ env ,
8185 ) ;
8286 } catch ( err ) {
8387 this . output . show ( true ) ;
@@ -90,6 +94,7 @@ export class Cargo {
9094 async executableFromArgs ( runnableArgs : CargoRunnableArgs ) : Promise < string > {
9195 const artifacts = await this . getArtifacts (
9296 Cargo . artifactSpec ( runnableArgs . cargoArgs , runnableArgs . executableArgs ) ,
97+ runnableArgs . environment ,
9398 ) ;
9499
95100 if ( artifacts . length === 0 ) {
@@ -106,8 +111,9 @@ export class Cargo {
106111 cargoArgs : string [ ] ,
107112 onStdoutJson : ( obj : any ) => void ,
108113 onStderrString : ( data : string ) => void ,
114+ env ?: Record < string , string > ,
109115 ) : Promise < number > {
110- const path = await cargoPath ( ) ;
116+ const path = await cargoPath ( env ) ;
111117 return await new Promise ( ( resolve , reject ) => {
112118 const cargo = cp . spawn ( path , cargoArgs , {
113119 stdio : [ "ignore" , "pipe" , "pipe" ] ,
@@ -133,29 +139,12 @@ export class Cargo {
133139 }
134140}
135141
136- /** Mirrors `project_model::sysroot::discover_sysroot_dir()` implementation*/
137- export async function getSysroot ( dir : string ) : Promise < string > {
138- const rustcPath = await getPathForExecutable ( "rustc" ) ;
139-
140- // do not memoize the result because the toolchain may change between runs
141- return await execute ( `${ rustcPath } --print sysroot` , { cwd : dir } ) ;
142- }
143-
144- export async function getRustcId ( dir : string ) : Promise < string > {
145- const rustcPath = await getPathForExecutable ( "rustc" ) ;
146-
147- // do not memoize the result because the toolchain may change between runs
148- const data = await execute ( `${ rustcPath } -V -v` , { cwd : dir } ) ;
149- const rx = / c o m m i t - h a s h : \s ( .* ) $ / m;
150-
151- const result = unwrapNullable ( rx . exec ( data ) ) ;
152- const first = unwrapUndefinable ( result [ 1 ] ) ;
153- return first ;
154- }
155-
156142/** Mirrors `toolchain::cargo()` implementation */
157143// FIXME: The server should provide this
158- export function cargoPath ( ) : Promise < string > {
144+ export function cargoPath ( env ?: Record < string , string > ) : Promise < string > {
145+ if ( env ?. [ "RUSTC_TOOLCHAIN" ] ) {
146+ return Promise . resolve ( "cargo" ) ;
147+ }
159148 return getPathForExecutable ( "cargo" ) ;
160149}
161150
0 commit comments