@@ -1277,3 +1277,74 @@ async fn rustup_updates_cargo_env_if_proxy() {
12771277 )
12781278 . await ;
12791279}
1280+
1281+ #[ tokio:: test]
1282+ async fn rust_analyzer_proxy_falls_back_external ( ) {
1283+ let mut cx = CliTestContext :: new ( Scenario :: SimpleV2 ) . await ;
1284+ cx. config
1285+ . expect_ok ( & [
1286+ "rustup" ,
1287+ "toolchain" ,
1288+ "install" ,
1289+ "stable" ,
1290+ "--profile=minimal" ,
1291+ "--component=rls" ,
1292+ ] )
1293+ . await ;
1294+ cx. config . expect_ok ( & [ "rustup" , "default" , "stable" ] ) . await ;
1295+
1296+ // We pretend to have a `rust-analyzer` installation by reusing the `rls`
1297+ // proxy and mock binary.
1298+ let rls = format ! ( "rls{EXE_SUFFIX}" ) ;
1299+ let ra = format ! ( "rust-analyzer{EXE_SUFFIX}" ) ;
1300+ let exedir = & cx. config . exedir ;
1301+ let bindir = & cx
1302+ . config
1303+ . rustupdir
1304+ . join ( "toolchains" )
1305+ . join ( for_host ! ( "stable-{0}" ) )
1306+ . join ( "bin" ) ;
1307+ for dir in [ exedir, bindir] {
1308+ fs:: rename ( dir. join ( & rls) , dir. join ( & ra) ) . unwrap ( ) ;
1309+ }
1310+
1311+ // Base case: rustup-hosted RA installed, external RA unavailable,
1312+ // use the former.
1313+ let real_path = cx
1314+ . config
1315+ . run ( "rust-analyzer" , & [ "--echo-current-exe" ] , & [ ] )
1316+ . await ;
1317+ assert ! ( real_path. ok) ;
1318+ let real_path_str_with_nl = & real_path. stderr ;
1319+ let real_path_str = real_path_str_with_nl. lines ( ) . next ( ) . unwrap ( ) ;
1320+ let real_path = Path :: new ( real_path_str) ;
1321+
1322+ assert ! ( real_path. is_file( ) ) ;
1323+
1324+ let tempdir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) . unwrap ( ) ;
1325+ let extern_dir = tempdir. path ( ) ;
1326+ let extern_path = & extern_dir. join ( "rust-analyzer" ) ;
1327+ fs:: copy ( real_path, extern_path) . unwrap ( ) ;
1328+
1329+ // First case: rustup-hosted and external RA both installed,
1330+ // prioritize the former.
1331+ cx. config
1332+ . expect_ok_ex_env (
1333+ & [ "rust-analyzer" , "--echo-current-exe" ] ,
1334+ & [ ( "PATH" , & extern_dir. to_string_lossy ( ) ) ] ,
1335+ "" ,
1336+ real_path_str_with_nl,
1337+ )
1338+ . await ;
1339+
1340+ // Second case: rustup-hosted RA unavailable, fallback on the external RA.
1341+ fs:: remove_file ( bindir. join ( & ra) ) . unwrap ( ) ;
1342+ cx. config
1343+ . expect_ok_ex_env (
1344+ & [ "rust-analyzer" , "--echo-current-exe" ] ,
1345+ & [ ( "PATH" , & extern_dir. to_string_lossy ( ) ) ] ,
1346+ "" ,
1347+ & ( extern_path. to_string_lossy ( ) + "\n " ) ,
1348+ )
1349+ . await ;
1350+ }
0 commit comments