Skip to content

Commit 4206a63

Browse files
committed
rework debugger termination
1 parent 3703767 commit 4206a63

File tree

6 files changed

+43
-18
lines changed

6 files changed

+43
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ All notable changes to the "robotcode" extension will be documented in this file
88
- Specifies the paths where robot/robotcode should discover test suites. Corresponds to the 'paths' option of robot
99
- Introduce setting `robotcode.robot.variableFiles` and correspondend launch config property `variableFiles`
1010
- Specifies the variable files for robotframework. Corresponds to the '--variablefile' option of robot.
11+
- Rework debugger termination
12+
- if you want to stop the current run
13+
- first click on stop tries to break the run like if you press <kbd>CTRL</kbd>+<kbd>c</kbd> to give the chance that logs and reports are written
14+
- second click stops/kill execution
15+
- 'None' values are now shown correctly in debugger
1116

1217
## 0.9.2
1318

robotcode/debugger/debugger.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def __init__(self) -> None:
231231
self.last_fail_message: Optional[str] = None
232232
self.stop_on_entry = False
233233
self.no_debug = False
234+
self.terminated = False
234235

235236
@property
236237
def debug(self) -> bool:
@@ -260,6 +261,10 @@ def robot_output_file(self) -> Optional[str]:
260261
def robot_output_file(self, value: Optional[str]) -> None:
261262
self._robot_output_file = value
262263

264+
@_logger.call
265+
def terminate(self) -> None:
266+
self.terminated = True
267+
263268
@_logger.call
264269
def start(self) -> None:
265270
with self.condition:
@@ -524,10 +529,14 @@ def process_start_state(self, source: str, line_no: int, type: str, status: str)
524529
)
525530

526531
def process_end_state(self, status: str, filter_id: str, description: str, text: Optional[str]) -> None:
527-
if status == "FAIL" and any(
528-
v
529-
for v in self.exception_breakpoints
530-
if v.filter_options is not None and any(o for o in v.filter_options if o.filter_id == filter_id)
532+
if (
533+
not self.terminated
534+
and status == "FAIL"
535+
and any(
536+
v
537+
for v in self.exception_breakpoints
538+
if v.filter_options is not None and any(o for o in v.filter_options if o.filter_id == filter_id)
539+
)
531540
):
532541
self.state = State.Paused
533542
self.send_event(

robotcode/debugger/launcher/server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
ConfigurationDoneRequest,
1616
DisconnectArguments,
1717
DisconnectRequest,
18+
Event,
1819
ExceptionBreakpointsFilter,
1920
InitializeRequestArguments,
2021
LaunchRequestArguments,
@@ -81,7 +82,7 @@ async def _initialize(self, arguments: InitializeRequestArguments, *args: Any, *
8182
supports_conditional_breakpoints=True,
8283
supports_hit_conditional_breakpoints=True,
8384
support_terminate_debuggee=True,
84-
support_suspend_debuggee=True,
85+
# support_suspend_debuggee=True,
8586
supports_evaluate_for_hovers=True,
8687
supports_terminate_request=True,
8788
supports_log_points=True,
@@ -216,6 +217,9 @@ async def _launch(
216217
if target:
217218
run_args.append(target)
218219

220+
if not paths and not target:
221+
run_args.append(".")
222+
219223
env = {k: ("" if v is None else str(v)) for k, v in env.items()} if env else {}
220224

221225
if console in ["integratedTerminal", "externalTerminal"]:
@@ -273,6 +277,8 @@ async def _disconnect(self, arguments: Optional[DisconnectArguments] = None, *ar
273277
@rpc_method(name="terminate", param_type=TerminateArguments)
274278
async def _terminate(self, arguments: Optional[TerminateArguments] = None, *args: Any, **kwargs: Any) -> None:
275279
if self.client.connected:
280+
self.send_event(Event("terminateRequested"))
281+
276282
return await self.client.protocol.send_request_async(TerminateRequest(arguments=arguments))
277283
else:
278284
await self.send_event_async(TerminatedEvent())

robotcode/debugger/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ async def terminate(self) -> None:
137137
async def _terminate(self, arguments: Optional[TerminateArguments] = None, *args: Any, **kwargs: Any) -> None:
138138
import signal
139139

140+
Debugger.instance().terminate()
141+
140142
if not self._sigint_signaled:
141143
self._logger.info("Send SIGINT to process")
142144
signal.raise_signal(signal.SIGINT)
@@ -145,8 +147,6 @@ async def _terminate(self, arguments: Optional[TerminateArguments] = None, *args
145147
self._logger.info("Send SIGTERM to process")
146148
signal.raise_signal(signal.SIGTERM)
147149

148-
Debugger.instance().stop()
149-
150150
@rpc_method(name="disconnect", param_type=DisconnectArguments)
151151
async def _disconnect(self, arguments: Optional[DisconnectArguments] = None, *args: Any, **kwargs: Any) -> None:
152152
if (

vscode-client/debugmanager.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ export class DebugManager {
247247
await DebugManager.OnDebugpyStarted(event.session, event.event, event.body);
248248
break;
249249
}
250+
case "terminateRequested": {
251+
for (const s of this._attachedSessions) {
252+
if (s.parentSession == event.session) {
253+
await vscode.debug.stopDebugging(s);
254+
}
255+
}
256+
break;
257+
}
250258
case "robotExited": {
251259
await DebugManager.OnRobotExited(
252260
event.session,
@@ -266,14 +274,7 @@ export class DebugManager {
266274
}
267275
}),
268276

269-
vscode.debug.onDidTerminateDebugSession(async (session) => {
270-
if (session.type === "robotcode") {
271-
for (const s of this._attachedSessions) {
272-
if (s.parentSession === session) {
273-
await vscode.debug.stopDebugging(s);
274-
}
275-
}
276-
}
277+
vscode.debug.onDidTerminateDebugSession((session) => {
277278
if (this._attachedSessions.has(session)) {
278279
this._attachedSessions.delete(session);
279280
}
@@ -423,8 +424,8 @@ export class DebugManager {
423424
{
424425
parentSession: session,
425426
compact: true,
426-
lifecycleManagedByParent: true,
427-
consoleMode: vscode.DebugConsoleMode.Separate,
427+
lifecycleManagedByParent: false,
428+
consoleMode: vscode.DebugConsoleMode.MergeWithParent,
428429
}
429430
);
430431
}

vscode-client/testcontrollermanager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,9 @@ export class TestControllerManager {
625625
} else {
626626
this.testController.items.forEach((test) => {
627627
const robotTest = this.findRobotItem(test);
628-
if (robotTest?.type === "workspace") {
628+
if (robotTest?.type === "error") {
629+
return;
630+
} else if (robotTest?.type === "workspace") {
629631
test.children.forEach((v) => includedItems.push(v));
630632
} else {
631633
includedItems.push(test);
@@ -636,6 +638,8 @@ export class TestControllerManager {
636638
const included = this.mapTestItemsToWorkspace(includedItems);
637639
const excluded = this.mapTestItemsToWorkspace(request.exclude ? Array.from(request.exclude) : []);
638640

641+
if (included.size === 0) return;
642+
639643
const run = this.testController.createTestRun(request);
640644

641645
token.onCancellationRequested(async (_) => {

0 commit comments

Comments
 (0)