@@ -670,6 +670,7 @@ object CheckUnused:
670
670
else
671
671
// If the rest of the line is blank, include it in the final edit position. (Delete trailing whitespace.)
672
672
// If for deletion, and the prefix of the line is also blank, then include that, too. (Del blank line.)
673
+ // If deleting a blank line and surrounded by blank lines, remove an adjoining blank line.
673
674
def editPosAt (srcPos : SrcPos , forDeletion : Boolean ): SrcPos =
674
675
val start = srcPos.span.start
675
676
val end = srcPos.span.end
@@ -682,7 +683,21 @@ object CheckUnused:
682
683
val bump = if (deleteLine) 1 else 0 // todo improve to include offset of next line, endline + 1
683
684
val p0 = srcPos.span
684
685
val p1 = if (next >= 0 && emptyRight) p0.withEnd(next + bump) else p0
685
- val p2 = if (deleteLine) p1.withStart(prev + 1 ) else p1
686
+ val p2 =
687
+ if deleteLine then
688
+ var newStart = prev + 1
689
+ if srcPos.line > 1 then
690
+ val source = srcPos.sourcePos.source
691
+ import source .{lineToOffset , lineToOffsetOpt , offsetToLine }
692
+ val startLine = offsetToLine(start)
693
+ val endLine = offsetToLine(end)
694
+ val preceding = lineToOffset(startLine - 1 )
695
+ lineToOffsetOpt(endLine + 2 ) match
696
+ case Some (succeeding) if lineToOffset(startLine) - preceding == 1 && succeeding - end == 2 =>
697
+ newStart = preceding
698
+ case _ =>
699
+ p1.withStart(newStart)
700
+ else p1
686
701
srcPos.sourcePos.withSpan(p2)
687
702
def actionsOf (actions : (SrcPos , String )* ): List [CodeAction ] =
688
703
val patches = actions.map((srcPos, replacement) => ActionPatch (srcPos.sourcePos, replacement)).toList
0 commit comments