Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

filter before add --error-format #1471

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions rls/src/build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ impl Executor for RlsExecutor {
_on_stderr_line: &mut dyn FnMut(&str) -> CargoResult<()>,
) -> CargoResult<()> {
// Use JSON output so that we can parse the rustc output.
// Filter first to work around "--error-format" being passed with
// CARGO_PIPELINING(?) enabled in Cargo.
let filtered_args = filter_arg(cargo_cmd.get_args(), "--error-format");
cargo_cmd.args_replace(&filtered_args);
cargo_cmd.arg("--error-format=json");
// Delete any stale data. We try and remove any json files with
// the same crate name as Cargo would emit. This includes files
Expand Down Expand Up @@ -753,6 +757,18 @@ fn dedup_flags(flag_str: &str) -> String {
result
}

fn filter_arg(args: &[OsString], key: &str) -> Vec<String> {
let key_as_prefix = key.to_owned() + "=";
args.iter()
.zip(vec!["".into()].iter().chain(args.iter()))
.filter_map(|(x, prev)| {
x.to_str()
.filter(|x| !x.starts_with(&key_as_prefix) && prev != key)
.map(|x| x.to_string())
})
.collect()
}

/// Error wrapper that tries to figure out which manifest the cause best relates to in the project
#[derive(Debug)]
pub struct ManifestAwareError {
Expand Down