Skip to content

Commit 10a4e37

Browse files
committed
Test refactor and comment improvements based on Greg's feedback
1 parent 4268576 commit 10a4e37

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

lldb/test/API/tools/lldb-dap/progress/Progress_emitter.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def create_options(cls):
3939
parser.add_option(
4040
"--total",
4141
dest="total",
42-
help="Total to count up, use -1 to identify as indeterminate",
42+
help="Total to count up, use None to identify as indeterminate",
4343
type="int",
44+
default=None,
4445
)
4546

4647
parser.add_option(
@@ -78,16 +79,16 @@ def __call__(self, debugger, command, exe_ctx, result):
7879
return
7980

8081
total = cmd_options.total
81-
if total == -1:
82+
if total is None:
8283
progress = lldb.SBProgress(
8384
"Progress tester", "Indeterminate Detail", debugger
8485
)
8586
else:
8687
progress = lldb.SBProgress("Progress tester", "Detail", total, debugger)
8788

88-
# Check to see if total is set to -1 to indicate an indeterminate progress
89+
# Check to see if total is set to None to indicate an indeterminate progress
8990
# then default to 10 steps.
90-
if total == -1:
91+
if total is None:
9192
total = 10
9293

9394
for i in range(1, total):

lldb/test/API/tools/lldb-dap/progress/TestDAP_Progress.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ def test_output_indeterminate(self):
109109
self.dap_server.request_evaluate(
110110
f"`command script import {progress_emitter}", context="repl"
111111
)
112-
self.dap_server.request_evaluate(
113-
"`test-progress --total -1 --seconds 1", context="repl"
114-
)
112+
self.dap_server.request_evaluate("`test-progress --seconds 1", context="repl")
115113

116114
self.dap_server.wait_for_event("progressEnd", 15)
117115
# Expect at least a start, an update, and end event
@@ -151,7 +149,7 @@ def test_output_nodetails_indeterminate(self):
151149
)
152150

153151
self.dap_server.request_evaluate(
154-
"`test-progress --total -1 --seconds 1 --no-details", context="repl"
152+
"`test-progress --seconds 1 --no-details", context="repl"
155153
)
156154

157155
self.dap_server.wait_for_event("progressEnd", 15)

lldb/tools/lldb-dap/Handler/InitializeRequestHandler.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ static std::string GetStringFromStructuredData(lldb::SBStructuredData &data,
2525
return std::string();
2626

2727
const size_t length = keyValue.GetStringValue(nullptr, 0);
28+
29+
if (length == 0)
30+
return std::string();
31+
2832
std::string str(length + 1, 0);
29-
keyValue.GetStringValue(&str[0], length);
33+
keyValue.GetStringValue(&str[0], length + 1);
3034
return str;
3135
}
3236

@@ -64,19 +68,38 @@ void ProgressEventThreadFunction(DAP &dap) {
6468
const uint64_t total = GetUintFromStructuredData(data, "total");
6569
const std::string details =
6670
GetStringFromStructuredData(data, "details");
67-
std::string message;
68-
// Include the title on the first event.
71+
6972
if (completed == 0) {
70-
const std::string title = GetStringFromStructuredData(data, "title");
71-
message += title;
72-
message += ": ";
73+
if (total == 1) {
74+
// This progress is non deterministic and won't get updated until it
75+
// is completed. Send the "message" which will be the combined title
76+
// and detail. The only other progress event for thus
77+
// non-deterministic progress will be the completed event So there
78+
// will be no need to update the detail.
79+
const std::string message =
80+
GetStringFromStructuredData(data, "message");
81+
dap.SendProgressEvent(progress_id, message.c_str(), completed,
82+
total);
83+
} else {
84+
// This progress is deterministic and will receive updates,
85+
// on the progress creation event VSCode will save the message in
86+
// the create packet and use that as the title, so we send just the
87+
// title in the progressCreate packet followed immediately by a
88+
// detail packet, if there is any detail.
89+
const std::string title =
90+
GetStringFromStructuredData(data, "title");
91+
dap.SendProgressEvent(progress_id, title.c_str(), completed, total);
92+
if (!details.empty())
93+
dap.SendProgressEvent(progress_id, details.c_str(), completed,
94+
total);
95+
}
96+
} else {
97+
// This progress event is either the end of the progress dialog, or an
98+
// update with possible detail. The "detail" string we send to VS Code
99+
// will be appended to the progress dialog's initial text from when it
100+
// was created.
101+
dap.SendProgressEvent(progress_id, details.c_str(), completed, total);
73102
}
74-
75-
message += details;
76-
// Verbose check, but we get -1 for the uint64 on failure to read
77-
// so we check everything before broadcasting an event.
78-
if (message.length() > 0)
79-
dap.SendProgressEvent(progress_id, message.c_str(), completed, total);
80103
}
81104
}
82105
}

0 commit comments

Comments
 (0)