Skip to content

Commit 54cf5bc

Browse files
findleyrgopherbot
authored andcommitted
internal/debug: show new View information in the debug page
Add View Type, EnvOverlay, and Root to the view debug page. Also inline the View debug page into the Session debug page, to save a click. For golang/go#57979 Change-Id: Id6fbf86a55329078adcada049e34607ee918da11 Reviewed-on: https://go-review.googlesource.com/c/tools/+/555197 Auto-Submit: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent b37fde9 commit 54cf5bc

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

gopls/internal/debug/serve.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ func (i *Instance) Serve(ctx context.Context, addr string) (string, error) {
462462
mux.HandleFunc("/analysis/", render(AnalysisTmpl, i.getAnalysis))
463463
mux.HandleFunc("/cache/", render(CacheTmpl, i.getCache))
464464
mux.HandleFunc("/session/", render(SessionTmpl, i.getSession))
465-
mux.HandleFunc("/view/", render(ViewTmpl, i.getView))
466465
mux.HandleFunc("/client/", render(ClientTmpl, i.getClient))
467466
mux.HandleFunc("/server/", render(ServerTmpl, i.getServer))
468467
mux.HandleFunc("/file/", render(FileTmpl, i.getFile))
@@ -644,12 +643,17 @@ var BaseTemplate = template.Must(template.New("").Parse(`
644643
width:6rem;
645644
}
646645
td.value {
647-
text-align: right;
646+
text-align: right;
648647
}
649648
ul.spans {
650649
font-family: monospace;
651650
font-size: 85%;
652651
}
652+
body {
653+
font-family: sans-serif;
654+
font-size: 1rem;
655+
line-height: normal;
656+
}
653657
</style>
654658
{{block "head" .}}{{end}}
655659
</head>
@@ -674,7 +678,6 @@ Unknown page
674678
{{define "clientlink"}}<a href="/client/{{.}}">Client {{.}}</a>{{end}}
675679
{{define "serverlink"}}<a href="/server/{{.}}">Server {{.}}</a>{{end}}
676680
{{define "sessionlink"}}<a href="/session/{{.}}">Session {{.}}</a>{{end}}
677-
{{define "viewlink"}}<a href="/view/{{.}}">View {{.}}</a>{{end}}
678681
`)).Funcs(template.FuncMap{
679682
"fuint64": fuint64,
680683
"fuint32": fuint32,
@@ -706,7 +709,7 @@ Unknown page
706709
})
707710

708711
var MainTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
709-
{{define "title"}}GoPls server information{{end}}
712+
{{define "title"}}Gopls server information{{end}}
710713
{{define "body"}}
711714
<h2>Caches</h2>
712715
<ul>{{range .State.Caches}}<li>{{template "cachelink" .ID}}</li>{{end}}</ul>
@@ -722,7 +725,7 @@ var MainTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
722725
`))
723726

724727
var InfoTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
725-
{{define "title"}}GoPls version information{{end}}
728+
{{define "title"}}Gopls version information{{end}}
726729
{{define "body"}}
727730
{{.}}
728731
{{end}}
@@ -771,6 +774,13 @@ var CacheTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
771774
{{define "body"}}
772775
<h2>memoize.Store entries</h2>
773776
<ul>{{range $k,$v := .MemStats}}<li>{{$k}} - {{$v}}</li>{{end}}</ul>
777+
<h2>File stats</h2>
778+
<p>
779+
{{- $stats := .FileStats -}}
780+
Total: <b>{{$stats.Total}}</b><br>
781+
Largest: <b>{{$stats.Largest}}</b><br>
782+
Errors: <b>{{$stats.Errs}}</b><br>
783+
</p>
774784
{{end}}
775785
`))
776786

@@ -806,7 +816,16 @@ var SessionTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
806816
{{define "body"}}
807817
From: <b>{{template "cachelink" .Cache.ID}}</b><br>
808818
<h2>Views</h2>
809-
<ul>{{range .Views}}<li>{{.Folder.Name}} is {{template "viewlink" .ID}} in {{.Folder.Dir}}</li>{{end}}</ul>
819+
<ul>{{range .Views}}
820+
{{- $envOverlay := .EnvOverlay -}}
821+
<li>ID: <b>{{.ID}}</b><br>
822+
Type: <b>{{.Type}}</b><br>
823+
Root: <b>{{.Root}}</b><br>
824+
{{- if $envOverlay}}
825+
Env overlay: <b>{{$envOverlay}})</b><br>
826+
{{end -}}
827+
Folder: <b>{{.Folder.Name}}:{{.Folder.Dir}}</b></li>
828+
{{end}}</ul>
810829
<h2>Overlays</h2>
811830
{{$session := .}}
812831
<ul>{{range .Overlays}}
@@ -816,14 +835,6 @@ From: <b>{{template "cachelink" .Cache.ID}}</b><br>
816835
{{end}}
817836
`))
818837

819-
var ViewTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
820-
{{define "title"}}View {{.ID}}{{end}}
821-
{{define "body"}}
822-
Name: <b>{{.Folder.Name}}</b><br>
823-
Folder: <b>{{.Folder.Dir}}</b><br>
824-
{{end}}
825-
`))
826-
827838
var FileTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(`
828839
{{define "title"}}Overlay {{.Identity.Hash}}{{end}}
829840
{{define "body"}}

gopls/internal/debug/template_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ var templates = map[string]struct {
3636
"TraceTmpl": {debug.TraceTmpl, debug.TraceResults{}},
3737
"CacheTmpl": {debug.CacheTmpl, &cache.Cache{}},
3838
"SessionTmpl": {debug.SessionTmpl, &cache.Session{}},
39-
"ViewTmpl": {debug.ViewTmpl, &cache.View{}},
4039
"ClientTmpl": {debug.ClientTmpl, &debug.Client{}},
4140
"ServerTmpl": {debug.ServerTmpl, &debug.Server{}},
4241
"FileTmpl": {debug.FileTmpl, &cache.Overlay{}},

gopls/internal/lsp/cache/cache.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sync/atomic"
1212
"time"
1313

14+
"golang.org/x/tools/gopls/internal/lsp/command"
1415
"golang.org/x/tools/gopls/internal/lsp/protocol"
1516
"golang.org/x/tools/internal/event"
1617
"golang.org/x/tools/internal/gocommand"
@@ -76,6 +77,7 @@ func (c *Cache) MemStats() map[reflect.Type]int { return c.store.Stats() }
7677

7778
// FileStats returns information about the set of files stored in the cache.
7879
// It is intended for debugging only.
79-
func (c *Cache) FileStats() (files, largest, errs int) {
80-
return c.fileStats()
80+
func (c *Cache) FileStats() (stats command.FileStats) {
81+
stats.Total, stats.Largest, stats.Errs = c.fileStats()
82+
return
8183
}

gopls/internal/server/command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ func (c *commandHandler) MemStats(ctx context.Context) (command.MemStatsResult,
10521052
// about the current state of the loaded workspace for the current session.
10531053
func (c *commandHandler) WorkspaceStats(ctx context.Context) (command.WorkspaceStatsResult, error) {
10541054
var res command.WorkspaceStatsResult
1055-
res.Files.Total, res.Files.Largest, res.Files.Errs = c.s.session.Cache().FileStats()
1055+
res.Files = c.s.session.Cache().FileStats()
10561056

10571057
for _, view := range c.s.session.Views() {
10581058
vs, err := collectViewStats(ctx, view)

gopls/internal/test/integration/debug/debug_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestStartDebugging(t *testing.T) {
6565
if err != nil {
6666
t.Fatalf("reading HTTP response body: %v", err)
6767
}
68-
const want = "<title>GoPls"
68+
const want = "<title>Gopls"
6969
if !strings.Contains(string(data), want) {
7070
t.Errorf("GET %s response does not contain %q: <<%s>>", debugURL, want, data)
7171
}

0 commit comments

Comments
 (0)