Skip to content

Commit d730223

Browse files
committed
add test and suite scopes to variables for debugging
1 parent fe0cd07 commit d730223

File tree

1 file changed

+67
-12
lines changed

1 file changed

+67
-12
lines changed

robotcode/debug_adapter/launcher/debugger.py

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(
6868
self.source = source
6969
self.line = line
7070
self.column = column
71+
self._suite_marker = object()
7172
self._test_marker = object()
7273
self._local_marker = object()
7374
self._global_marker = object()
@@ -76,6 +77,12 @@ def __init__(
7677
def id(self) -> int:
7778
return id(self)
7879

80+
def test_id(self) -> int:
81+
return id(self._test_marker)
82+
83+
def suite_id(self) -> int:
84+
return id(self._suite_marker)
85+
7986
def local_id(self) -> int:
8087
return id(self._local_marker)
8188

@@ -436,7 +443,8 @@ def get_scopes(self, frame_id: int) -> List[Scope]:
436443
result: List[Scope] = []
437444
entry = next((v for v in self.stack_frames if v.id == frame_id), None)
438445
if entry is not None:
439-
if entry.context() is not None:
446+
context = entry.context()
447+
if context is not None:
440448
result.append(
441449
Scope(
442450
name="Local",
@@ -445,14 +453,33 @@ def get_scopes(self, frame_id: int) -> List[Scope]:
445453
variables_reference=entry.local_id(),
446454
)
447455
)
448-
result.append(
449-
Scope(
450-
name="Global",
451-
expensive=False,
452-
presentation_hint="global",
453-
variables_reference=entry.global_id(),
456+
if context.variables._test is not None and context.variables._test != context.variables.current:
457+
result.append(
458+
Scope(
459+
name="Test",
460+
expensive=False,
461+
presentation_hint="test",
462+
variables_reference=entry.test_id(),
463+
)
464+
)
465+
if context.variables._suite is not None and context.variables._suite != context.variables.current:
466+
result.append(
467+
Scope(
468+
name="Suite",
469+
expensive=False,
470+
presentation_hint="suite",
471+
variables_reference=entry.suite_id(),
472+
)
473+
)
474+
if context.variables._global is not None:
475+
result.append(
476+
Scope(
477+
name="Global",
478+
expensive=False,
479+
presentation_hint="global",
480+
variables_reference=entry.global_id(),
481+
)
454482
)
455-
)
456483

457484
return result
458485

@@ -465,16 +492,44 @@ def get_variables(
465492
format: Optional[ValueFormat] = None,
466493
) -> List[Variable]:
467494
result: List[Variable] = []
468-
entry = next((v for v in self.stack_frames if variables_reference in [v.global_id(), v.local_id()]), None)
495+
entry = next(
496+
(
497+
v
498+
for v in self.stack_frames
499+
if variables_reference in [v.global_id(), v.local_id(), v.suite_id(), v.test_id()]
500+
),
501+
None,
502+
)
469503
if entry is not None:
470504
context = entry.context()
471505
if context is not None:
472-
current_index = context.variables._scopes.index(context.variables.current)
473-
globals = context.variables._scopes[max(current_index - 1, 0)].as_dict()
474506

475507
if entry.global_id() == variables_reference:
476-
result += [Variable(name=k, value=repr(v), type=repr(type(v))) for k, v in globals.items()]
508+
result += [
509+
Variable(name=k, value=repr(v), type=repr(type(v)))
510+
for k, v in context.variables._global.as_dict().items()
511+
]
512+
elif entry.suite_id() == variables_reference:
513+
# current_index = context.variables._scopes.index(context.variables._suite)
514+
# globals = context.variables._scopes[max(current_index - 1, 0)].as_dict()
515+
globals = context.variables._global.as_dict()
516+
result += [
517+
Variable(name=k, value=repr(v), type=repr(type(v)))
518+
for k, v in context.variables._suite.as_dict().items()
519+
if k not in globals or globals[k] != v
520+
]
521+
elif entry.test_id() == variables_reference:
522+
# current_index = context.variables._scopes.index(context.variables._test)
523+
# globals = context.variables._scopes[max(current_index - 1, 0)].as_dict()
524+
globals = context.variables._suite.as_dict()
525+
result += [
526+
Variable(name=k, value=repr(v), type=repr(type(v)))
527+
for k, v in context.variables._test.as_dict().items()
528+
if k not in globals or globals[k] != v
529+
]
477530
elif entry.local_id() == variables_reference:
531+
current_index = context.variables._scopes.index(context.variables.current)
532+
globals = context.variables._scopes[max(current_index - 1, 0)].as_dict()
478533
result += [
479534
Variable(name=k, value=repr(v), type=repr(type(v)))
480535
for k, v in context.variables.current.as_dict().items()

0 commit comments

Comments
 (0)