-
Notifications
You must be signed in to change notification settings - Fork 257
rls behaviour depends on its current directory when using rustup #375
Comments
The RLS only works with nightly toolchain. If you try and use a stable toolchain everything will break because the versions of dylibs the RLS tries to link against will be wrong. I'm not exactly sure of the ins and outs of using Rustup like you are doing, so I'm not sure if it should be causing problems like this. |
I understand that rls works only with the nightly toolchain - both rls and my test project are set up to use the nightlies. The problem is that RLS does not care which toolchain is configured for the project, and uses the one configured for the current directory of the rls process instead. |
I'm not sure the RLS can do much about this - the toolchain is decided at the point where the RLS process is run, because that's when rustup intercepts the command. The RLS itself, and other tools like rustc and cargo, are unaware of the existence of rustup. |
@Diggsey Why is that? All rls has to do different is defer initializing itself until a initialize request is received, change the working directory to the project root, and then initialize, hasn't it? |
No, the RLS doesn't choose the toolchain - by the time the RLS is running, the toolchain has already been selected and cannot be changed (because each toolchain has its own RLS) |
But why? I thought there is no rust runtime, and executables generated by rustc are just normal binaries. How is the toolchain relevant to a compiled binary at runtime? Are these binaries unable to run on systems where no or a different toolchain is installed? |
@Trolldemorted rls is a bit unusual in that it dynamically links against the compiler which is part of the toolchain. |
So except writing a wrapper that will start up rls only after the init request was received there is nothing non-hackish we can do (i assumed before that rls was a wrapper for the analyser/compiler)? Statically linking is not an option? Related: rust-lang/rustup#765 (comment) |
@nrc I spent some more time on this issue today:
A quick glance at rls-analysis:
=> for rustup users with stable default, rls will be dynamically linked against the installed nightly toolchain (because its in PATH), could have been built with a different version of the nightly toolchain (since rust override allows you to select a certain version of the nightly toolchain), and starts rustc from the stable toolchain. Changing the working directory before responding to the initialize request would help with this a lot. |
Changing or relying on the working directory has caused us many problems in the past. I'd be pretty uncomfortable relying on it again. It is unfortunate that we don't refer to the right rustc in rls-analysis though. However, I don't think it is that which is causing the error - that is only used to find the location of the sysroot to find save-analysis data, not for building. How are you running the RLS? Via VSCode? RLS should be started with the equivalent of |
Any update on this? I'm running into this problem now where RLS is using sources from stable (my default toolchain) when completing code in a project using a pinned nightly (using the |
If you use rustup with the stable toolchain as the default one, and create an override for a project, all rust/cargo commands in that directory use the overwritten toolchain.
However, rls does apparently not use the appropriate toolchain for overridden root directories - when i send a
rootPath
(which is rustup-overridden) in theInitializeParams
, rls sends apublishDiagnostics
message with errors:However, if rls' execution directory is a directory (not neccessarily the project root, any will do) which is also set to nightly, everything works as expected.
The text was updated successfully, but these errors were encountered: