I'm building a Rust game with Piston and I'm trying to use the SublimeLinter Rust package. When I open my .rs game files, I get this linter error:
extern crate piston; // linter error: "can't find crate for 'piston'"
If I check the Sublime console, I can see that the linter is finding rustc:
SublimeLinter: rust activated: /usr/local/bin/rustc
I don't see any obvious error messages in the console. I have piston listed as a dependency in my Cargo.toml and I'm able to cargo run successfully.
I'm a complete Rust & SublimeLinter newbie.
I get a similar error for whichever import I put first; for example if I move extern crate graphics; to be the first line in the file I get the error "can't find crate for 'graphics'".
EDIT: turns out enabling the "use-cargo" setting fixed the issue. I added a ".sublimelinterrc" file to my project root with these contents:
{
"linters": {
"rust": {
"use-crate-root": true,
"use-cargo": true
}
}
}
I have not been able to reproduce your error. However, I'll list what I did that seemed to work. Perhaps you will see a step where we diverged, and that will give you a hint of where to look.
I installed Sublime Text 3. I chose the stable channel, build 3083. I installed Package Control, and then three packages:
SublimeLinter (3.5.1)
SublimeLinter-contrib-rustc (1.3.5)
Rust (2015.05.28.16.43.21)
I restarted Sublime Text and opened a project of mine that uses Cargo and depends on other packages. I opened the console (ctrl-`) and enabled debug mode, which takes effect at the next Sublime restart.
Because I have non-standard install of Rust, I saw that Sublime was unable to run rustc due to missing dynamic libraries. I then closed Sublime, and opened it from my terminal: open /Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text. This uses my environment variables set by my shell.
I saw that the linter was complaining that my library had no main method, so I enabled the use-cargo option.
SublimeLinter: rust output:
error: main function not found
error: aborting due to previous error
After changing the use-cargo setting, I caused a deliberate syntax error in my code and saw that it was highlighted. I then misnamed the crate in the extern crate line, and saw it was highlighted.
At no point did there seem to be a problem with finding crates. I could tell that cargo was being used via the console:
SublimeLinter: rust output:
Updating registry `https://github.com/rust-lang/crates.io-index`
Downloading rand v0.3.9
...
Related
Whenever I create a new rust file in neovim it says that it is not a part of module tree and I get a bunch of errors. The weird thing is it eventually it just starts working but that is not good enough so my question is how to manually add files to the module tree in vim.
I have tried restarting vim and reinstalling coc rust but nothing has worked.
For files to be part of the module tree they have to be mentioned in the hierarchy somewhere i.e.:
// my_mod.rs
pub fn some_code() {}
// lib.rs or main.rs
mod my_mod; // without this line you will get the error
If the file is mentioned and the error still persists sometimes the state in rust_analyzer gets out of sync and a restart of it should resolve it.
I know that there are a lot of similar questions regarding rust-analyzer and I've checked them out but couldn't find the solution to my problem so I decided to ask a question myself. I've decided to start learning Rust and I'm having issues with rust-analyzer.
Here is my workspace structure:
I created a project using cargo and hoped that rust-analyzer will automatically register it but for some reason it fails.
I get this error message
> rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/remax/Storage/Projects/rust/rusttest/hello_cargo/Cargo.toml, cargo 1.61.0 (a028ae4 2022-04-29): Failed to run `"/home/remax/.cargo/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/remax/Storage/Projects/rust/rusttest/hello_cargo/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: could not execute process `rustc -vV` (never executed)
Caused by:
No such file or directory (os error 2)
I honestly have no idea what to do.
My cargo version is 1.61.0
UPDATE: issue persists even with only rust project in workspace
You missed the rustup step. It is stated in the rust-analyzer extension that you need to install rustup first.
Quick start
install rustup
install the rust-analyzer extension.
rustup must be installed in the same system as Vscode. If you are using WLS Subsystem (like me), try installing rustup on Windows with the rustup-init.exe.
Run/Debug won't work (probably - I don't know why, but there's always cargo run) but you'll still get all the other features.
I am learning rust by building a cli. The project uses gstreamer-rs. So far it works well on my machine but I still can't figure out how to distribute the binary.
The project and the test realease
Running cargo build --release builds a target that is around 500 MB large.
I thought that I could ask my friend to install the required dependecies by apt-installing the libraries that would appear in the error while he tried to run the binary from the release.
But from the error message, it seems like the binary stores the path to libraries on my machine (/home/nsrcodes/ is my home directory)
thread 'main' panicked at 'Unable to make desktop-audio-encoder: BoolError { message: "Failed to create element from factory name", filename: "/home/nsrcodes/.cargo/registry/src/github.com-1ecc6299db9ec823/gstreamer-0.17.4/src/auto/element_factory.rs", function: "gstreamer::auto::element_factory", line: 204 }', src/recorder.rs:79:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
what is the right way to distribute this?
I'm trying to follow this guide to be able to have source code coverage for a project in Rust.
I did the following:
Installed grcov
cargo install grcov
Added llvm-tools-preview
rustup component add llvm-tools-preview
Set my RUSTFLAGS variable to "-Zinstrument-coverage"
set RUSTFLAGS="-Zinstrument-coverage"
I build my project
cargo build
Set my LLVM_PROFILE_FILE variable to: "test-%p-%m.profraw"
set LLVM_PROFILE_FILE="test-%p-%m.profraw"
Run my tests with
cargo test
But no .profraw files appears, I only have the following:
Am I missing some extra configuration?
Here is my environment information:
cargo 1.57.0 (b2e52d7ca 2021-10-21)
release: 1.57.0
host: x86_64-pc-windows-msvc
os: Windows 10.0.18363 (Windows 10 Enterprise) [64-bit]
Thank you in advance for your help.
I was seeing similar behavior with rust 1.61 nightly on windows. I noticed warning messages stating ""test-%p-%m.profraw"" could not be written. In my case, the fix was to change how I set the LLVM_PROFILE_FILE environment variable. If I set it like:
set LLVM_PROFILE_FILE=test-%p-%m.profraw without the wrapping quotation marks and re-run my tests, the .profraw files are generated.
Your mileage may vary. I had the same issue with the RUSTFLAGS environment variable where I had to remove the quotes for it to even compile.
Another noteworthy thing I encountered with 1.61 is a warning that -Zinstrument-coverage is deprecated in favor of -Cinstrument-coverage.
Intellisense isn't working in VSCode. Examples like:
F2 (rename symbol): shows "initializing JS/TS language feature", but stucks forever issue-image
dropdown suggestions not coming up directly, ctrl+enter shows loading, but not getting completed
doesn't show error even in case of genuine error, etc.
Already tried below things:
restarted VScode multiple times
Ctrl+Shift+P > typescript: Restart TS server --> nothing happens
Installed & uninstalled extension (TSLint, JsHint, ESLint)
"Help" -> "check for updates" --> says "there are currently no updates available"
re-ran all command i.e. npm run setup-npm-auth, npm install etc.
tried force build
{verified my solution is getting built properly}
Current versions:
npm: 6.9.0
node: 10.16.3
VScode version
I just had the same issue. Fortunately I was able to fix the problem following this steps from vscode github's comments. You can enable ts language server's log and debug your issue. To enable ts server logging:
Set "typescript.tsserver.trace": "verbose" (Restart vscode)
Reproduce the problem
Open the output panel and view the TypeScript section
In my case my code was referencing to the directory outside of the workspace. So VSCode could never finish the task. I am not sure it's bug or limitation, nevertheless make sure all of your working code is included in your VSCode workspace (or added to working folders). Otherwise it'll stuck like this even code you're referring to exists side by side but not included in your workspace (or visible) in your VSCode.