Skip to content

feat(toolchain): consider external rust-analyzer when calling a proxy #4324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rami3l
Copy link
Member

@rami3l rami3l commented May 7, 2025

Closes #3846.

Following the reasoning in #3846 (comment), the current implementation prioritizes rustup-hosted RA and only delegates to the outside as a final rescue. This way, it will also close #3299.

This approach has also been approved by @davidbarsky in #t-rustup > More frequent rust-analyzer updates in rustup @ 💬 as a temporary measure before the new update cadence for RA on our release server is settled.

Concerns

  • Should we emit a log line indicating the fallback is happening? Idem for the pre-existing cargo fallback.

@rami3l rami3l force-pushed the feat/smarter-ra-shim branch from 6fa6a79 to 9fd24ff Compare May 8, 2025 10:36
@rami3l rami3l marked this pull request as ready for review May 8, 2025 11:44
@rami3l rami3l requested review from djc and ChrisDenton May 8, 2025 11:44
@rami3l rami3l force-pushed the feat/smarter-ra-shim branch 4 times, most recently from 19cc68b to 15569c1 Compare May 8, 2025 11:53
@rami3l rami3l force-pushed the feat/smarter-ra-shim branch from 15569c1 to a45dd3f Compare May 8, 2025 12:21
// Try to find the first `rust-analyzer` under the `$PATH` that is both
// an existing file and not the same file as `me`, i.e. not a rustup proxy.
Ok(env::split_paths(&path).find_map(|mut p| {
p.push(binary);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to check the executable bit of this path. And maybe show the first nonexecutable file path when nothing found.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure about that. If something is in PATH the expectation is that it's executable. It's up to the OS to determine if it actually is or not and I don't think it's useful to second guess it.

Copy link
Member Author

@rami3l rami3l May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this should look more like which in that only executables can be considered candidates (provided that it's as platform-agnostic as it gets). However I'm not very sure about the second half...

Copy link
Member

@weihanglo weihanglo May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And most shells have the behavior, as well as execvp on Linux.

The other way is falling back to call rust-analyzer directly and let OS do whatever it wants, so we don't need to mimic the PATH lookup logic.

edit: the fallback won't work. It'll become an infinite loop… 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From experience I'm very leery of look-before-you-leap because even if you ignore toctou, there's opportunities for things to go wrong on weird filesystems or setups.

Btw, I just tried in bash and it just runs a script without the executable bit (well, it fails, but it tries) and does not read the rest of the PATH.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I just tried in bash and it just runs a script without the executable bit (well, it fails, but it tries) and does not read the rest of the PATH.

I just tried the same on my Mac and I believe that's not the case at least on my machine: a simple touch rust-analyzer can change the interpretation of calling that command depending on chmod +x and chmod -x.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there's a difference between bash and which:

$ which biscuits
/home/chris/.cargo/bin/biscuits
$ biscuits
-bash: /home/chris/temp/biscuits: Permission denied

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisDenton
Did you have another biscuits executable with a lower precedence in your PATH?

That was not my case with bash 5.2.37 on both macOS 15.4.1 and Linux 5.10.235. Not sure what was different 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. /home/chris/.cargo/bin/biscuits is the executable

Copy link
Member Author

@rami3l rami3l May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure, but anyway this is what I've tried, and it seems to be coherent with what which gives (this ~/.moon/bin has higher precedence than the rust-analyzer proxy, of course):

> printf '#!/bin/sh\necho Hello World' > ~/.moon/bin/rust-analyzer
> chmod +x ~/.moon/bin/rust-analyzer
> rust-analyzer
Hello World
> chmod -x ~/.moon/bin/rust-analyzer
> rust-analyzer
error: Unknown binary 'rust-analyzer' in official toolchain 'stable-aarch64-apple-darwin'.

Maybe that's because I'm using fish? No, same behavior using zsh as well.

@rami3l rami3l force-pushed the feat/smarter-ra-shim branch from a45dd3f to a3330ad Compare May 8, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants