Skip to content

Commit

Permalink
params: map sort keys
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Oct 12, 2023
1 parent 7041a1b commit faaef51
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion gopls/goxls/lsview/lsview.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"log"
"os"
"reflect"
"sort"
"time"

"golang.org/x/tools/internal/fakenet"
Expand Down Expand Up @@ -157,7 +158,9 @@ func paramsFmt(ret any, prefix string) []byte {
var b bytes.Buffer
switch val := ret.(type) {
case mapt:
for k, v := range val {
keys := keys(val)
for _, k := range keys {
v := val[k]
if isComplex(v) {
fmt.Fprintf(&b, "%s%s:\n%s", prefix, k, paramsFmt(v, prefix+indent))
} else {
Expand Down Expand Up @@ -194,6 +197,15 @@ func isComplex(v any) bool {
return ok
}

func keys(v mapt) []string {
ret := make([]string, 0, len(v))
for key := range v {
ret = append(ret, key)
}
sort.Strings(ret)
return ret
}

func check(err error) {
if err != nil {
log.Panicln(err)
Expand Down

0 comments on commit faaef51

Please sign in to comment.