[英]Working with single file rust using rust-analyzer
I'm trying to make rust-analyzer (with Neovim) work with a single Rust file.我正在尝试使 rust-analyzer(使用 Neovim)与单个 Rust 文件一起工作。 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.我知道使用 Cargo 应该是默认设置,但我正在尝试解决项目 euler中的问题,在这些问题中,为每个问题制作一个项目似乎有点过头了。 Furthermore, I solve problems in various languages, so I want to make each code self-contained.此外,我用各种语言解决问题,所以我想让每个代码独立。
However, with coc-rust-analyzer , it says:但是,使用coc-rust-analyzer ,它说:
[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.我只想用这个文件运行 rust-analyzer。 What should I do?我应该怎么办?
————— ————
Update: I'm just starting to use Rust, and I used Python, OCaml, C++ for previous problems.更新:我刚刚开始使用 Rust,我使用 Python、OCaml、C++ 来解决以前的问题。 I used rustc
for a simple problem.我用rustc
来解决一个简单的问题。
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像 OCaml 这样的语言使用ocamlfind
和ocamlopt
提供(详细)解决方案,并使用merlin ,它是 vim 和 emacs 的工具,我只需要一个顶级.merlin
文件,例如
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.我本可以使用dune ,这有点像 cargo 的构建系统部分。
I found that rustc
can link external crates, eg rustc executable.rs --extern rary=library.rlib &&./executable
.我发现rustc
可以链接外部 crate,例如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.我承认这可能比基于 Cargo 的解决方案更复杂,但仍然让我怀疑 rust-analyzer 是否只能用于基于 Cargo 的项目。
rust-analyzer can work for standalone/single rust file, https://github.com/rust-analyzer/rust-analyzer/pull/8955 , coc-rust-analyzer supports this too. rust-analyzer 可以用于独立/单个 rust 文件, https://github.com/rust-analyzer/rust-analyzer/pull/8955,coc-rust-analyzer也支持这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.