From 54cf5bc0ae34ea99aa1be17ba30e82f7b028c86d Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Wed, 10 Jan 2024 16:00:35 -0500 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Alan Donovan --- gopls/internal/debug/serve.go | 39 ++++++++++++------- gopls/internal/debug/template_test.go | 1 - gopls/internal/lsp/cache/cache.go | 6 ++- gopls/internal/server/command.go | 2 +- .../test/integration/debug/debug_test.go | 2 +- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/gopls/internal/debug/serve.go b/gopls/internal/debug/serve.go index d0315b16a37..29b4117e4ef 100644 --- a/gopls/internal/debug/serve.go +++ b/gopls/internal/debug/serve.go @@ -462,7 +462,6 @@ func (i *Instance) Serve(ctx context.Context, addr string) (string, error) { mux.HandleFunc("/analysis/", render(AnalysisTmpl, i.getAnalysis)) mux.HandleFunc("/cache/", render(CacheTmpl, i.getCache)) mux.HandleFunc("/session/", render(SessionTmpl, i.getSession)) - mux.HandleFunc("/view/", render(ViewTmpl, i.getView)) mux.HandleFunc("/client/", render(ClientTmpl, i.getClient)) mux.HandleFunc("/server/", render(ServerTmpl, i.getServer)) mux.HandleFunc("/file/", render(FileTmpl, i.getFile)) @@ -644,12 +643,17 @@ var BaseTemplate = template.Must(template.New("").Parse(` width:6rem; } td.value { - text-align: right; + text-align: right; } ul.spans { font-family: monospace; font-size: 85%; } +body { + font-family: sans-serif; + font-size: 1rem; + line-height: normal; +} {{block "head" .}}{{end}} @@ -674,7 +678,6 @@ Unknown page {{define "clientlink"}}Client {{.}}{{end}} {{define "serverlink"}}Server {{.}}{{end}} {{define "sessionlink"}}Session {{.}}{{end}} -{{define "viewlink"}}View {{.}}{{end}} `)).Funcs(template.FuncMap{ "fuint64": fuint64, "fuint32": fuint32, @@ -706,7 +709,7 @@ Unknown page }) var MainTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(` -{{define "title"}}GoPls server information{{end}} +{{define "title"}}Gopls server information{{end}} {{define "body"}}

Caches

    {{range .State.Caches}}
  • {{template "cachelink" .ID}}
  • {{end}}
@@ -722,7 +725,7 @@ var MainTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(` `)) var InfoTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(` -{{define "title"}}GoPls version information{{end}} +{{define "title"}}Gopls version information{{end}} {{define "body"}} {{.}} {{end}} @@ -771,6 +774,13 @@ var CacheTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(` {{define "body"}}

memoize.Store entries

    {{range $k,$v := .MemStats}}
  • {{$k}} - {{$v}}
  • {{end}}
+

File stats

+

+{{- $stats := .FileStats -}} +Total: {{$stats.Total}}
+Largest: {{$stats.Largest}}
+Errors: {{$stats.Errs}}
+

{{end}} `)) @@ -806,7 +816,16 @@ var SessionTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(` {{define "body"}} From: {{template "cachelink" .Cache.ID}}

Views

-
    {{range .Views}}
  • {{.Folder.Name}} is {{template "viewlink" .ID}} in {{.Folder.Dir}}
  • {{end}}
+
    {{range .Views}} +{{- $envOverlay := .EnvOverlay -}} +
  • ID: {{.ID}}
    +Type: {{.Type}}
    +Root: {{.Root}}
    +{{- if $envOverlay}} +Env overlay: {{$envOverlay}})
    +{{end -}} +Folder: {{.Folder.Name}}:{{.Folder.Dir}}
  • +{{end}}

Overlays

{{$session := .}}
    {{range .Overlays}} @@ -816,14 +835,6 @@ From: {{template "cachelink" .Cache.ID}}
    {{end}} `)) -var ViewTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(` -{{define "title"}}View {{.ID}}{{end}} -{{define "body"}} -Name: {{.Folder.Name}}
    -Folder: {{.Folder.Dir}}
    -{{end}} -`)) - var FileTmpl = template.Must(template.Must(BaseTemplate.Clone()).Parse(` {{define "title"}}Overlay {{.Identity.Hash}}{{end}} {{define "body"}} diff --git a/gopls/internal/debug/template_test.go b/gopls/internal/debug/template_test.go index 53d4cb157b8..f3d4827a9b0 100644 --- a/gopls/internal/debug/template_test.go +++ b/gopls/internal/debug/template_test.go @@ -36,7 +36,6 @@ var templates = map[string]struct { "TraceTmpl": {debug.TraceTmpl, debug.TraceResults{}}, "CacheTmpl": {debug.CacheTmpl, &cache.Cache{}}, "SessionTmpl": {debug.SessionTmpl, &cache.Session{}}, - "ViewTmpl": {debug.ViewTmpl, &cache.View{}}, "ClientTmpl": {debug.ClientTmpl, &debug.Client{}}, "ServerTmpl": {debug.ServerTmpl, &debug.Server{}}, "FileTmpl": {debug.FileTmpl, &cache.Overlay{}}, diff --git a/gopls/internal/lsp/cache/cache.go b/gopls/internal/lsp/cache/cache.go index 72fe36ee302..9127412e430 100644 --- a/gopls/internal/lsp/cache/cache.go +++ b/gopls/internal/lsp/cache/cache.go @@ -11,6 +11,7 @@ import ( "sync/atomic" "time" + "golang.org/x/tools/gopls/internal/lsp/command" "golang.org/x/tools/gopls/internal/lsp/protocol" "golang.org/x/tools/internal/event" "golang.org/x/tools/internal/gocommand" @@ -76,6 +77,7 @@ func (c *Cache) MemStats() map[reflect.Type]int { return c.store.Stats() } // FileStats returns information about the set of files stored in the cache. // It is intended for debugging only. -func (c *Cache) FileStats() (files, largest, errs int) { - return c.fileStats() +func (c *Cache) FileStats() (stats command.FileStats) { + stats.Total, stats.Largest, stats.Errs = c.fileStats() + return } diff --git a/gopls/internal/server/command.go b/gopls/internal/server/command.go index 60c71840f4f..fbaf2017bdd 100644 --- a/gopls/internal/server/command.go +++ b/gopls/internal/server/command.go @@ -1052,7 +1052,7 @@ func (c *commandHandler) MemStats(ctx context.Context) (command.MemStatsResult, // about the current state of the loaded workspace for the current session. func (c *commandHandler) WorkspaceStats(ctx context.Context) (command.WorkspaceStatsResult, error) { var res command.WorkspaceStatsResult - res.Files.Total, res.Files.Largest, res.Files.Errs = c.s.session.Cache().FileStats() + res.Files = c.s.session.Cache().FileStats() for _, view := range c.s.session.Views() { vs, err := collectViewStats(ctx, view) diff --git a/gopls/internal/test/integration/debug/debug_test.go b/gopls/internal/test/integration/debug/debug_test.go index 9aba51f37e5..04dff9062d0 100644 --- a/gopls/internal/test/integration/debug/debug_test.go +++ b/gopls/internal/test/integration/debug/debug_test.go @@ -65,7 +65,7 @@ func TestStartDebugging(t *testing.T) { if err != nil { t.Fatalf("reading HTTP response body: %v", err) } - const want = "GoPls" + const want = "<title>Gopls" if !strings.Contains(string(data), want) { t.Errorf("GET %s response does not contain %q: <<%s>>", debugURL, want, data) }