Shorten variable types (#3535)

* Add ShortenType function

Taken from

  https://github.com/aarzilli/gdlv/blob/master/internal/prettyprint/short.go

with kind permission by @aarzilli.

* Shorten type names in variable values

The variables view in VS Code is a lot easier to read if long type names are
shortened in much the same way as we shorten them for functions in the call
stack view.

We only shorten them in the value strings; the Type field of dap.Variable is
kept as is. Since this only appears in a tooltip, it isn't a problem to have the
full type visible there.
This commit is contained in:
Stefan Haller
2023-11-09 10:15:25 +01:00
committed by GitHub
parent d6f215b27b
commit aec354cd0b
5 changed files with 179 additions and 24 deletions

View File

@ -2502,7 +2502,7 @@ func TestGlobalScopeAndVariables(t *testing.T) {
client.VariablesRequest(globalsScope)
globals := client.ExpectVariablesResponse(t)
checkChildren(t, globals, "Globals", 1)
ref := checkVarExact(t, globals, 0, "SomeVar", "github.com/go-delve/delve/_fixtures/internal/dir0/pkg.SomeVar", "github.com/go-delve/delve/_fixtures/internal/dir0/pkg.SomeType {X: 0}", "github.com/go-delve/delve/_fixtures/internal/dir0/pkg.SomeType", hasChildren)
ref := checkVarExact(t, globals, 0, "SomeVar", "github.com/go-delve/delve/_fixtures/internal/dir0/pkg.SomeVar", "pkg.SomeType {X: 0}", "github.com/go-delve/delve/_fixtures/internal/dir0/pkg.SomeType", hasChildren)
if ref > 0 {
client.VariablesRequest(ref)