I'm trying to make rust-analyzer (with Neovim) work with a single Rust file. I know that using Cargo should be the default, but I'm trying to solve problems like the ones from project euler, where making a project for each problem seems like an overkill. Furthermore, I solve problems in various languages, so I want to make each code self-contained.
However, with coc-rust-analyzer, it says:
[coc.nvim] rust-analyzer failed to discover workspace, no Cargo.toml found, dirs searched: /Users/jay/some-dir
I just want to run rust-analyzer with this file only. What should I do?
—————
Update:
I'm just starting to use Rust, and I used Python, OCaml, C++ for previous problems. I used rustc
for a simple problem.
Languages like OCaml provides a (verbose) solution using
ocamlfind
& ocamlopt
, and to use merlin which is a tool for vim and emacs, I only need a top level .merlin
file like
PKG core stdio ppx_deriving.std ppx_variants_conv
that lists all the packages I need to use. I could have used dune, which is kind of like the build system part of cargo.
I found that rustc
can link external crates, e.g. rustc executable.rs --extern rary=library.rlib && ./executable
. I admit this may be more complex than a Cargo based solution, but still makes me wonder if rust-analyzer can only work with Cargo based projects.
On the highest level, rust-analyzer is a thing which accepts input source code from the client and produces a structured semantic model of the code. More specifically, input data consists of a set of test files ( (PathBuf, String) pairs) and information about project structure, captured in the so called CrateGraph .
We highly recommend giving rust-analyzer a spin today, even if it will take some more time for us to complete the due process and switch from the existing officially recommended LSP implementation (RLS) properly.
Log messages are printed to stderr, in VS Code you can see then in the Output > Rust Analyzer Language Server tab of the panel. To see more logs, set the RA_LOG=info environment variable, this can be done either by setting the environment variable manually or by using rust-analyzer.
Install the rust-analyzer extension# You can find and install the rust-analyzer extension from within VS Code via the Extensions view (Ctrl+Shift+X) and searching for 'rust-analyzer'. You should install the Release Version.
rust-analyzer can work for standalone/single rust file, https://github.com/rust-analyzer/rust-analyzer/pull/8955, coc-rust-analyzer supports this too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With