@@ -25,6 +25,7 @@ import (
2525 "strings"
2626 "unicode"
2727
28+ "github.com/bufbuild/protocompile/internal/ext/cmpx"
2829 "github.com/bufbuild/protocompile/internal/ext/iterx"
2930 "github.com/bufbuild/protocompile/internal/ext/slicesx"
3031 "github.com/bufbuild/protocompile/internal/ext/stringsx"
@@ -308,8 +309,7 @@ type window struct {
308309 // The byte offset range this window's text occupies in the containing
309310 // source File.
310311 offsets [2 ]int
311- // A list of all underline elements in this window. Must be sorted
312- // according to cmpUnderlines.
312+ // A list of all underline elements in this window.
313313 underlines []underline
314314 multilines []multiline
315315}
@@ -347,8 +347,7 @@ func buildWindow(level Level, locations [][2]Location, snippets []snippet) *wind
347347 end : locations [i ][1 ].Line ,
348348 startWidth : locations [i ][0 ].Column ,
349349 endWidth : locations [i ][1 ].Column ,
350- level : noteLevel ,
351- message : snippet .message ,
350+ level : noteLevel , message : snippet .message ,
352351 })
353352 ml := & w .multilines [len (w .multilines )- 1 ]
354353
@@ -409,8 +408,16 @@ func buildWindow(level Level, locations [][2]Location, snippets []snippet) *wind
409408 }
410409 }
411410
412- slices .SortFunc (w .underlines , cmpUnderlines )
413- slices .SortFunc (w .multilines , cmpMultilines )
411+ slices .SortFunc (w .underlines , cmpx .Join (
412+ cmpx .Key (func (u underline ) int { return u .line }),
413+ cmpx .Key (func (u underline ) Level { return u .level }),
414+ cmpx .Key (func (u underline ) int { return u .Len () }),
415+ cmpx .Key (func (u underline ) int { return u .start }),
416+ ))
417+ slices .SortFunc (w .multilines , cmpx .Join (
418+ cmpx .Key (func (m multiline ) int { return m .start }),
419+ cmpx .Key (func (m multiline ) int { return m .end }),
420+ ))
414421 return w
415422}
416423
@@ -844,37 +851,13 @@ func (u underline) Len() int {
844851 return u .end - u .start
845852}
846853
847- // cmpUnderliens sorts ascending on line, then level, then length, then
848- // start column.
849- func cmpUnderlines (a , b underline ) int {
850- if diff := a .line - b .line ; diff != 0 {
851- return diff
852- }
853- if diff := a .level - b .level ; diff != 0 {
854- return int (diff )
855- }
856- if diff := a .Len () - b .Len (); diff != 0 {
857- return diff
858- }
859- return a .start - b .start
860- }
861-
862854type multiline struct {
863855 start , end int
864856 startWidth , endWidth int
865857 level Level
866858 message string
867859}
868860
869- // cmpMultilines sorts ascending on line, then descending on end. This sort
870- // order is intended to promote visual nesting of multis from left to right.
871- func cmpMultilines (a , b multiline ) int {
872- if diff := a .start - b .start ; diff != 0 {
873- return diff
874- }
875- return b .end - a .end
876- }
877-
878861func (r * renderer ) sidebar (bars , lineno , slashAt int , multis []* multiline ) string {
879862 var sidebar strings.Builder
880863 for i , ml := range multis {
0 commit comments