Skip to content

Commit d1b82a0

Browse files
committed
Merge branch 'main' into release
2 parents 5c9e003 + 6bb3cc0 commit d1b82a0

File tree

6 files changed

+87
-27
lines changed

6 files changed

+87
-27
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ JSON file to see where the automatically copied portion appears.
3030

3131
If you update the config! settings in `crates/rust-analyzer/src/config.rs`, you
3232
need to run:
33-
`cargo test -p rust-analyzer generate_package_json_config generate_config_documentation`
33+
```
34+
cargo test -p rust-analyzer generate_package_json_config
35+
cargo test -p rust-analyzer generate_config_documentation
36+
```
3437
to update the `package.json` file and the documentation (which we don't currently publish).
3538

3639

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ where the quoted string is a list of space-separated Verus arguments, e.g., `ext
8787

8888
#### Using `cargo verus`
8989

90-
By default, `verus-analyzer` direclyt invokes the Verus executable on the root of your crate. If you would
90+
By default, `verus-analyzer` directly invokes the Verus executable on the root of your crate. If you would
9191
instead prefer to have it invoke `cargo verus`, toggle the setting: "Verus-analyzer › Cargo: Verus Enable".
9292

9393
#### Advanced Verus Developments

crates/flycheck/src/lib.rs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub enum FlycheckConfig {
9797
verus_args: Vec<String>,
9898
cargo_verus_enable: bool,
9999
cargo_options: CargoOptions,
100+
report_all_errors: bool,
100101
},
101102
}
102103

@@ -107,8 +108,8 @@ impl fmt::Display for FlycheckConfig {
107108
FlycheckConfig::CustomCommand { command, args, .. } => {
108109
write!(f, "{command} {}", args.join(" "))
109110
}
110-
FlycheckConfig::VerusCommand { verus_args, cargo_verus_enable, cargo_options } => {
111-
write!(f, "verus {} (cargo_verus enabled: {}, cargo_verus options {:?})", verus_args.join(" "), cargo_verus_enable, cargo_options)
111+
FlycheckConfig::VerusCommand { verus_args, cargo_verus_enable, cargo_options, report_all_errors } => {
112+
write!(f, "verus {} (cargo_verus enabled: {}, cargo_verus options {:?}, report all errors: {})", verus_args.join(" "), cargo_verus_enable, cargo_options, report_all_errors)
112113
}
113114
}
114115
}
@@ -546,7 +547,7 @@ impl FlycheckActor {
546547
}
547548

548549
// copied from above check_command
549-
fn run_cargo_verus(&self, file: String, verus_args: &Vec<String>, cargo_options: &CargoOptions) -> Command {
550+
fn run_cargo_verus(&self, file: String, verus_args: &Vec<String>, cargo_options: &CargoOptions, report_all_errors: bool) -> Command {
550551
// Find the `cargo-verus` binary
551552
let verus_binary_str = match std::env::var("VERUS_BINARY_PATH") {
552553
Ok(path) => path,
@@ -627,21 +628,27 @@ impl FlycheckActor {
627628
module_args.push("--verify-root".to_string());
628629
}
629630

631+
// Cargo command
630632
cmd.arg("verify".to_string());
633+
// Provide the cargo arguments
631634
cmd.arg("--message-format=json".to_string());
632635
cargo_options.apply_on_command(&mut cmd);
636+
cmd.args(&cargo_options.extra_args);
637+
// Provide the Verus arguments
633638
cmd.arg("--".to_string());
634639
cmd.args(verus_args);
635640
cmd.args(extra_args_from_toml);
636-
cmd.args(module_args);
641+
if !report_all_errors {
642+
cmd.args(module_args);
643+
}
637644

638645
cmd.current_dir(&self.root);
639646
dbg!(&self.root);
640647
cmd
641648
}
642649

643650
// copied from above check_command
644-
fn run_verus_direct(&self, file: String, verus_args: &Vec<String>) -> Command {
651+
fn run_verus_direct(&self, file: String, verus_args: &Vec<String>, report_all_errors: bool) -> Command {
645652
let verus_binary_str = match std::env::var("VERUS_BINARY_PATH") {
646653
Ok(path) => path,
647654
Err(_) => {
@@ -696,15 +703,16 @@ impl FlycheckActor {
696703
}
697704
}
698705

699-
// We may need to add additional arguments
700-
let mut args = verus_args.to_vec();
706+
// We may need to add additional configuration arguments
707+
let mut config_args = vec![]; // File name and crate type
708+
let mut module_args = vec![]; // Arguments to restrict verification to the file currently being edited
701709
match toml_dir {
702710
None => {
703711
// This file doesn't appear to be part of a larger project
704712
// Try to invoke Verus on it directly, but try to avoid
705713
// complaints about missing `fn main()`
706-
args.push("--crate-type".to_string());
707-
args.push("lib".to_string());
714+
config_args.push("--crate-type".to_string());
715+
config_args.push("lib".to_string());
708716
}
709717
Some(toml_dir) => {
710718
// This file appears to be part of a Rust project.
@@ -713,8 +721,8 @@ impl FlycheckActor {
713721
let root_file = if toml_dir.join("src").join("main.rs").exists() {
714722
Some(toml_dir.join("src").join("main.rs"))
715723
} else if toml_dir.join("src").join("lib.rs").exists() {
716-
args.push("--crate-type".to_string());
717-
args.push("lib".to_string());
724+
config_args.push("--crate-type".to_string());
725+
config_args.push("lib".to_string());
718726
Some(toml_dir.join("src").join("lib.rs"))
719727
} else {
720728
None
@@ -735,32 +743,39 @@ impl FlycheckActor {
735743
.trim_end_matches("::mod")
736744
.to_string();
737745

738-
args.insert(0, root_file.to_str().unwrap().to_string());
746+
config_args.insert(0, root_file.to_str().unwrap().to_string());
739747
if file == root_file {
740748
tracing::info!("file == root_file");
741749
} else {
742750
tracing::info!(?root_file, "root_file");
743-
args.insert(1, "--verify-module".to_string());
744-
args.insert(2, file_as_module);
751+
module_args.push("--verify-module".to_string());
752+
module_args.push(file_as_module);
745753
}
746754
}
747755
None => {
748756
// Puzzling -- we found a Cargo.toml but no root file.
749757
// Do our best by trying to run directly on the file supplied
750-
args.insert(0, file.to_str().unwrap().to_string());
751-
args.push("--crate-type".to_string());
752-
args.push("lib".to_string());
758+
config_args.insert(0, file.to_str().unwrap().to_string());
759+
config_args.push("--crate-type".to_string());
760+
config_args.push("lib".to_string());
753761
}
754762
}
755763
}
756764
}
765+
766+
// Apply all of the argument collections
767+
cmd.args(verus_args);
768+
cmd.args(config_args);
769+
cmd.args(extra_args_from_toml);
770+
if !report_all_errors {
771+
cmd.args(module_args);
772+
}
757773

758-
args.append(&mut extra_args_from_toml);
759-
args.push("--".to_string());
760-
args.push("--error-format=json".to_string());
774+
// Apply arguments that go to rustc instead of Verus
775+
cmd.arg("--".to_string());
776+
cmd.arg("--error-format=json".to_string());
761777

762778
cmd.current_dir(&self.root);
763-
cmd.args(args);
764779
cmd
765780
}
766781

@@ -772,11 +787,11 @@ impl FlycheckActor {
772787
FlycheckConfig::CustomCommand { .. } => {
773788
panic!("verus analyzer does not yet support custom commands")
774789
}
775-
FlycheckConfig::VerusCommand { verus_args, cargo_verus_enable, cargo_options } => {
790+
FlycheckConfig::VerusCommand { verus_args, cargo_verus_enable, cargo_options, report_all_errors } => {
776791
if *cargo_verus_enable {
777-
self.run_cargo_verus(file, verus_args, cargo_options)
792+
self.run_cargo_verus(file, verus_args, cargo_options, *report_all_errors)
778793
} else {
779-
self.run_verus_direct(file, verus_args)
794+
self.run_verus_direct(file, verus_args, *report_all_errors)
780795
}
781796
}
782797
};

crates/rust-analyzer/src/config.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ config_data! {
171171
cargo_targetDir | rust_analyzerTargetDir: Option<TargetDirectory> = None,
172172
/// Run `cargo verus` instead of running the `verus` binary directly.
173173
cargo_verusEnable: bool = false,
174+
/// Extra Verus arguments passed to each invocation of `verus` performed either via Cargo or directly.
175+
verus_extraArgs: Vec<String> = vec![],
176+
/// Setting this to true causes verus-analyzer to report errors in all files, not just the one you are editing.
177+
verus_reportAllErrorsEnable: bool = false,
174178

175179
/// Run the check command for diagnostics on save.
176180
checkOnSave | checkOnSave_enable: bool = true,
@@ -1941,7 +1945,12 @@ impl Config {
19411945
},
19421946
}
19431947
}
1944-
Some(_) | None => FlycheckConfig::VerusCommand { verus_args: self.check_extra_args(), cargo_verus_enable: *self.cargo_verusEnable(), cargo_options: self.cargo_test_options() },
1948+
Some(_) | None => FlycheckConfig::VerusCommand {
1949+
verus_args: self.verus_extraArgs().clone(),
1950+
cargo_verus_enable: *self.cargo_verusEnable(),
1951+
cargo_options: self.cargo_test_options(),
1952+
report_all_errors: *self.verus_reportAllErrorsEnable(),
1953+
},
19451954
}
19461955
}
19471956

docs/user/generated_config.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,16 @@ Show documentation.
995995
--
996996
Whether to insert closing angle brackets when typing an opening angle bracket of a generic argument list.
997997
--
998+
[[rust-analyzer.verus.extraArgs]]rust-analyzer.verus.extraArgs (default: `[]`)::
999+
+
1000+
--
1001+
Extra Verus arguments passed to each invocation of `verus` performed either via Cargo or directly.
1002+
--
1003+
[[rust-analyzer.verus.reportAllErrorsEnable]]rust-analyzer.verus.reportAllErrorsEnable (default: `false`)::
1004+
+
1005+
--
1006+
Setting this to true causes verus-analyzer to report errors in all files, not just the one you are editing.
1007+
--
9981008
[[rust-analyzer.workspace.symbol.search.kind]]rust-analyzer.workspace.symbol.search.kind (default: `"only_types"`)::
9991009
+
10001010
--

editors/code/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,29 @@
25682568
}
25692569
}
25702570
},
2571+
{
2572+
"title": "verus",
2573+
"properties": {
2574+
"verus-analyzer.verus.extraArgs": {
2575+
"markdownDescription": "Extra Verus arguments passed to each invocation of `verus` performed either via Cargo or directly.",
2576+
"default": [],
2577+
"type": "array",
2578+
"items": {
2579+
"type": "string"
2580+
}
2581+
}
2582+
}
2583+
},
2584+
{
2585+
"title": "verus",
2586+
"properties": {
2587+
"verus-analyzer.verus.reportAllErrorsEnable": {
2588+
"markdownDescription": "Setting this to true causes verus-analyzer to report errors in all files, not just the one you are editing.",
2589+
"default": false,
2590+
"type": "boolean"
2591+
}
2592+
}
2593+
},
25712594
{
25722595
"title": "workspace",
25732596
"properties": {

0 commit comments

Comments
 (0)