Warning
This post was published 41 days ago. The information described in this article may have changed.
Hi,
Im struggling to get the rust-analyzer visual studio code plugin to work.
I have several crates in my workspace that depend on msvc c++ tools to build (wrapped c++ code). This means I must run rust-analyzer and cargo in a command promt / environment appropriately prepared e.g. "x64 Naitve Tools Command Prompt for VS 2022" as provided by the VS install.
For manual "cargo build" etc. that is fine since I have set visual studio to use that Native tools command prompt as the integrated terminal.
However, I seem unable to configure the rust-analyzer plugin to use that terminal, I have tried various things, the most promissing (but still failing) is to set:
"rust-analyzer.cargo.targetDir": true,
"rust-analyzer.server.path": "ra-ra.bat",
Where ra-ra.bat is a file on PATH with the following content only (needed since server.path seems not to accept arguments but a path to a binary only):
ra-ra.bat
python.exe C:\rust\bin\run-ra.py
And run-ra.py is a short ptyhon script to locate the latest version of the plugin and start the
the bundled rust-analyzer in a correct environment:
run-ra.py
from glob import glob
import subprocess
alt = list(glob("C:\vsc_extensions\rust-lang.rust-analyzer*"))
alt.sort()
ra_path = alt[-1] + "\server\rust-analyzer.exe"
args = ['cmd.exe', '/c',
'C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvars64.bat', "&&", e]
result = subprocess.run(args)
I.e. starting rust-analyzer inside a cmd shell that loads the environemnt first.
The ra-ra.bat and run-ra.py files seem to work fine when I start them manually from a commandprompt, the native tools settings are loaded and rust-analyzer is started (and i can send messages to it from the commandline).
However, the rust-analyzer plugin in visual studio is unable to start it (non descirpt error message in the UI with "spawn EINVAL" and nothing under output in vs code for the language server)
Does anyone know if there is another / better way to ensure that the rust-analyzer plugin starts the rust-analyzer.exe binary in a shell where I can preload a .bat fle (effectively what the native tools from VS does)?
Regards
2 posts - 2 participants
🏷️ rust_feed