What does the rust-analyzer error "could not resolve macro `$crate::format_args`" mean and how do I fix it? - visual-studio-code

I'm using rust-analyzer version 0.2.408 on Visual Studio Code.
I'm writing a command line application that involves centering text in the terminal. This is the function I wrote to do this:
use console::{Alignment, pad_str};
fn get_padded_row(row: &str, width: u16, symbol: Option<char>) -> String {
let symbol = symbol.unwrap_or(' ');
return pad_str(row, width as usize, Alignment::Center, None)
.to_string()
.replace(' ', &symbol.to_string());
}
This function works perfectly fine, and there were no errors with it. Then I wrote a test:
#[cfg(test)]
mod tests {
use crate::get_padded_row;
#[test]
fn row_padding_dashes() {
let padded_row = get_padded_row("hello", 15, Some('-'));
assert_eq!(
padded_row, "-----hello-----".to_string(),
"`get_padded_row` was not correct, got `{}`", padded_row
);
}
}
The code still works perfectly fine. Both cargo run and cargo test work, the function passes the test, and cargo check returns no issues. But rust-analyzer gives an error, highlighting everything from the tr}; in the use statement to the p right after return: "could not resolve macro $crate::format_args rust-analyzer(macro-error)". Searching for this error returns nothing. VSCode links me to rust-analyzer user manual, which says only "This diagnostic is shown for macro expansion errors". Restarting VSCode and reinstalling rust-analyzer have done nothing. The error always comes back, and highlighting the same oddly specific region. The only way I've found to get rid of it while keeping rust-analyzer installed is to remove the test.
Judging from how the error is about macro expansion, and how removing the test fixes the issue, I'd imagine it's caused by the #[test] macro, but it's strange that rustc finds no issues at all with my code while rust-analyzer is freaking out about this error. So far, I've had better experiences with rust-analyzer than with the official Rust VSCode extension, but I'm on the verge of switching back to fix this issue.

This is a bug in rust-analyzer. For now, you can disable the warning in your settings.json:
"rust-analyzer.diagnostics.disabled": [
"macro-error"
]
The bug was fixed on nightly, so you could install the nightly binary of rust-analyzer from GitHub, or you could just wait a couple days for the fix to land on stable.
Alternatively, you could downgrade to rls version 0.2.400, because the bug was caused by a commit in version 0.2.408:
Extensions Icon -> rust-analyzer -> Manage (gear icon) -> Install Another Version

Three months later and there seems to be a bug with Nightly release? Unsure.
I added unresolved-macro-call to Diagnostics: Disabled settings for rust-analyzer.

I've tried many things, read the open issue on github, etc which is tagged as solved, but persists here.
For vscode users, open settings (json) and disable by adding:
"rust-analyzer.procMacro.enable": false

Related

VSCode says "Failed to run custom build command" on cbindgen, but it actually works

I have a Rust (2021) lib. It compiled fine.
I added a build.rs file with this in it:
extern crate cbindgen;
use std::env;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
cbindgen::Builder::new()
.with_crate(crate_dir)
.generate()
.expect("Unable to generate bindings")
.write_to_file("rush_engine.h");
}
Next, I added this to the bottom of Cargo.toml:
[build-dependencies]
cbindgen = "0.20.0"
Finally, I added a cbindgen.toml file with the contents of this:
https://github.com/eqrion/cbindgen/blob/master/template.toml
If I run 'cargo build' the .h file appears as expected and there's no errors from cargo in the terminal window.
However, VS Code has the entire Cargo.toml underlined under every word with red squiggles and there's an error message at the bottom saying 'failed to run custom build command for lib_name'.
I cannot find a solution to this (have removed everything and re-added, cleaned out target folder, etc) and though it's not breaking anything, it's kinda off-putting that this glaring error keeps showing.
Any pointers on how to solve this would be grately appreciated.
Cheers
Jase
Additional requested info:
The Cargo.toml at issue looks like this:
[package]
name = "rush_engine"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "staticlib"]
[dependencies]
chrono = "0.4"
[build-dependencies]
cbindgen = "0.20.0"
The VSCode extensions I'm using are:
rust-lang.rust (version 0.7.8)
...that's literally it. I don't see anything else rust related in running extensions.
Something Francis Gagné (thanks!) said got me wondering and experimenting. That's how I found a solution.
The solution (for me) was uninstall the official Rust extension, then install the rust-analyzer extension. This seems to have the exact same functionality, and it's not red-squiggling my entire Cargo.toml file, too!

Live Sass Compiler - #use causes compilation error

I'm using Live Sass Compiler v3.0.0 in my VS Code and it throws a compilation error whenever I use the #use rule to import variables from another file. However, when I use the Sass command line interface (sass --watch) to compile my files, it throws no errors.
Therefore, I want to ask is this caused by a syntax error in my code or a bug of Live Sass Compiler.
Steps to Reproduce
File Structure & Code
This is the file structure of the folder called sass-test that I opened in VS Code:
sass-test
| style.scss
| _variables.scss
style.scss
#use "variables";
html {
color: variables.$primaryColor;
}
_variables.scss
$primaryColor: #ff0000;
Live Sass Compiler Output
Open style.scss in a new tab in VS Code. Then, click the "Watch Sass" button located in the bottom right of the window. Live Sass Compiler would output the following error:
Compiling Sass/Scss Files:
d:\Web Development\sass-test\style.scss
--------------------
Compilation Error
Error: Invalid CSS after " color: variables": expected expression (e.g. 1px, bold), was ".$primaryColor;"
on line 4 of sass/d:\Web Development\sass-test\style.scss
>> color: variables.$primaryColor;
------------------^
--------------------
Watching...
-------------------
Sass CLI Output
Open Terminal and run sass --watch style.scss:style.css. The compiler successfully compiles without any errors:
Compiled style.scss to style.css.
Sass is watching for changes. Press Ctrl-C to stop.
Since my code can compile successfully with Sass CLI, does it mean that my code is syntactically correct and it's caused by a bug from the Live Sass Compiler extension?
I had same/similar problem two days ago.
#use is a new directive introduced in the new official Version 'Dart Sass' and replaces '#import' which is depricated now.
The popular Extension 'Live Sass Compiler' in VS Code is not longer supported by the maintainer for some time. So unfortunately the Sass Version is not updated in that extension...
In VS Code for 'Dart Sass' I found the the Extension 'DartJS Sass Compiler':
https://marketplace.visualstudio.com/items?itemName=codelios.dartsass
Actual I just did a quick testing so I cannot report much about it. But on the first glance it is running well. But as it is another extension you may have to change some settings.
UPDATE
Additional to the above reported exentsion DartJS Sass Compiler with actual SASS version I found an actualised and actual maintained fork of Live Sass Compiler. It has been deep hidden in the searching reuslts. As it is a very popular extension in VS Code here the link to the fork:
https://marketplace.visualstudio.com/items?itemName=glenn2223.live-sass
Remark:
I played arround with both extension. Both are doing the job well and have advantages.
'DartJS Sass Compiler' has the additional possibility for more detailed output like information about sass version and watchers. And additional to included SASS version it allows to use your own SASS version if installed to your system or locally to your project. So there is no/less dependency on updates by the maintainer.
'Live Sass Compiler' runs out of the box with included sass version. As it is a very popular extension in VS Code there is a special advantage: it seems it keeps your settings in the old projects running.
I think both are good solutions.

ESLint/VSCode marking valid imports as unresolved

Having problems with the ESLint plugin for VSCode. It's marking a lot of inputs that are valid as unresolvable. Dunno how to fix it :/ Local server still runs fine despite the linter marking problems but it's really annoying seeing errors everywhere that aren't errors. My coworker thinks it has something to do with BABEL_ENV variable?
In my case I had specified the paths property on the tsconfig.json file but I was still facing the error on vscode but whenever I was running eslint via CLI the issue wasn't reported.
If you read the description of the eslint plugin on vscode there's asection that talks about eslint.workingDirectories which fixed it for me when I set that option to {"mode": "auto"} on the vscode settings
I guess your import statement like import Foo from "#/components/Foo".
If you import like this, you should setup compiler settings in tsconfig.json or jsconfig.json, like below
{
"compilerOptions": {
...
"paths": {
"#/*": ["src/*"]
}
...
},
...
}

Dart static type errors (instead of just warnings) in Eclipse

I am using the Dart plugin for Eclipse (not the standalone Dart Editor).
How do I configure the project/build so that static type warnings appear as errors in the Eclipse "Problems" tab? For example, this line of code actually compiles, which seems ludicrous:
int newtodo = new LIElement();
Running dartanalyzer at the command line gives an error, as desired:
dartanalyzer foo.dart
But instead of having to run dartanalyzer at the command line (or discovering them at runtime), I would like to have these errors reported on-the-fly in Eclipse.
If this doesn't produce a warning this is a bug according to this discussion new user question. type warnings as errors in Eclipse
(Also initiated from #Justin M. Keyes)

Coffeescript compilation fails for no apparent reason

When I try to compile this script (first.coffe):
some_object =
property_a : 123
property_b : "hello"
I get following error:
In first.coffee, Parse error on line 2: Unexpected 'INDENT'
but when I use "try coffeescript" functionality of coffeescript website, everything seems to work fine, because output is exactly this:
var some_object;
some_object = {
property_a: 123,
property_b: "hello"
};
What am I doing wrong? I work on Ubuntu, so coffescript was installed from repositories.
It might have something to do with your text editor. I know I've had trouble before with indent settings and line endings. Try opening it up in a different editor if you are using VIM.
Ubuntu 11.10 has an up-to-date CoffeeScript package. Older versions of Ubuntu may have a CoffeeScript package that is too old. If you are using an Ubuntu older than 11.10, uninstall that package and install a newer CoffeeScript.