Skip to content

Commit 71ab7ba

Browse files
johanfyllingashutosh-narkar
authored andcommitted
debug: Always including Input and Data variable scopes
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]>
1 parent e16f22a commit 71ab7ba

File tree

2 files changed

+77
-9
lines changed

2 files changed

+77
-9
lines changed

Diff for: debug/debugger_test.go

+65-9
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
15111511
name: "Locals",
15121512
namedVariables: 0,
15131513
},
1514+
"Input (not provided)": {
1515+
name: "Input (not provided)",
1516+
namedVariables: 0,
1517+
},
1518+
"Data (not provided)": {
1519+
name: "Data (not provided)",
1520+
namedVariables: 0,
1521+
},
15141522
},
15151523
},
15161524
{
@@ -1543,6 +1551,10 @@ func TestDebuggerScopeVariables(t *testing.T) {
15431551
},
15441552
},
15451553
},
1554+
"Data (not provided)": {
1555+
name: "Data (not provided)",
1556+
namedVariables: 0,
1557+
},
15461558
},
15471559
},
15481560
{
@@ -1580,6 +1592,10 @@ func TestDebuggerScopeVariables(t *testing.T) {
15801592
},
15811593
},
15821594
},
1595+
"Data (not provided)": {
1596+
name: "Data (not provided)",
1597+
namedVariables: 0,
1598+
},
15831599
},
15841600
},
15851601
{
@@ -1644,6 +1660,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
16441660
},
16451661
},
16461662
},
1663+
"Input (not provided)": {
1664+
name: "Input (not provided)",
1665+
namedVariables: 0,
1666+
},
1667+
"Data (not provided)": {
1668+
name: "Data (not provided)",
1669+
namedVariables: 0,
1670+
},
16471671
},
16481672
},
16491673
{
@@ -1662,6 +1686,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
16621686
},
16631687
},
16641688
},
1689+
"Input (not provided)": {
1690+
name: "Input (not provided)",
1691+
namedVariables: 0,
1692+
},
1693+
"Data (not provided)": {
1694+
name: "Data (not provided)",
1695+
namedVariables: 0,
1696+
},
16651697
},
16661698
},
16671699
{
@@ -1684,6 +1716,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
16841716
name: "Locals",
16851717
namedVariables: 0,
16861718
},
1719+
"Input (not provided)": {
1720+
name: "Input (not provided)",
1721+
namedVariables: 0,
1722+
},
1723+
"Data (not provided)": {
1724+
name: "Data (not provided)",
1725+
namedVariables: 0,
1726+
},
16871727
"Result Set": {
16881728
name: "Result Set",
16891729
namedVariables: 1,
@@ -1739,6 +1779,14 @@ func TestDebuggerScopeVariables(t *testing.T) {
17391779
name: "Locals",
17401780
namedVariables: 0,
17411781
},
1782+
"Input (not provided)": {
1783+
name: "Input (not provided)",
1784+
namedVariables: 0,
1785+
},
1786+
"Data (not provided)": {
1787+
name: "Data (not provided)",
1788+
namedVariables: 0,
1789+
},
17421790
"Virtual Cache": {
17431791
name: "Virtual Cache",
17441792
namedVariables: 2,
@@ -1766,6 +1814,10 @@ func TestDebuggerScopeVariables(t *testing.T) {
17661814
name: "Locals",
17671815
namedVariables: 0,
17681816
},
1817+
"Input (not provided)": {
1818+
name: "Input (not provided)",
1819+
namedVariables: 0,
1820+
},
17691821
"Data": {
17701822
name: "Data",
17711823
namedVariables: 1,
@@ -1859,23 +1911,27 @@ func TestDebuggerScopeVariables(t *testing.T) {
18591911
if scope.Name() != expScope.name {
18601912
t.Errorf("Expected scope name %s, got %s", expScope.name, scope.Name())
18611913
}
1914+
18621915
if scope.NamedVariables() != expScope.namedVariables {
18631916
t.Errorf("Expected %d named variables, got %d", expScope.namedVariables, scope.NamedVariables())
18641917
}
1865-
if scope.VariablesReference() == 0 {
1918+
1919+
if scope.NamedVariables() > 0 && scope.VariablesReference() == 0 {
18661920
t.Errorf("Expected non-zero variables reference")
18671921
}
18681922

1869-
vars, err := s.Variables(scope.VariablesReference())
1870-
if err != nil {
1871-
t.Fatalf("Unexpected error: %v", err)
1872-
}
1923+
if expScope.namedVariables > 0 {
1924+
vars, err := s.Variables(scope.VariablesReference())
1925+
if err != nil {
1926+
t.Fatalf("Unexpected error: %v", err)
1927+
}
18731928

1874-
if len(vars) != expScope.namedVariables {
1875-
t.Fatalf("Expected nuber of variables to equal named variables for scope (%d), got %d", expScope.namedVariables, len(vars))
1876-
}
1929+
if len(vars) != expScope.namedVariables {
1930+
t.Fatalf("Expected nuber of variables to equal named variables for scope (%d), got %d", expScope.namedVariables, len(vars))
1931+
}
18771932

1878-
assertVariables(t, s, vars, expScope.variables)
1933+
assertVariables(t, s, vars, expScope.variables)
1934+
}
18791935
}
18801936
})
18811937
}

Diff for: debug/thread.go

+12
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ func (t *thread) scopes(stackIndex int) []Scope {
360360
variablesReference: t.inputVars(e),
361361
}
362362
scopes = append(scopes, inputScope)
363+
} else {
364+
inputScope := scope{
365+
name: "Input (not provided)",
366+
namedVariables: 0,
367+
}
368+
scopes = append(scopes, inputScope)
363369
}
364370

365371
if t.store != nil {
@@ -369,6 +375,12 @@ func (t *thread) scopes(stackIndex int) []Scope {
369375
variablesReference: t.dataVars(),
370376
}
371377
scopes = append(scopes, dataScope)
378+
} else {
379+
dataScope := scope{
380+
name: "Data (not provided)",
381+
namedVariables: 0,
382+
}
383+
scopes = append(scopes, dataScope)
372384
}
373385

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

0 commit comments

Comments
 (0)