chore(cli): apply clippy fixes
This commit is contained in:
parent
1fb16a72ac
commit
04ff704bca
49 changed files with 1094 additions and 1277 deletions
|
|
@ -9,8 +9,9 @@ use std::{
|
|||
};
|
||||
use tree_sitter::{Language, Parser, Point, Query, QueryCursor};
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn query_files_at_paths(
|
||||
language: Language,
|
||||
language: &Language,
|
||||
paths: Vec<String>,
|
||||
query_path: &Path,
|
||||
ordered_captures: bool,
|
||||
|
|
@ -24,8 +25,8 @@ pub fn query_files_at_paths(
|
|||
let mut stdout = stdout.lock();
|
||||
|
||||
let query_source = fs::read_to_string(query_path)
|
||||
.with_context(|| format!("Error reading query file {:?}", query_path))?;
|
||||
let query = Query::new(&language, &query_source).with_context(|| "Query compilation failed")?;
|
||||
.with_context(|| format!("Error reading query file {query_path:?}"))?;
|
||||
let query = Query::new(language, &query_source).with_context(|| "Query compilation failed")?;
|
||||
|
||||
let mut query_cursor = QueryCursor::new();
|
||||
if let Some(range) = byte_range {
|
||||
|
|
@ -36,15 +37,15 @@ pub fn query_files_at_paths(
|
|||
}
|
||||
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(&language)?;
|
||||
parser.set_language(language)?;
|
||||
|
||||
for path in paths {
|
||||
let mut results = Vec::new();
|
||||
|
||||
writeln!(&mut stdout, "{}", path)?;
|
||||
writeln!(&mut stdout, "{path}")?;
|
||||
|
||||
let source_code =
|
||||
fs::read(&path).with_context(|| format!("Error reading source file {:?}", path))?;
|
||||
fs::read(&path).with_context(|| format!("Error reading source file {path:?}"))?;
|
||||
let tree = parser.parse(&source_code, None).unwrap();
|
||||
|
||||
let start = Instant::now();
|
||||
|
|
@ -57,17 +58,16 @@ pub fn query_files_at_paths(
|
|||
if !quiet {
|
||||
writeln!(
|
||||
&mut stdout,
|
||||
" pattern: {:>2}, capture: {} - {}, start: {}, end: {}, text: `{}`",
|
||||
" pattern: {:>2}, capture: {} - {capture_name}, start: {}, end: {}, text: `{}`",
|
||||
mat.pattern_index,
|
||||
capture.index,
|
||||
capture_name,
|
||||
capture.node.start_position(),
|
||||
capture.node.end_position(),
|
||||
capture.node.utf8_text(&source_code).unwrap_or("")
|
||||
)?;
|
||||
}
|
||||
results.push(query_testing::CaptureInfo {
|
||||
name: capture_name.to_string(),
|
||||
name: (*capture_name).to_string(),
|
||||
start: capture.node.start_position(),
|
||||
end: capture.node.end_position(),
|
||||
});
|
||||
|
|
@ -85,23 +85,19 @@ pub fn query_files_at_paths(
|
|||
if end.row == start.row {
|
||||
writeln!(
|
||||
&mut stdout,
|
||||
" capture: {} - {}, start: {}, end: {}, text: `{}`",
|
||||
" capture: {} - {capture_name}, start: {start}, end: {end}, text: `{}`",
|
||||
capture.index,
|
||||
capture_name,
|
||||
start,
|
||||
end,
|
||||
capture.node.utf8_text(&source_code).unwrap_or("")
|
||||
)?;
|
||||
} else {
|
||||
writeln!(
|
||||
&mut stdout,
|
||||
" capture: {}, start: {}, end: {}",
|
||||
capture_name, start, end,
|
||||
" capture: {capture_name}, start: {start}, end: {end}",
|
||||
)?;
|
||||
}
|
||||
}
|
||||
results.push(query_testing::CaptureInfo {
|
||||
name: capture_name.to_string(),
|
||||
name: (*capture_name).to_string(),
|
||||
start: capture.node.start_position(),
|
||||
end: capture.node.end_position(),
|
||||
});
|
||||
|
|
@ -115,7 +111,7 @@ pub fn query_files_at_paths(
|
|||
)?;
|
||||
}
|
||||
if should_test {
|
||||
query_testing::assert_expected_captures(results, path, &mut parser, language.clone())?
|
||||
query_testing::assert_expected_captures(&results, path, &mut parser, language)?;
|
||||
}
|
||||
if print_time {
|
||||
writeln!(&mut stdout, "{:?}", start.elapsed())?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue