Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some compiler errors are not highlighted in editor (vscode) #1628

Closed
Lexey40o opened this issue Aug 18, 2023 · 13 comments · Fixed by rust-lang/rust-analyzer#17561
Closed

Some compiler errors are not highlighted in editor (vscode) #1628

Lexey40o opened this issue Aug 18, 2023 · 13 comments · Fixed by rust-lang/rust-analyzer#17561

Comments

@Lexey40o
Copy link

rustc --version: rustc 1.71.1 (eb26296b5 2023-08-03)
rustlings --version: v5.5.1
OS: Microsoft Windows 10 Home 10.0.19045 Build 19045
rust-analyzer vscode plugin version: v0.4.1627
vscode version: 1.81.1

ls -la

total 29597
drwxrwxrwx 1 user user     512 Aug 17 22:16 .
drwxrwxrwx 1 user user     512 Jul 28 12:07 ..
-rwxrwxrwx 1 user user   59202 May 17 13:09 .all-contributorsrc
drwxrwxrwx 1 user user     512 May  2 12:35 .devcontainer
-rwxrwxrwx 1 user user     109 May  2 12:35 .editorconfig
drwxrwxrwx 1 user user     512 Aug 17 16:54 .git
drwxrwxrwx 1 user user     512 May  2 12:35 .github
-rwxrwxrwx 1 user user     224 May 17 13:09 .gitignore
-rwxrwxrwx 1 user user     169 May  2 12:35 .gitpod.yml
-rwxrwxrwx 1 user user      61 May 17 13:09 .markdownlint.yml
drwxrwxrwx 1 user user     512 May  2 12:35 .vscode
-rwxrwxrwx 1 user user   76274 May 17 13:09 AUTHORS.md
-rwxrwxrwx 1 user user   47175 May 17 13:09 CHANGELOG.md
-rwxrwxrwx 1 user user    4301 May  2 12:35 CONTRIBUTING.md
-rwxrwxrwx 1 user user   19047 May 17 13:09 Cargo.lock
-rwxrwxrwx 1 user user     616 May 17 13:09 Cargo.toml
-rwxrwxrwx 1 user user    1117 May  2 12:35 LICENSE
-rwxrwxrwx 1 user user    6720 May 17 13:09 README.md
drwxrwxrwx 1 user user     512 May  2 12:35 exercises
-rwxrwxrwx 1 user user    1572 May  2 12:35 flake.lock
-rwxrwxrwx 1 user user    2032 May 17 13:09 flake.nix
-rwxrwxrwx 1 user user   43455 May 17 13:09 info.toml
-rwxrwxrwx 1 user user    3116 May  2 12:35 install.ps1
-rwxrwxrwx 1 user user    4846 May  2 12:35 install.sh
-rwxrwxrwx 1 user user     212 May 17 13:09 oranda.json
-rwxrwxrwx 1 user user    9082 Aug 17 22:38 rust-project.json
-rwxrwxrwx 1 user user     284 May  2 12:35 shell.nix
drwxrwxrwx 1 user user     512 May 17 13:09 src
drwxrwxrwx 1 user user     512 Aug 17 22:17 target
-rwxrwxrwx 1 user user 1437696 May  2 12:59 temp_13664_ThreadId1.pdb
-rwxrwxrwx 1 user user 2715648 Jul 17 21:33 temp_14188_ThreadId1.pdb
-rwxrwxrwx 1 user user 2715648 Aug 17 21:39 temp_14824_ThreadId1.pdb
-rwxrwxrwx 1 user user 2715648 May 17 12:58 temp_16652_ThreadId1.pdb
-rwxrwxrwx 1 user user 2715648 Jul 17 21:22 temp_18980_ThreadId1.pdb
-rwxrwxrwx 1 user user 2699264 May  2 15:10 temp_19512_ThreadId1.pdb
-rwxrwxrwx 1 user user 2715648 Aug 17 21:53 temp_20004_ThreadId1.pdb
-rwxrwxrwx 1 user user 1437696 May  2 13:56 temp_20164_ThreadId1.pdb
-rwxrwxrwx 1 user user 2715648 Aug 17 16:48 temp_21876_ThreadId1.pdb
-rwxrwxrwx 1 user user 2715648 Jul 15 15:54 temp_24296_ThreadId1.pdb
-rwxrwxrwx 1 user user 2699264 May  3 19:07 temp_26588_ThreadId1.pdb
-rwxrwxrwx 1 user user 2715648 May 17 13:18 temp_3312_ThreadId1.pdb
drwxrwxrwx 1 user user     512 May  2 12:35 tests

When going through exercise enums3.rs, I noticed that certain errors won't be highlighted in the editor (vscode), but will be caught by rustlings run enums3. Here's a modified version of enums3.rs that contains errors which should be highlighted but are not.
An interesting bit is that if you delete not_an_inscope_variable, I do get error highlighting for the wrong number of arguments error (E0107).

I'm guessing this has to do with the relationship between the unique project structure of rustlings and the rust-analyzer plugin. I was not able to reproduce this problem inside a project with a normal structure, as the errors were appropriately highlighted inside the editor.

If this turns out to be a rust-analyzer problem, I'd be happy to open an issue there.

@mo8it
Copy link
Contributor

mo8it commented Jun 19, 2024

In the upcoming version 6, we use Cargo.toml instead of project.json, but this issue still exists. So it is a rust-analyzer issue.

@JaKXz

This comment was marked as resolved.

@mo8it

This comment was marked as resolved.

@JaKXz

This comment was marked as resolved.

@mo8it

This comment was marked as resolved.

@mo8it
Copy link
Contributor

mo8it commented Jul 7, 2024

@Veykril What is the best next step? Should I open an issue in the rust-analyzer repo or is there already one that I couldn't find?

This isn't specific to VS-Code. I can also reproduce it in Helix. Here is how to reproduce it in VS-Code:

cargo install rustlings
rustlings init
cd rustlings
code .

Almost all files should contain errors, but some errors aren't shown.

@Veykril

This comment was marked as resolved.

@Veykril
Copy link
Member

Veykril commented Jul 7, 2024

Ah you are talking about cargo check diagnostics I suppose

@Veykril
Copy link
Member

Veykril commented Jul 7, 2024

It seems cargo is not reporting all errors. r-a invokes cargo check --workspace --message-format=json-diagnostic-rendered-ansi --manifest-path Cargo.toml --all-targets which seems to exit out early before checking all crates, or the output at least does not contain all errors here. So this is a cargo bug.

@mo8it
Copy link
Contributor

mo8it commented Jul 7, 2024

image

Yes, cargo check errors and warnings are only shown in some of the exercises, not all.

This is how it is supposed to look like:

image

I got the second screenshot after saving the file for 2-3 times.
It seems like Rust-Analyzer stops at some point and which files show errors and warning is controlled by some race condition.

@mo8it
Copy link
Contributor

mo8it commented Jul 7, 2024

@Veykril The required Cargo option is --keep-going. Adding check.extraArgs = ["--keep-going"] fixed this issue. But this would be something that everyone has to configure in the editor.

Is it fine to add --keep-going to the check command here? I can open a PR.

This should be done depending on the available Rust version like this snippet because --keep-going was stabilized in 1.74.

@Veykril
Copy link
Member

Veykril commented Jul 7, 2024

Oh that is a good point. Yes we should unconditionally throw that into the FlycheckConfig::CargoCommand branch

bors added a commit to rust-lang/rust-analyzer that referenced this issue Jul 8, 2024
Add --keep-going to the check command

Fixes rust-lang/rustlings#1628

`@Veykril` I am not sure about what you meant with "unconditionally" in rust-lang/rustlings#1628 (comment), but I didn't find out how to get the version of the toolchain anyway to do a check like in [this snippet](https://github.com/rust-lang/rust-analyzer/blob/a5b21ea0aa644dffd7cf958b43f11f221d53404e/crates/project-model/src/build_scripts.rs#L125-L127). Is this check even required if rust-analyzer was installed with the toolchain?

`--keep-going` was [stabilized in 1.74](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-174-2023-11-16)
@mo8it
Copy link
Contributor

mo8it commented Jul 8, 2024

A fix has been merged into Rust-Analyzer :D

@mo8it mo8it closed this as completed Jul 8, 2024
lnicola pushed a commit to lnicola/rust that referenced this issue Jul 11, 2024
Add --keep-going to the check command

Fixes rust-lang/rustlings#1628

`@Veykril` I am not sure about what you meant with "unconditionally" in rust-lang/rustlings#1628 (comment), but I didn't find out how to get the version of the toolchain anyway to do a check like in [this snippet](https://github.com/rust-lang/rust-analyzer/blob/a5b21ea0aa644dffd7cf958b43f11f221d53404e/crates/project-model/src/build_scripts.rs#L125-L127). Is this check even required if rust-analyzer was installed with the toolchain?

`--keep-going` was [stabilized in 1.74](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-174-2023-11-16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants