@@ -18,8 +18,32 @@ using namespace lldb;
1818
1919namespace lldb_dap {
2020
21- static void ProgressEventThreadFunction (DAP &dap) {
22- llvm::set_thread_name (dap.name + " .progress_handler" );
21+ static std::string GetStringFromStructuredData (lldb::SBStructuredData &data,
22+ const char *key) {
23+ lldb::SBStructuredData keyValue = data.GetValueForKey (key);
24+ if (!keyValue)
25+ return std::string ();
26+
27+ const size_t length = keyValue.GetStringValue (nullptr , 0 );
28+
29+ if (length == 0 )
30+ return std::string ();
31+
32+ std::string str (length + 1 , 0 );
33+ keyValue.GetStringValue (&str[0 ], length + 1 );
34+ return str;
35+ }
36+
37+ static uint64_t GetUintFromStructuredData (lldb::SBStructuredData &data,
38+ const char *key) {
39+ lldb::SBStructuredData keyValue = data.GetValueForKey (key);
40+
41+ if (!keyValue.IsValid ())
42+ return 0 ;
43+ return keyValue.GetUnsignedIntegerValue ();
44+ }
45+
46+ void ProgressEventThreadFunction (DAP &dap) {
2347 lldb::SBListener listener (" lldb-dap.progress.listener" );
2448 dap.debugger .GetBroadcaster ().AddListener (
2549 listener, lldb::SBDebugger::eBroadcastBitProgress |
@@ -35,14 +59,47 @@ static void ProgressEventThreadFunction(DAP &dap) {
3559 done = true ;
3660 }
3761 } else {
38- uint64_t progress_id = 0 ;
39- uint64_t completed = 0 ;
40- uint64_t total = 0 ;
41- bool is_debugger_specific = false ;
42- const char *message = lldb::SBDebugger::GetProgressFromEvent (
43- event, progress_id, completed, total, is_debugger_specific);
44- if (message)
45- dap.SendProgressEvent (progress_id, message, completed, total);
62+ lldb::SBStructuredData data =
63+ lldb::SBDebugger::GetProgressDataFromEvent (event);
64+
65+ const uint64_t progress_id =
66+ GetUintFromStructuredData (data, " progress_id" );
67+ const uint64_t completed = GetUintFromStructuredData (data, " completed" );
68+ const uint64_t total = GetUintFromStructuredData (data, " total" );
69+ const std::string details =
70+ GetStringFromStructuredData (data, " details" );
71+
72+ if (completed == 0 ) {
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);
102+ }
46103 }
47104 }
48105 }
0 commit comments