Skip to content

Commit 64bbad1

Browse files
committed
internal/lsp/debug: improve readability of session options
I find the session options page in gopls debug a bit hard to read. This change aims to improve readability by: - Sorting non-default options first (and alphabetically by name) - Use bold text for option name - Hide the "current value" if it's string representation equals the default value's string representation Change-Id: I93606ae788b97e46dc1d3aff420bb58f4c4d9674 Reviewed-on: https://go-review.googlesource.com/c/tools/+/352130 Trust: Pontus Leitzler <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent b182fde commit 64bbad1

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

internal/lsp/debug/info.go

+25-11
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,15 @@ func swalk(t reflect.Type, ix []int, indent string) {
183183
}
184184
}
185185

186-
func showOptions(o *source.Options) []string {
187-
// non-breaking spaces for indenting current and defaults when they are on a separate line
188-
const indent = "\u00a0\u00a0\u00a0\u00a0\u00a0"
189-
var ans strings.Builder
186+
type sessionOption struct {
187+
Name string
188+
Type string
189+
Current string
190+
Default string
191+
}
192+
193+
func showOptions(o *source.Options) []sessionOption {
194+
var out []sessionOption
190195
t := reflect.TypeOf(*o)
191196
swalk(t, []int{}, "")
192197
v := reflect.ValueOf(*o)
@@ -195,17 +200,26 @@ func showOptions(o *source.Options) []string {
195200
val := v.FieldByIndex(f.index)
196201
def := do.FieldByIndex(f.index)
197202
tx := t.FieldByIndex(f.index)
198-
prefix := fmt.Sprintf("%s (type is %s): ", tx.Name, tx.Type)
199203
is := strVal(val)
200204
was := strVal(def)
201-
if len(is) < 30 && len(was) < 30 {
202-
fmt.Fprintf(&ans, "%s current:%s, default:%s\n", prefix, is, was)
203-
} else {
204-
fmt.Fprintf(&ans, "%s\n%scurrent:%s\n%sdefault:%s\n", prefix, indent, is, indent, was)
205-
}
205+
out = append(out, sessionOption{
206+
Name: tx.Name,
207+
Type: tx.Type.String(),
208+
Current: is,
209+
Default: was,
210+
})
206211
}
207-
return strings.Split(ans.String(), "\n")
212+
sort.Slice(out, func(i, j int) bool {
213+
rd := out[i].Current == out[i].Default
214+
ld := out[j].Current == out[j].Default
215+
if rd != ld {
216+
return ld
217+
}
218+
return out[i].Name < out[j].Name
219+
})
220+
return out
208221
}
222+
209223
func strVal(val reflect.Value) string {
210224
switch val.Kind() {
211225
case reflect.Bool:

internal/lsp/debug/serve.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ Unknown page
791791
}
792792
return s
793793
},
794-
"options": func(s *cache.Session) []string {
794+
"options": func(s *cache.Session) []sessionOption {
795795
return showOptions(s.Options())
796796
},
797797
})
@@ -919,7 +919,11 @@ From: <b>{{template "cachelink" .Cache.ID}}</b><br>
919919
<h2>Overlays</h2>
920920
<ul>{{range .Overlays}}<li>{{template "filelink" .}}</li>{{end}}</ul>
921921
<h2>Options</h2>
922-
{{range options .}}<p>{{.}}{{end}}
922+
{{range options .}}
923+
<p><b>{{.Name}}</b> {{.Type}}</p>
924+
<p><i>default:</i> {{.Default}}</p>
925+
{{if ne .Default .Current}}<p><i>current:</i> {{.Current}}</p>{{end}}
926+
{{end}}
923927
{{end}}
924928
`))
925929

0 commit comments

Comments
 (0)