@@ -25,6 +25,7 @@ import (
25
25
"strings"
26
26
"unicode"
27
27
28
+ "github.com/bufbuild/protocompile/internal/ext/cmpx"
28
29
"github.com/bufbuild/protocompile/internal/ext/iterx"
29
30
"github.com/bufbuild/protocompile/internal/ext/slicesx"
30
31
"github.com/bufbuild/protocompile/internal/ext/stringsx"
@@ -308,8 +309,7 @@ type window struct {
308
309
// The byte offset range this window's text occupies in the containing
309
310
// source File.
310
311
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.
313
313
underlines []underline
314
314
multilines []multiline
315
315
}
@@ -347,8 +347,7 @@ func buildWindow(level Level, locations [][2]Location, snippets []snippet) *wind
347
347
end : locations [i ][1 ].Line ,
348
348
startWidth : locations [i ][0 ].Column ,
349
349
endWidth : locations [i ][1 ].Column ,
350
- level : noteLevel ,
351
- message : snippet .message ,
350
+ level : noteLevel , message : snippet .message ,
352
351
})
353
352
ml := & w .multilines [len (w .multilines )- 1 ]
354
353
@@ -409,8 +408,16 @@ func buildWindow(level Level, locations [][2]Location, snippets []snippet) *wind
409
408
}
410
409
}
411
410
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
+ ))
414
421
return w
415
422
}
416
423
@@ -844,37 +851,13 @@ func (u underline) Len() int {
844
851
return u .end - u .start
845
852
}
846
853
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
-
862
854
type multiline struct {
863
855
start , end int
864
856
startWidth , endWidth int
865
857
level Level
866
858
message string
867
859
}
868
860
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
-
878
861
func (r * renderer ) sidebar (bars , lineno , slashAt int , multis []* multiline ) string {
879
862
var sidebar strings.Builder
880
863
for i , ml := range multis {
0 commit comments