@@ -119,6 +119,20 @@ impl FileObj {
119119 None
120120 }
121121
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+
122136 /// Create a list of [`Suggestion`](struct@crate::clang_tools::Suggestion) from a
123137 /// generated [`Patch`](struct@git2::Patch) and store them in the given
124138 /// [`ReviewComments`](struct@crate::clang_tools::ReviewComments).
@@ -161,10 +175,10 @@ impl FileObj {
161175 // Count of clang-tidy diagnostics that had no fixes applied
162176 let mut total = 0 ;
163177 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 ) {
165179 // notification had no suggestion applied in `patched`
166180 let mut suggestion = format ! (
167- "### clang-tidy diagnostic\n **{file_name}:{}:{}** {}: [{}]\n > {}" ,
181+ "### clang-tidy diagnostic\n **{file_name}:{}:{}** {}: [{}]\n \n > {}\n " ,
168182 & note. line,
169183 & note. cols,
170184 & note. severity,
@@ -173,7 +187,8 @@ impl FileObj {
173187 ) ;
174188 if !note. suggestion . is_empty ( ) {
175189 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 ( ) ,
177192 ) ;
178193 }
179194 total += 1 ;
@@ -342,4 +357,10 @@ mod test {
342357 let ranges = file_obj. get_ranges ( & LinesChangedOnly :: On ) ;
343358 assert_eq ! ( ranges, vec![ 4 ..=5 , 9 ..=9 ] ) ;
344359 }
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+ }
345366}
0 commit comments