File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -741,7 +741,30 @@ export class ReviewManager {
741741 break ;
742742 }
743743 }
744- hunk . diffLines = hunk . diffLines . slice ( i , j + 1 ) ;
744+
745+ let slice = hunk . diffLines . slice ( i , j + 1 ) ;
746+
747+ if ( slice . every ( line => line . type === DiffChangeType . Add ) ) {
748+ // we have only inserted lines, so we need to include a context line so that
749+ // there's a line to anchor the suggestion to
750+ if ( i > 1 ) {
751+ // include from the begginning of the hunk
752+ i -- ;
753+ oldLineNumber -- ;
754+ oldLength ++ ;
755+ } else if ( j < hunk . diffLines . length - 1 ) {
756+ // include from the end of the hunk
757+ j ++ ;
758+ oldLength ++ ;
759+ } else {
760+ // include entire context
761+ i = 1 ;
762+ j = hunk . diffLines . length - 1 ;
763+ }
764+ slice = hunk . diffLines . slice ( i , j + 1 ) ;
765+ }
766+
767+ hunk . diffLines = slice ;
745768 hunk . oldLength = oldLength ;
746769 hunk . oldLineNumber = oldLineNumber ;
747770 }
You can’t perform that action at this time.
0 commit comments