@@ -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