Skip to content

Commit f6ceb8d

Browse files
committed
[lldb-dap] Follow the spec more closely on 'initialize' arguments.
Updates `InitializeRequestArguments` to correctly follow the spec, see https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize.
1 parent 25ab47b commit f6ceb8d

File tree

4 files changed

+78
-13
lines changed

4 files changed

+78
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ llvm::Expected<InitializeResponse> InitializeRequestHandler::Run(
2323
const InitializeRequestArguments &arguments) const {
2424
// Store initialization arguments for later use in Launch/Attach.
2525
dap.clientFeatures = arguments.supportedFeatures;
26-
dap.sourceInitFile = arguments.lldbExtSourceInitFile.value_or(true);
26+
dap.sourceInitFile = arguments.lldbExtSourceInitFile;
2727

2828
return dap.GetCapabilities();
2929
}

lldb/tools/lldb-dap/Protocol/ProtocolRequests.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,13 @@ bool fromJSON(const json::Value &Params, InitializeRequestArguments &IRA,
216216
}
217217

218218
return OM.map("adapterID", IRA.adapterID) &&
219-
OM.map("clientID", IRA.clientID) &&
220-
OM.map("clientName", IRA.clientName) && OM.map("locale", IRA.locale) &&
221-
OM.map("linesStartAt1", IRA.linesStartAt1) &&
222-
OM.map("columnsStartAt1", IRA.columnsStartAt1) &&
219+
OM.mapOptional("clientID", IRA.clientID) &&
220+
OM.mapOptional("clientName", IRA.clientName) &&
221+
OM.mapOptional("locale", IRA.locale) &&
222+
OM.mapOptional("linesStartAt1", IRA.linesStartAt1) &&
223+
OM.mapOptional("columnsStartAt1", IRA.columnsStartAt1) &&
223224
OM.mapOptional("pathFormat", IRA.pathFormat) &&
224-
OM.map("$__lldb_sourceInitFile", IRA.lldbExtSourceInitFile);
225+
OM.mapOptional("$__lldb_sourceInitFile", IRA.lldbExtSourceInitFile);
225226
}
226227

227228
bool fromJSON(const json::Value &Params, Configuration &C, json::Path P) {

lldb/tools/lldb-dap/Protocol/ProtocolRequests.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,23 @@ struct InitializeRequestArguments {
108108
std::string adapterID;
109109

110110
/// The ID of the client using this adapter.
111-
std::optional<std::string> clientID;
111+
std::string clientID;
112112

113113
/// The human-readable name of the client using this adapter.
114-
std::optional<std::string> clientName;
114+
std::string clientName;
115115

116116
/// The ISO-639 locale of the client using this adapter, e.g. en-US or de-CH.
117-
std::optional<std::string> locale;
117+
std::string locale;
118118

119119
/// Determines in what format paths are specified. The default is `path`,
120120
/// which is the native format.
121121
PathFormat pathFormat = ePatFormatPath;
122122

123123
/// If true all line numbers are 1-based (default).
124-
std::optional<bool> linesStartAt1;
124+
bool linesStartAt1 = true;
125125

126126
/// If true all column numbers are 1-based (default).
127-
std::optional<bool> columnsStartAt1;
127+
bool columnsStartAt1 = true;
128128

129129
/// The set of supported features reported by the client.
130130
llvm::DenseSet<ClientFeature> supportedFeatures;
@@ -133,7 +133,7 @@ struct InitializeRequestArguments {
133133
/// @{
134134

135135
/// Source init files when initializing lldb::SBDebugger.
136-
std::optional<bool> lldbExtSourceInitFile;
136+
bool lldbExtSourceInitFile = true;
137137

138138
/// @}
139139
};

lldb/unittests/DAP/ProtocolRequestsTest.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ TEST(ProtocolRequestsTest, EvaluateArguments) {
7777
EXPECT_EQ(expected->expression, "hello world");
7878
EXPECT_EQ(expected->context, eEvaluateContextRepl);
7979

80-
// Check required keys;
80+
// Check required keys.
8181
EXPECT_THAT_EXPECTED(parse<EvaluateArguments>(R"({})"),
8282
FailedWithMessage("missing value at (root).expression"));
8383
}
@@ -118,3 +118,67 @@ TEST(ProtocolRequestsTest, EvaluateResponseBody) {
118118
ASSERT_THAT_EXPECTED(expected_opt, llvm::Succeeded());
119119
EXPECT_EQ(PrettyPrint(*expected_opt), PrettyPrint(body));
120120
}
121+
122+
TEST(ProtocolRequestsTest, InitializeRequestArguments) {
123+
llvm::Expected<InitializeRequestArguments> expected =
124+
parse<InitializeRequestArguments>(R"({"adapterID": "myid"})");
125+
ASSERT_THAT_EXPECTED(expected, llvm::Succeeded());
126+
EXPECT_EQ(expected->adapterID, "myid");
127+
128+
// Check optional keys.
129+
expected = parse<InitializeRequestArguments>(R"({
130+
"adapterID": "myid",
131+
"clientID": "myclientid",
132+
"clientName": "lldb-dap-unit-tests",
133+
"locale": "en-US",
134+
"linesStartAt1": true,
135+
"columnsStartAt1": true,
136+
"pathFormat": "uri",
137+
"supportsVariableType": true,
138+
"supportsVariablePaging": true,
139+
"supportsRunInTerminalRequest": true,
140+
"supportsMemoryReferences": true,
141+
"supportsProgressReporting": true,
142+
"supportsInvalidatedEvent": true,
143+
"supportsMemoryEvent": true,
144+
"supportsArgsCanBeInterpretedByShell": true,
145+
"supportsStartDebuggingRequest": true,
146+
"supportsANSIStyling": true
147+
})");
148+
ASSERT_THAT_EXPECTED(expected, llvm::Succeeded());
149+
EXPECT_EQ(expected->adapterID, "myid");
150+
EXPECT_EQ(expected->clientID, "myclientid");
151+
EXPECT_EQ(expected->clientName, "lldb-dap-unit-tests");
152+
EXPECT_EQ(expected->locale, "en-US");
153+
EXPECT_EQ(expected->linesStartAt1, true);
154+
EXPECT_EQ(expected->columnsStartAt1, true);
155+
EXPECT_EQ(expected->pathFormat, ePathFormatURI);
156+
EXPECT_EQ(expected->supportedFeatures.contains(eClientFeatureVariableType),
157+
true);
158+
EXPECT_EQ(
159+
expected->supportedFeatures.contains(eClientFeatureRunInTerminalRequest),
160+
true);
161+
EXPECT_EQ(
162+
expected->supportedFeatures.contains(eClientFeatureMemoryReferences),
163+
true);
164+
EXPECT_EQ(
165+
expected->supportedFeatures.contains(eClientFeatureProgressReporting),
166+
true);
167+
EXPECT_EQ(
168+
expected->supportedFeatures.contains(eClientFeatureInvalidatedEvent),
169+
true);
170+
EXPECT_EQ(expected->supportedFeatures.contains(eClientFeatureMemoryEvent),
171+
true);
172+
EXPECT_EQ(expected->supportedFeatures.contains(
173+
eClientFeatureArgsCanBeInterpretedByShell),
174+
true);
175+
EXPECT_EQ(
176+
expected->supportedFeatures.contains(eClientFeatureStartDebuggingRequest),
177+
true);
178+
EXPECT_EQ(expected->supportedFeatures.contains(eClientFeatureANSIStyling),
179+
true);
180+
181+
// Check required keys.
182+
EXPECT_THAT_EXPECTED(parse<InitializeRequestArguments>(R"({})"),
183+
FailedWithMessage("missing value at (root).adapterID"));
184+
}

0 commit comments

Comments
 (0)