Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 14 additions & 16 deletions cpp-linter/src/clang_tools/clang_tidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde::Deserialize;
// project-specific modules/crates
use super::MakeSuggestions;
use crate::{
cli::{ClangParams, LinesChangedOnly},
cli::ClangParams,
common_fs::{FileObj, normalize_path},
};

Expand Down Expand Up @@ -263,19 +263,17 @@ pub fn run_clang_tidy(
cmd.args(["--extra-arg", format!("\"{}\"", arg).as_str()]);
}
let file_name = file.name.to_string_lossy().to_string();
if clang_params.lines_changed_only != LinesChangedOnly::Off {
let ranges = file.get_ranges(&clang_params.lines_changed_only);
if !ranges.is_empty() {
let filter = format!(
"[{{\"name\":{:?},\"lines\":{:?}}}]",
&file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
ranges
.iter()
.map(|r| [r.start(), r.end()])
.collect::<Vec<_>>()
);
cmd.args(["--line-filter", filter.as_str()]);
}
let ranges = file.get_ranges(&clang_params.lines_changed_only);
if !ranges.is_empty() {
let filter = format!(
"[{{\"name\":{:?},\"lines\":{:?}}}]",
&file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
ranges
.iter()
.map(|r| [r.start(), r.end()])
.collect::<Vec<_>>()
);
cmd.args(["--line-filter", filter.as_str()]);
}
let original_content = if !clang_params.tidy_review {
None
Expand Down Expand Up @@ -429,7 +427,7 @@ mod test {
)
.unwrap();
let file = FileObj::new(PathBuf::from("tests/demo/demo.cpp"));
let arc_ref = Arc::new(Mutex::new(file));
let arc_file = Arc::new(Mutex::new(file));
let extra_args = vec!["-std=c++17".to_string(), "-Wall".to_string()];
let clang_params = ClangParams {
style: "".to_string(),
Expand All @@ -445,7 +443,7 @@ mod test {
clang_tidy_command: Some(exe_path),
clang_format_command: None,
};
let mut file_lock = arc_ref.lock().unwrap();
let mut file_lock = arc_file.lock().unwrap();
let logs = run_clang_tidy(&mut file_lock, &clang_params)
.unwrap()
.into_iter()
Expand Down
11 changes: 6 additions & 5 deletions cpp-linter/src/clang_tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn analyze_single_file(
}

/// A struct to contain the version numbers of the clang-tools used
#[derive(Default)]
#[derive(Debug, Default)]
pub struct ClangVersions {
/// The clang-format version used.
pub format_version: Option<String>,
Expand All @@ -199,9 +199,9 @@ pub struct ClangVersions {
/// If `tidy_checks` is `"-*"` then clang-tidy is not executed.
/// If `style` is a blank string (`""`), then clang-format is not executed.
pub async fn capture_clang_tools_output(
files: &mut Vec<Arc<Mutex<FileObj>>>,
files: &[Arc<Mutex<FileObj>>],
version: &RequestedVersion,
clang_params: &mut ClangParams,
mut clang_params: ClangParams,
rest_api_client: &impl RestApiClient,
) -> Result<ClangVersions> {
let mut clang_versions = ClangVersions::default();
Expand Down Expand Up @@ -240,10 +240,11 @@ pub async fn capture_clang_tools_output(
};

let mut executors = JoinSet::new();
let arc_params = Arc::new(clang_params);
// iterate over the discovered files and run the clang tools
for file in files {
let arc_params = Arc::new(clang_params.clone());
let arc_file = Arc::clone(file);
let arc_file = file.clone();
let arc_params = arc_params.clone();
executors.spawn(async move { analyze_single_file(arc_file, arc_params) });
}

Expand Down
4 changes: 2 additions & 2 deletions cpp-linter/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ pub async fn run_main(args: Vec<String>) -> Result<()> {
clang_params.tidy_review &= is_pr;
let user_inputs = FeedbackInput::from(&cli);
let clang_versions = capture_clang_tools_output(
&mut arc_files,
&arc_files,
&cli.general_options.version,
&mut clang_params,
clang_params,
&rest_api_client,
)
.await?;
Expand Down
Loading