@@ -119,6 +119,20 @@ impl FileObj {
119
119
None
120
120
}
121
121
122
+ /// Similar to [`FileObj::is_hunk_in_diff()`] but looks for a single line instead of
123
+ /// an entire [`DiffHunk`].
124
+ ///
125
+ /// This is a private function because it is only used in
126
+ /// [`FileObj::make_suggestions_from_patch()`].
127
+ fn is_line_in_diff ( & self , line : & u32 ) -> bool {
128
+ for range in & self . diff_chunks {
129
+ if range. contains ( line) {
130
+ return true ;
131
+ }
132
+ }
133
+ false
134
+ }
135
+
122
136
/// Create a list of [`Suggestion`](struct@crate::clang_tools::Suggestion) from a
123
137
/// generated [`Patch`](struct@git2::Patch) and store them in the given
124
138
/// [`ReviewComments`](struct@crate::clang_tools::ReviewComments).
@@ -161,10 +175,10 @@ impl FileObj {
161
175
// Count of clang-tidy diagnostics that had no fixes applied
162
176
let mut total = 0 ;
163
177
for note in & advice. notes {
164
- if note. fixed_lines . is_empty ( ) {
178
+ if note. fixed_lines . is_empty ( ) && self . is_line_in_diff ( & note . line ) {
165
179
// notification had no suggestion applied in `patched`
166
180
let mut suggestion = format ! (
167
- "### clang-tidy diagnostic\n **{file_name}:{}:{}** {}: [{}]\n > {}" ,
181
+ "### clang-tidy diagnostic\n **{file_name}:{}:{}** {}: [{}]\n \n > {}\n " ,
168
182
& note. line,
169
183
& note. cols,
170
184
& note. severity,
@@ -173,7 +187,8 @@ impl FileObj {
173
187
) ;
174
188
if !note. suggestion . is_empty ( ) {
175
189
suggestion. push_str (
176
- format ! ( "```{file_ext}\n {}```" , & note. suggestion. join( "\n " ) ) . as_str ( ) ,
190
+ format ! ( "\n ```{file_ext}\n {}\n ```\n " , & note. suggestion. join( "\n " ) )
191
+ . as_str ( ) ,
177
192
) ;
178
193
}
179
194
total += 1 ;
@@ -342,4 +357,10 @@ mod test {
342
357
let ranges = file_obj. get_ranges ( & LinesChangedOnly :: On ) ;
343
358
assert_eq ! ( ranges, vec![ 4 ..=5 , 9 ..=9 ] ) ;
344
359
}
360
+
361
+ #[ test]
362
+ fn line_not_in_diff ( ) {
363
+ let file_obj = FileObj :: new ( PathBuf :: from ( "tests/demo/demo.cpp" ) ) ;
364
+ assert ! ( !file_obj. is_line_in_diff( & 42 ) ) ;
365
+ }
345
366
}
0 commit comments