Skip to content

Commit 2eee320

Browse files
committed
Update DAP Client to Support RunInTerminal and Structured Launch Arguments
Refactor the DAP client API to use move semantics for Initialize and Launch requests, enabling cleaner handling of optional arguments. Add support for the `runInTerminal` launch mode by introducing optional `console` and `runInTerminal` fields to `LaunchRequestArguments`, along with two new capability flags (`supportsRunInTerminalRequest` and `supportsArgsCanBeInterpretedByShell`) in the initialize request. Replace pointer-based and vector-based Launch overloads with a dedicated `LaunchRequestArguments` overload, while keeping the old vector-based API as a convenience wrapper. Introduce `Json::Contains` helper for safer optional property serialization. * dap/Client.hpp, dap/Client.cpp: Change `Initialize` to take rvalue reference; add `Launch(LaunchRequestArguments&&)` overload * dap/dap.hpp, dap/dap.cpp: Add `console` and `runInTerminal` optional fields to `LaunchRequestArguments` * dap/JSON.hpp, dap/JSON.cpp: Add `Contains` methods; apply consistent formatting * dbgcli/MainFrame.cpp: Advertise terminal capabilities; use new structured Launch API **Generated by CodeLite** Signed-off-by: Eran Ifrah <eran@codelite.org>
1 parent 6bda8c0 commit 2eee320

7 files changed

Lines changed: 106 additions & 59 deletions

File tree

dap/Client.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -462,18 +462,12 @@ void dap::Client::Reset()
462462
}
463463

464464
/// API
465-
void dap::Client::Initialize(const dap::InitializeRequestArguments* initArgs)
465+
void dap::Client::Initialize(dap::InitializeRequestArguments&& initArgs)
466466
{
467467
// Send initialize request
468468
auto req = MakeRequest<InitializeRequest>();
469-
if (initArgs) {
470-
req->arguments = *initArgs;
469+
req->arguments = std::move(initArgs);
471470

472-
} else {
473-
// use the defaults
474-
req->arguments.clientID = "wxdap";
475-
req->arguments.clientName = "wxdap";
476-
}
477471
SendRequest(req);
478472
m_handshake_state = eHandshakeState::kInProgress;
479473
}
@@ -497,20 +491,26 @@ void dap::Client::ConfigurationDone()
497491
SendRequest(req);
498492
}
499493

500-
void dap::Client::Launch(std::vector<wxString>&& cmd, const wxString& workingDirectory, const dap::Environment& env)
494+
void dap::Client::Launch(LaunchRequestArguments&& args)
501495
{
502496
m_active_thread_id = wxNOT_FOUND;
503497
auto req = MakeRequest<LaunchRequest>();
504-
req->arguments.program = cmd[0];
498+
req->arguments = std::move(args);
499+
SendRequest(req);
500+
}
501+
502+
void dap::Client::Launch(std::vector<wxString>&& cmd, const wxString& workingDirectory, const dap::Environment& env)
503+
{
504+
LaunchRequestArguments args;
505+
args.program = cmd[0];
505506

506507
cmd.erase(cmd.begin());
507-
req->arguments.args = cmd; // the remainder are the args
508+
args.args = cmd; // the remainder are the args
508509

509510
// set the working directory & env vars
510-
req->arguments.cwd = workingDirectory;
511-
req->arguments.env = env;
512-
513-
SendRequest(req);
511+
args.cwd = workingDirectory;
512+
args.env = env;
513+
Launch(std::move(args));
514514
}
515515

516516
void dap::Client::GetThreads()

dap/Client.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class WXDLLIMPEXP_DAP Client : public wxEvtHandler
224224
/**
225225
* @brief initiate the handshake between the server and the client
226226
*/
227-
void Initialize(const dap::InitializeRequestArguments* initArgs = nullptr);
227+
void Initialize(dap::InitializeRequestArguments&& initArgs);
228228

229229
/**
230230
* @brief are we still connected?
@@ -254,6 +254,11 @@ class WXDLLIMPEXP_DAP Client : public wxEvtHandler
254254
*/
255255
void Launch(std::vector<wxString>&& cmd, const wxString& workingDirectory = wxEmptyString,
256256
const dap::Environment& env = {});
257+
/**
258+
* @brief start the debuggee
259+
*/
260+
void Launch(LaunchRequestArguments&& args);
261+
257262
/**
258263
* @brief attach to dap server
259264
*/

dap/JSON.cpp

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
namespace dap
2626
{
27-
#define CHECK_IS_CONTAINER() \
28-
if(!m_cjson) { \
29-
return Json(nullptr); \
30-
} \
31-
if(!IsArray() && !IsObject()) { \
32-
return Json(m_cjson); \
27+
#define CHECK_IS_CONTAINER() \
28+
if (!m_cjson) { \
29+
return Json(nullptr); \
30+
} \
31+
if (!IsArray() && !IsObject()) { \
32+
return Json(m_cjson); \
3333
}
3434

3535
Json::Json(cJsonDap* ptr)
@@ -39,9 +39,9 @@ Json::Json(cJsonDap* ptr)
3939

4040
void Json::DecRef()
4141
{
42-
if(m_refCount) {
42+
if (m_refCount) {
4343
(*m_refCount)--;
44-
if(m_refCount->load() == 0) {
44+
if (m_refCount->load() == 0) {
4545
// Releas the underlying pointer
4646
Delete();
4747
delete m_refCount;
@@ -52,30 +52,30 @@ void Json::DecRef()
5252

5353
void Json::IncRef()
5454
{
55-
if(m_refCount) {
55+
if (m_refCount) {
5656
(*m_refCount)++;
5757
}
5858
}
5959

6060
void Json::Manage()
6161
{
62-
if(!IsManaged()) {
62+
if (!IsManaged()) {
6363
m_refCount = new std::atomic_int;
6464
m_refCount->store(1);
6565
}
6666
}
6767

6868
void Json::UnManage()
6969
{
70-
if(m_refCount) {
70+
if (m_refCount) {
7171
delete m_refCount;
7272
m_refCount = nullptr;
7373
}
7474
}
7575

7676
Json& Json::operator=(const Json& other)
7777
{
78-
if(this == &other) {
78+
if (this == &other) {
7979
return *this;
8080
}
8181
DecRef();
@@ -96,13 +96,13 @@ Json::~Json()
9696

9797
Json Json::operator[](const wxString& index) const
9898
{
99-
if(m_cjson == nullptr) {
99+
if (m_cjson == nullptr) {
100100
return Json(nullptr);
101101
}
102102

103103
cJsonDap* child = m_cjson->child;
104-
while(child) {
105-
if(child->string && strcmp(child->string, index.c_str()) == 0) {
104+
while (child) {
105+
if (child->string && strcmp(child->string, index.c_str()) == 0) {
106106
return Json(child);
107107
}
108108
child = child->next;
@@ -112,15 +112,15 @@ Json Json::operator[](const wxString& index) const
112112

113113
Json Json::AddItem(const wxString& name, cJsonDap* item)
114114
{
115-
if(m_cjson == nullptr) {
115+
if (m_cjson == nullptr) {
116116
cJSON_Delete(item);
117117
return Json(nullptr);
118118
}
119-
if(m_cjson->type != cJsonDap_Array && m_cjson->type != cJsonDap_Object) {
119+
if (m_cjson->type != cJsonDap_Array && m_cjson->type != cJsonDap_Object) {
120120
cJSON_Delete(item);
121121
return Json(nullptr);
122122
}
123-
if(m_cjson->type == cJsonDap_Array) {
123+
if (m_cjson->type == cJsonDap_Array) {
124124
cJSON_AddItemToArray(m_cjson, item);
125125
} else {
126126
cJSON_AddItemToObject(m_cjson, name.c_str(), item);
@@ -130,7 +130,7 @@ Json Json::AddItem(const wxString& name, cJsonDap* item)
130130

131131
wxString Json::ToString(bool pretty) const
132132
{
133-
if(m_cjson == nullptr) {
133+
if (m_cjson == nullptr) {
134134
return "";
135135
}
136136
char* c = pretty ? cJSON_Print(m_cjson) : cJSON_PrintUnformatted(m_cjson);
@@ -156,7 +156,7 @@ Json Json::CreateObject()
156156
void Json::Delete()
157157
{
158158
// Delete only when owned
159-
if(m_cjson) {
159+
if (m_cjson) {
160160
cJSON_Delete(m_cjson);
161161
m_cjson = nullptr;
162162
}
@@ -167,7 +167,7 @@ Json Json::Add(const char* name, const wxString& value) { return Add(name, value
167167
Json Json::Add(const char* name, const char* value)
168168
{
169169
CHECK_IS_CONTAINER();
170-
if(IsObject()) {
170+
if (IsObject()) {
171171
cJSON_AddItemToObject(m_cjson, name, cJSON_CreateString(value));
172172
} else {
173173
// Array
@@ -179,7 +179,7 @@ Json Json::Add(const char* name, const char* value)
179179
Json Json::Add(const char* name, double value)
180180
{
181181
CHECK_IS_CONTAINER();
182-
if(IsObject()) {
182+
if (IsObject()) {
183183
cJSON_AddItemToObject(m_cjson, name, cJSON_CreateNumber(value));
184184
} else {
185185
// Array
@@ -191,7 +191,7 @@ Json Json::Add(const char* name, double value)
191191
Json Json::Add(const char* name, bool value)
192192
{
193193
CHECK_IS_CONTAINER();
194-
if(IsObject()) {
194+
if (IsObject()) {
195195
cJSON_AddItemToObject(m_cjson, name, cJSON_CreateBool(value ? 1 : 0));
196196
} else {
197197
// Array
@@ -202,44 +202,44 @@ Json Json::Add(const char* name, bool value)
202202

203203
wxString Json::GetString(const wxString& defaultVaule) const
204204
{
205-
if(!m_cjson || m_cjson->type != cJsonDap_String) {
205+
if (!m_cjson || m_cjson->type != cJsonDap_String) {
206206
return defaultVaule;
207207
}
208208
return m_cjson->valuestring;
209209
}
210210

211211
double Json::GetNumber(double defaultVaule) const
212212
{
213-
if(!m_cjson || m_cjson->type != cJsonDap_Number) {
213+
if (!m_cjson || m_cjson->type != cJsonDap_Number) {
214214
return defaultVaule;
215215
}
216216
return m_cjson->valuedouble;
217217
}
218218

219219
int Json::GetInteger(int defaultVaule) const
220220
{
221-
if(!m_cjson || m_cjson->type != cJsonDap_Number) {
221+
if (!m_cjson || m_cjson->type != cJsonDap_Number) {
222222
return defaultVaule;
223223
}
224224
return m_cjson->valueint;
225225
}
226226

227227
bool Json::GetBool(bool defaultVaule) const
228228
{
229-
if(!m_cjson || (m_cjson->type != cJsonDap_True && m_cjson != cJsonDap_False)) {
229+
if (!m_cjson || (m_cjson->type != cJsonDap_True && m_cjson != cJsonDap_False)) {
230230
return defaultVaule;
231231
}
232232
return m_cjson->type == cJsonDap_True ? true : false;
233233
}
234234

235235
Json Json::operator[](size_t index) const
236236
{
237-
if(index >= GetCount()) {
237+
if (index >= GetCount()) {
238238
return Json(nullptr);
239239
}
240240
cJsonDap* child = m_cjson->child;
241241
size_t where = 0;
242-
while(where != index) {
242+
while (where != index) {
243243
child = child->next;
244244
++where;
245245
}
@@ -248,12 +248,12 @@ Json Json::operator[](size_t index) const
248248

249249
size_t Json::GetCount() const
250250
{
251-
if(m_cjson == nullptr) {
251+
if (m_cjson == nullptr) {
252252
return 0;
253253
}
254254
size_t count(0);
255255
cJsonDap* child = m_cjson->child;
256-
while(child) {
256+
while (child) {
257257
++count;
258258
child = child->next;
259259
}
@@ -262,11 +262,11 @@ size_t Json::GetCount() const
262262

263263
Json Json::AddObject(const char* name, const Json& obj)
264264
{
265-
if(!m_cjson) {
265+
if (!m_cjson) {
266266
return obj;
267267
}
268268
cJSON_AddItemToObject(m_cjson, name, obj.m_cjson);
269-
if(obj.IsManaged()) {
269+
if (obj.IsManaged()) {
270270
Json& o = const_cast<Json&>(obj);
271271
o.UnManage(); // We take ownership
272272
}
@@ -276,21 +276,21 @@ Json Json::AddObject(const char* name, const Json& obj)
276276
Json Json::Add(const char* name, const std::vector<wxString>& value)
277277
{
278278
auto a = AddArray(name);
279-
for(const auto& s : value) {
279+
for (const auto& s : value) {
280280
a.Add(s);
281281
}
282282
return a;
283283
}
284284

285285
std::vector<wxString> Json::GetStringArray() const
286286
{
287-
if(!m_cjson || m_cjson->type != cJsonDap_Array) {
287+
if (!m_cjson || m_cjson->type != cJsonDap_Array) {
288288
return {};
289289
}
290290
std::vector<wxString> arr;
291291
size_t count = GetCount();
292292
arr.reserve(count);
293-
for(size_t i = 0; i < count; ++i) {
293+
for (size_t i = 0; i < count; ++i) {
294294
arr.push_back((*this)[i].GetString());
295295
}
296296
return arr;
@@ -299,10 +299,10 @@ std::vector<wxString> Json::GetStringArray() const
299299
Json Json::Add(const char* name, const Json& value)
300300
{
301301
CHECK_IS_CONTAINER();
302-
if(IsObject()) {
302+
if (IsObject()) {
303303
return AddObject(name, value);
304304
} else {
305-
if(value.IsManaged()) {
305+
if (value.IsManaged()) {
306306
Json& o = const_cast<Json&>(value);
307307
o.UnManage(); // We take ownership
308308
}
@@ -317,4 +317,23 @@ Json Json::Parse(const wxString& source)
317317
json.Manage();
318318
return json;
319319
}
320-
} // namespace dap
320+
bool Json::Contains(const wxString& name) const
321+
{
322+
if (!m_cjson) {
323+
return false;
324+
}
325+
326+
const auto& j = (*this)[name];
327+
return j.m_cjson != nullptr;
328+
}
329+
330+
bool Json::Contains(const char* name) const
331+
{
332+
if (!m_cjson) {
333+
return false;
334+
}
335+
336+
const auto& j = (*this)[wxString::FromUTF8(name)];
337+
return j.m_cjson != nullptr;
338+
}
339+
} // namespace dap

dap/JSON.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct WXDLLIMPEXP_DAP Json {
6666
*/
6767
wxString GetName() const
6868
{
69-
if(m_cjson == nullptr || !m_cjson->string) {
69+
if (m_cjson == nullptr || !m_cjson->string) {
7070
return "";
7171
}
7272
return wxString(m_cjson->string);
@@ -134,6 +134,9 @@ struct WXDLLIMPEXP_DAP Json {
134134
Json AddObject(const wxString& name, const Json& obj) { return AddObject(name.mb_str(wxConvUTF8).data(), obj); }
135135
Json AddObject(const char* name, const Json& obj);
136136

137+
bool Contains(const wxString& name) const;
138+
bool Contains(const char* name) const;
139+
137140
/**
138141
* @brief return value as wxString
139142
*/

0 commit comments

Comments
 (0)