Skip to content

Commit f4f95f9

Browse files
committed
Added doxygen comments for static LSP message types
1 parent 36e81a6 commit f4f95f9

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/lsp/static/Message.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
#include <nlohmann/json.hpp>
1111
#include "LSPTypes.h"
1212

13+
/**
14+
* @struct ResponseError
15+
* @brief Represents an error response in the LSP.
16+
* This implementation is slightly off-spec -- the spec says that ResponseError
17+
* is an **optional** field in a ResponseMessage, but our implementation always
18+
* includes it, and makes the distinction that if the code is 0, there is no error.
19+
* We should definitely change this to be more exactly in-line with the spec, but
20+
* this has worked for us so far.
21+
*
22+
*/
1323
struct ResponseError {
1424
int code = 0; // Error code, 0 means no error
1525
std::string message;
@@ -68,6 +78,11 @@ struct ResponseMessage;
6878
template<typename ParamsType>
6979
struct NotificationMessage;
7080

81+
/**
82+
* @struct GenericRequestMessage
83+
* @brief A generic type that can be converted to/from any specific RequestMessage type.
84+
*
85+
*/
7186
struct GenericRequestMessage : public RequestMessageBase {
7287
LSPAny params;
7388

@@ -102,6 +117,15 @@ struct GenericRequestMessage : public RequestMessageBase {
102117
}
103118
}
104119

120+
/**
121+
* @brief Convert this GenericRequestMessage to a specific RequestMessage type.
122+
*
123+
* This method allows converting the generic message to a specific type based on the ParamsType.
124+
* It uses the JSON serialization/deserialization to convert the params field to the specific type.
125+
*
126+
* @tparam ParamsType The specific parameters type to convert to.
127+
* @return RequestMessage<ParamsType> The specific RequestMessage type with the converted parameters.
128+
*/
105129
template <typename ParamsType>
106130
RequestMessage<ParamsType> toSpecific() const {
107131
RequestMessage<ParamsType> specific;
@@ -117,6 +141,11 @@ struct GenericRequestMessage : public RequestMessageBase {
117141
}
118142
};
119143

144+
/**
145+
* @struct GenericResponseMessage
146+
* @brief A generic type that can be converted to/from any specific ResponseMessage type.
147+
*
148+
*/
120149
struct GenericResponseMessage : public ResponseMessageBase {
121150
LSPAny result;
122151

@@ -174,6 +203,11 @@ struct GenericResponseMessage : public ResponseMessageBase {
174203
}
175204
};
176205

206+
/**
207+
* @struct GenericNotificationMessage
208+
* @brief A generic type that can be converted to/from any specific NotificationMessage type.
209+
*
210+
*/
177211
struct GenericNotificationMessage : public NotificationMessageBase {
178212
LSPAny params;
179213

@@ -231,6 +265,17 @@ struct GenericNotificationMessage : public NotificationMessageBase {
231265
template <typename ParamsType>
232266
struct RequestTraits;
233267

268+
/**
269+
* @struct RequestMessage
270+
* @brief A template class for all LSP request messages.
271+
*
272+
* Different request types are distinguished by their method name and parameters.
273+
* This class is templated on the ParamsType, which represents the specific parameters
274+
* for the request. It inherits from RequestMessageBase to provide the common structure.
275+
* The method name is determined by the RequestTraits specialization for the ParamsType.
276+
*
277+
* @tparam ParamsType
278+
*/
234279
template<typename ParamsType>
235280
struct RequestMessage : public RequestMessageBase {
236281
ParamsType params;
@@ -261,6 +306,17 @@ struct RequestMessage : public RequestMessageBase {
261306
}
262307
};
263308

309+
/**
310+
* @struct ResponseMessage
311+
* @brief A template class for all LSP response messages.
312+
*
313+
* Different response types are distinguished by their result type.
314+
* This class is templated on the ResultType, which represents the specific result
315+
* for the response. It inherits from ResponseMessageBase to provide the common structure.
316+
* The error field is included to indicate if there was an error processing the request.
317+
*
318+
* @tparam ResultType
319+
*/
264320
template<typename ResultType>
265321
struct ResponseMessage : public ResponseMessageBase {
266322
ResponseError error;
@@ -288,6 +344,11 @@ struct ResponseMessage : public ResponseMessageBase {
288344
}
289345
}
290346

347+
/**
348+
* @brief Convert this ResponseMessage to a GenericResponseMessage.
349+
*
350+
* @return GenericResponseMessage
351+
*/
291352
GenericResponseMessage toGeneric() const {
292353
GenericResponseMessage generic;
293354
generic.jsonrpc = jsonrpc;
@@ -308,6 +369,20 @@ struct ResponseMessage : public ResponseMessageBase {
308369
template <typename ParamsType>
309370
struct NotificationTraits;
310371

372+
/**
373+
* @struct NotificationMessage
374+
* @brief A template class for all LSP notification messages.
375+
*
376+
* Notifications do not have a response, and are distinguished by their method name and parameters.
377+
* This class is templated on the ParamsType, which represents the specific parameters of the notification.
378+
* It inherits from NotificationMessageBase to provide the common structure.
379+
* The method name is determined by the NotificationTraits specialization for the ParamsType.
380+
*
381+
* Notifications in the LSP spec are used to send information (either from the server to the client, or vice versa)
382+
* without expecting a response. They are typically used for events or updates that do not require a reply.
383+
*
384+
* @tparam ParamsType
385+
*/
311386
template<typename ParamsType>
312387
struct NotificationMessage : public NotificationMessageBase {
313388
ParamsType params;
@@ -335,6 +410,11 @@ struct NotificationMessage : public NotificationMessageBase {
335410
}
336411
}
337412

413+
/**
414+
* @brief Convert this NotificationMessage to a GenericNotificationMessage.
415+
*
416+
* @return GenericNotificationMessage
417+
*/
338418
GenericNotificationMessage toGeneric() const {
339419
GenericNotificationMessage generic;
340420
generic.jsonrpc = jsonrpc;

0 commit comments

Comments
 (0)