Skip to content

Commit

Permalink
debug: Always including Input and Data variable scopes
Browse files Browse the repository at this point in the history
even when there are no explicit `input` and `data` documents.

This makes discoverability of the scopes much better, as users will know to expect them.
Whereas, if it's only enabled/visible when there is an actual document, a user who
has not come across it before might not realize it should appear, and can therefore
be slow to realize scenarios where their setup is expecting an `input` document, but
is missing it for some reason.

Signed-off-by: Johan Fylling <[email protected]>
  • Loading branch information
johanfylling authored and ashutosh-narkar committed Sep 26, 2024
1 parent e16f22a commit 71ab7ba
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
74 changes: 65 additions & 9 deletions debug/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
name: "Locals",
namedVariables: 0,
},
"Input (not provided)": {
name: "Input (not provided)",
namedVariables: 0,
},
"Data (not provided)": {
name: "Data (not provided)",
namedVariables: 0,
},
},
},
{
Expand Down Expand Up @@ -1543,6 +1551,10 @@ func TestDebuggerScopeVariables(t *testing.T) {
},
},
},
"Data (not provided)": {
name: "Data (not provided)",
namedVariables: 0,
},
},
},
{
Expand Down Expand Up @@ -1580,6 +1592,10 @@ func TestDebuggerScopeVariables(t *testing.T) {
},
},
},
"Data (not provided)": {
name: "Data (not provided)",
namedVariables: 0,
},
},
},
{
Expand Down Expand Up @@ -1644,6 +1660,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
},
},
},
"Input (not provided)": {
name: "Input (not provided)",
namedVariables: 0,
},
"Data (not provided)": {
name: "Data (not provided)",
namedVariables: 0,
},
},
},
{
Expand All @@ -1662,6 +1686,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
},
},
},
"Input (not provided)": {
name: "Input (not provided)",
namedVariables: 0,
},
"Data (not provided)": {
name: "Data (not provided)",
namedVariables: 0,
},
},
},
{
Expand All @@ -1684,6 +1716,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
name: "Locals",
namedVariables: 0,
},
"Input (not provided)": {
name: "Input (not provided)",
namedVariables: 0,
},
"Data (not provided)": {
name: "Data (not provided)",
namedVariables: 0,
},
"Result Set": {
name: "Result Set",
namedVariables: 1,
Expand Down Expand Up @@ -1739,6 +1779,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
name: "Locals",
namedVariables: 0,
},
"Input (not provided)": {
name: "Input (not provided)",
namedVariables: 0,
},
"Data (not provided)": {
name: "Data (not provided)",
namedVariables: 0,
},
"Virtual Cache": {
name: "Virtual Cache",
namedVariables: 2,
Expand Down Expand Up @@ -1766,6 +1814,10 @@ func TestDebuggerScopeVariables(t *testing.T) {
name: "Locals",
namedVariables: 0,
},
"Input (not provided)": {
name: "Input (not provided)",
namedVariables: 0,
},
"Data": {
name: "Data",
namedVariables: 1,
Expand Down Expand Up @@ -1859,23 +1911,27 @@ func TestDebuggerScopeVariables(t *testing.T) {
if scope.Name() != expScope.name {
t.Errorf("Expected scope name %s, got %s", expScope.name, scope.Name())
}

if scope.NamedVariables() != expScope.namedVariables {
t.Errorf("Expected %d named variables, got %d", expScope.namedVariables, scope.NamedVariables())
}
if scope.VariablesReference() == 0 {

if scope.NamedVariables() > 0 && scope.VariablesReference() == 0 {
t.Errorf("Expected non-zero variables reference")
}

vars, err := s.Variables(scope.VariablesReference())
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if expScope.namedVariables > 0 {
vars, err := s.Variables(scope.VariablesReference())
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

if len(vars) != expScope.namedVariables {
t.Fatalf("Expected nuber of variables to equal named variables for scope (%d), got %d", expScope.namedVariables, len(vars))
}
if len(vars) != expScope.namedVariables {
t.Fatalf("Expected nuber of variables to equal named variables for scope (%d), got %d", expScope.namedVariables, len(vars))
}

assertVariables(t, s, vars, expScope.variables)
assertVariables(t, s, vars, expScope.variables)
}
}
})
}
Expand Down
12 changes: 12 additions & 0 deletions debug/thread.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ func (t *thread) scopes(stackIndex int) []Scope {
variablesReference: t.inputVars(e),
}
scopes = append(scopes, inputScope)
} else {
inputScope := scope{
name: "Input (not provided)",
namedVariables: 0,
}
scopes = append(scopes, inputScope)
}

if t.store != nil {
Expand All @@ -369,6 +375,12 @@ func (t *thread) scopes(stackIndex int) []Scope {
variablesReference: t.dataVars(),
}
scopes = append(scopes, dataScope)
} else {
dataScope := scope{
name: "Data (not provided)",
namedVariables: 0,
}
scopes = append(scopes, dataScope)
}

if rs := t.stack.Result(); rs != nil {
Expand Down

0 comments on commit 71ab7ba

Please sign in to comment.