Couldn't start client Rust Language Server - visual-studio-code

I'm trying to figure out how to use rustc & cargo from my WSL. I use VS Code and Rust (rls) plugin and can compile my code but there is a problem with RLS:
Couldn't start client Rust Language Server
Rustup not available. Install from https://www.rustup.rs/
How i can solve this problem?

Set rust-client.rustupPath in VSCode settings:
{
"rust-client.rustupPath": "~/.cargo/bin/rustup"
}
If you're using WSL on Windows then make sure you edit Rust extension WSL settings, not user/local settings.
Tutorial:

I had this problem as well with WSL and Visual Studio Code. The problem seems to stem from the fact that the Rust Language Server needs to find rustup in your path. We both probably followed the same path of using a package manager to install cargo, and therefore, the rust compiler tools. This does not include rustup which you can actually use to keep the rust toolchain up-to-date. rustup also appears to be the preferred method of installing the rust toolchain on your system.
After installing rustup with the default setup, you should see a .rustup directory in your home directory. This is where the toolchain lives. The install text all stated that it would add the toolchain to your environment path after logging out and back in, but I didn't have luck with this. I'm currently using fish instead of bash and had to update the configuration to include the toolchain at startup. Once I did that, I was able to have VSCode properly install and run the RLS.

This worked for me for in a remote SSH environment with Ubuntu 20.04
Edit .profile and .bashrc files in the user home directory
In .profile, comment the following line:
export PATH="$HOME/.cargo/bin:$PATH"
In both, add the following line:
[[ ":$PATH:" != *":$HOME/.cargo/bin:"* ]] && PATH="$HOME/.cargo/bin:${PATH}"
Reboot.

Even though if I run:
which rustup
/Users/justincalleja/.cargo/bin/rustup
A simple entry of rustup in the VSCode settings for:
"Rust-client: Rustup Path Path to rustup executable. Ignored if rustup
is disabled."
wasn't enough and I had to put the absolute path to the rustup binary as shown above. After doing so, I reloaded the window and was then asked to download missing components (or dependencies - the prompt is gone now I forgot). After doing this, the VSCode plugin seems to be working fine. I can format the code at least.
So it looks like it's some mismatch with VSCode's PATH and the PATH on my system. I'm not sure what it is but if you just want to get the extension to work, try using the absolute path to rustup in your Settings.
(Note: source "$HOME/.cargo/env" is added automatically to your startup files like .bashrc. First thing I tried was adding it to the startup file of zsh; the shell I'm using and to which it wasn't added. But that doesn't work either. I'm using rustc 1.49.0 (e1884a8e3 2020-12-29) ).

So... I'm running Rust on Windows 10 and I experienced this same issue. My Rust version is 1.24.3, my VSCode version is 1.63.2.
The first thing you need to do is add "%USERPROFILE%.cargo\bin" to your environment variables
The next solution that worked for me can be found in this tutorial: Rust on Windows and Visual Studio Code

i am running VSCode on mac, and using remote development.the remote server is
ubuntu 20. i had this problem, added rust-client.rustupPath to vscode settings and killed the vscode-server on remote server to fix this problem. now it work.

Related

rust-analyzer failed to load workspace: "cargo" "--version" failed: program not found

I have Rust installed using WSL2 Ubuntu I have alredy ran basic commands like hello world in rust so cargo is working. I wanted to download the rust-analyzer in VSCODE but I keep getting that error message from the title: rust-analyzer failed to load workspace: "cargo" "--version" failed: program not found
I tried ensuring all paths are correct, all vesions of extension and vscode and rust are up to date. several uninstall re-installs and rustup updates. Toolchain is using stable version. I have reviewed a lot of the other post about this accross all platforms but it seems I can not find the fix. It would be very helpful to get some guidance. Thank you!st
The solution is to open folder as if in WSL.
To do that you need to install this VS code extension called Remote development
Than go to the green symbol in the bottom right corner and then select open WSL folder and open folder with your rust project or just open new WSL window
The last step is to go to extensions and then search for rust-analyzer and hit install
More info regarding the development on WSL can be found here
another good option is open your wsl, move to the project folder and type $ code . or $ code YOUR_PROJECT, then install rust-analyzer extension
Remove the rustc and cargo provide by system package manager (e.g. apt).
Install them from offical rustup script instead.
[note]
I just encounter the same problem when using flatpak version of Lapce.
rust-analyzer failed to load workspace: "cargo" "--version" failed: No such file or directory (os error 2)

why my vscode does not have the same libraries installed in wsl?

I'm using wsl and it runs codes in vscode pretty fine and I have different libraries which I installed through pip and conda in wsl but when I run that code using vscode itself it doesn't recognize the libraries or even pip itself.
I don't have any other environment.
I should add that I installed the packages globally using conda install ... or pip install ... in base environment and I only have base environment and I run my code through code . and I also have python and remote wsl extensions installed in my vscode.
what can be the problem?
I don't have much personal experience with this, but I found some useful information in this Stack Overflow question (even though it doesn't utilize conda), along with https://code.visualstudio.com/docs/remote/wsl-tutorial#_python-development.
I also found this blog post useful, even if it doesn't cover WSL.
In short, make sure you:
Have installed the Python extension (by Microsoft) in VSCode. This is critical for being able to detect and select the Python interpreter. You don't mention having this in place, so I believe this is your likely problem.
You have done this already, but including it for others who might read this later -- Install the Remote - WSL extension (or the Remote Development extension pack) in VSCode.
You are also doing this already -- Start VSCode from inside your WSL distribution. Alternatively, you can start VSCode from Windows and then select the Remote WSL - Reopen Folder in WSL from the Command Palette (also accessible from the "Remote" Status Bar).
In VSCode, open the Command Palette with Shift+Ctrl+P, search for the Python: Select Interpreter command, and you should find your Conda environment in the list.
After selecting this, you should find that your project is using the interpreter and modules that you have installed via conda.
One thing I did to overcome this issue is go to Extensions -> Local (You should have two tabs there, Local and WSL:DISTRO) DISTRO refers to whatever DISTRO you're using, you will see that some of the local extensions are disabled in the current workspace (WSL) and there is a little cloud icon in the WSL:DISTRO tab that says install Local Extensions in WSL:DISTRO once you click that it will let you choose which extensions to install and you should be good to go!

Visual Studio Code, code command does not start new file

I'm having an issue where if I do code <filename> where the file does not already exist, it does not create a new file.
Normally, vscode would (almost) create a new file, I could write some code, and then save it and it would appear in my file manager. But this just stopped working.
I had a look through all my extensions and uninstalled all the recent extensions. I've reinstalled vscode, still no luck.
I am using windows with wsl, this affects me when running vscode both in windows and in wsl.
Did some googling around, can't find anything useful. Any advice?
I figured out what caused this in case anyone else is having the same problem.
I installed Rust in windows and that seemed to have messed up the code command.
Sorry, can't remember which version it was, I just uninstalled it on windows and noticed that it fixed it.
(p.s: Rust is great, but I have it installed in WSL so don't need it in windows.)
If you are using npm on windows, you can install touch by running npm i -g touch and creating a folder in a specific location by navigating in the location and creating by mkdir <foldername> navigating inside it and using touch <filename>. From there you can simply launch VS Code by running code . in that folder namespace
If you are using WSL (Ubuntu), it comes preinstalled and you can run mkdir <foldername> && touch <filename> && code .
Not exactly what you are looking for but it can work!

Is it possible to specify the path to the libstdc++ in VS Code clangd extension?

I use VS Code as my main code editor for my C++ development. I am using the remote SSH extension by Microsoft to access my office workstation from home. For the C++ autocompletion and linting I use the clangd extension by LLVM. Company policy prevents users from having sudo access to workstations and libraries are often not at the latest version.
When I try to launch clangd I get the following error message:
/lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by /my/path/to/clangd)
Which obviously means that the version of libstdc++ is too old for the version of clangd that I am using. This is easily fixable by adding to LD_LIBRARY_PATH the location of most recent gcc libraries (part of our compiler toolchain) and then launching VS Code.
However, now that I am working remotely I cannot do that because VS Code is installed onto my laptop and I am using the SSH extension to access the code on my office workstation. Looking on the man page for clangd I cannot see a way to specify the path to the libstdc++ that I want to use. Is there a way, other than adding the libraries to the LD_LIBRARY_PATH upon startup/login, to bypass this issue?
I found a way, albeit a little bit hacky.
Export the new LD_LIBRARY_PATH on .zprofile (or equivalent for your shell. I am using zsh). Make sure that there are no VSCode servers running in the host. If there are, make sure to remove them.
In the settings.json file add the following line, to tell VSCode that you want the shell to be a login, interactive shell:
"terminal.integrated.shellArgs.linux": ["-l", "-i"]
Job done. Clangd now finds the correct libraries.
Another way to do this is to use env in your settings.json as follows:
"clangd.path": "env",
"clangd.arguments": [
"LD_LIBRARY_PATH=<your_custom_path>",
"/path/to/my/clangd"
],

Version mismatch between tsc compiler and VS Code's language service

I just started playing with Visual Studio Code and when I created a new file called index.html, I am shown this warning message
A version mismatch between the globally installed tsc compiler (1.0.3.0) and VS Code's language service (1.8.10) has
Can someone please guide me what i have to do to fix this.
Is this serious or I can ignore. I googled but could not get much info
Thanks
I added this to my settings.json file, accessed through preferences > Workspace Settings :
"typescript.tsdk": "node_modules/typescript/lib"
now I no longer receive this error and in the bottom right corner of my screen it shows the current version of Typescript that I have installed.
[UPDATE] VS Code 1.6 now ships with TypeScript 2.0.3.
I just installed the latest Typescript, currently v.2.0.3, and installed VS Code v.1.5.3 on macOS Sierra. For some reason, exactly following the official doc didn't work for me.
Here's how I made it work:
After having installed the latest version globally:
npm i -g typescript, I added the following line to my settings.json file (opened by cmd + ,):
"typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib",
Hope this helps someone else.
[update] as #ptpaterson mentioned on the comment below, on Windows the path is: "typescript.tsdk": "C:/Users/{user_name}/AppData/Roaming/npm/node_modules/typescript/lib/"
You have to change the version of TypeScript that Visual Code is using to match the version you have installed:
https://code.visualstudio.com/docs/languages/typescript#_using-newer-typescript-versions
The above is taken from the link:
If you want to use a newer version of TypeScript, you can define the typescript.tsdk setting (File > Preferences > User/Workspace Settings) pointing to a directory containing the TypeScript tsserver.js file.
You can find the installation location using npm list typescript, tsserver.js is usually under the lib folder.
For example:
{
"typescript.tsdk": "node_modules/typescript/lib"
}
You have to update your Typescript installation and restart Code afterwards:
npm install -g typescript
or
npm install -g typescript#1.8.10
The message should not longer appear, if it worked.
This error was being generated because I had a reference to an older installation of TypeScript in my System Path variable:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
The Visual Studio Code error was resolved when I removed this entry.
However, my TypeScript files then failed to transpile as the build action couldn't find the tsc.exe file.
When the SDK is installed (through Visual Studio or via a manual *.visx install), a tsc.exe file is installed and the PATH environment variable is updated to reference the folder that this file resides in (see above).
There is another way to transpile your files on a Windows environment by using node.js:
Install node.js. Installation packages can be found here.
Use npm to install TypeScript:
npm install -g typescript
This will add the TypeScript files to your profile AppData folder:
C:\Users\{your_user_name}\AppData\Roaming\npm\node_modules\typescript\lib
Configure your Visual Studio Code user settings.json file to reference this folder:
{
"typescript.tsdk": "C:\\Users\\{your_user_name}\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib"
}
Add / update the user PATH environment variable to reference the folder that contains the tsc.cmd file:
%USERPROFILE%\AppData\Roaming\npm
None of the solutions above worked for me - first of all this is the global tsc I want to have updated to the latest version.
After I did some investigation it turned out that the problem lies in system's PATH variables; tsc.cmd (along with tscserver.cmd) exists in these locations:
c:\Program Files\nodejs - where the npm.exe and node.exe are
%USERPROFILE%\AppData\Roaming\npm - where global packages are
What you can do is to juggle environment\user variables so the tsc command would be resolved from %USERPROFILE% first instead of Program Files.
The quick & dirty way would be just deleting tsc.cmd and tscserver.cmd from the Program Files path.
Installing v2.0.3 of typescript was not sufficient... but but then updating the version dependency on package.json worked for me.
Npm command:
npm install -g typescript#2.0.3
Updated line on package.json:
"typescript": "^2.0.3"
The cause of my experience with this issue (in VSCode 1.8 on Mac OS X 10.12.2) was that I have been using NVM and while my code was running on the NVM version, VSCode was looking at a system installation of node.
Double check which installation of npm you are using to install typescript globally. If in doubt (on linux/mac) use which tsc from the command-line to verify the location being used by VSCode.
For example, if I simply call npm i -g typescript, npm resolves to ~/.nvm/versions/node/v6.9.1/bin/npm. I had to solve the problem by calling /usr/local/bin/npm i -g typescript explicitly because VSCode looks for node in /usr/local/bin/node by default.
Install TypeScript globally to share the installation across workspaces. In this case, you install it using npm install -g typescript#next.
You then have to tell VS Code on setting.json file (File -> Preferences -> Workspace Settings) the install location using the typescript.tsdk setting. Set typescript.tsdk to the path of the lib folder containing the tsserver.js file of the installed TypeScript module.
On windows:
"typescript.tsdk": "C:/Users/<MyUser>/AppData/Roaming/npm/node_modules/typescript/lib"
On Mac:
"typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib"
Installing VSCode 1.6.0 fixed the TypeScript version mismatch warning message for me.
You'd think that this being a Microsoft product they'd give the Windows paths on their website
https://code.visualstudio.com/docs/languages/typescript#_using-newer-typescript-versions
but they don't. They only give the Unix path types.
Use:-
On windows: "typescript.tsdk": "C:/Users/YourNameHere/AppData/Roaming/npm/node_modules/typescript/lib/"
Note that forward strokes must be used even though Windows uses backstrokes for the paths!
Some other answers miss off the last forward stroke which is necessary.
You can just remove 'typescript.tsdk' and use the one embedded in Code if you don't really care about which tsdk version you use.