summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2025-11-24 22:54:06 +0100
committerAlbert Cervin <albert@acervin.com>2025-11-24 22:54:06 +0100
commitf5645976b2ed01e643db9183826b6afdf9a96541 (patch)
tree21782aade57f7d5e705ecb5d6fe80e644b9f7d90
parent95bef98a8caf9eaab95977efbccc8d64da6a74fd (diff)
downloaddged-f5645976b2ed01e643db9183826b6afdf9a96541.tar.gz
dged-f5645976b2ed01e643db9183826b6afdf9a96541.tar.xz
dged-f5645976b2ed01e643db9183826b6afdf9a96541.zip
Fix diagnostics to JSON
Did not escape the message and did not put a comma between array entries.
-rw-r--r--src/main/lsp/types.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/main/lsp/types.c b/src/main/lsp/types.c
index 870ca3d..a623be0 100644
--- a/src/main/lsp/types.c
+++ b/src/main/lsp/types.c
@@ -520,9 +520,9 @@ static struct s8 diagnostic_to_json(struct diagnostic *diag) {
"{ \"range\": %.*s, \"message\": \"%.*s\", \"severity\": %d }";
struct s8 range = region_to_json(diag->region);
- struct s8 json =
- s8from_fmt(fmt, range.l, range.s, diag->message.l, diag->message.s,
- severity_to_json(diag->severity));
+ struct s8 message = escape_json_string(diag->message);
+ struct s8 json = s8from_fmt(fmt, range.l, range.s, message.l, message.s,
+ severity_to_json(diag->severity));
s8delete(range);
return json;
@@ -543,17 +543,14 @@ static struct s8 diagnostic_vec_to_json(diagnostic_vec diagnostics) {
}
uint8_t *final = (uint8_t *)calloc(len, 1);
- struct s8 json = {
- .s = final,
- .l = len,
- };
-
final[0] = '[';
size_t offset = 1;
for (uint32_t i = 0; i < ndiags; ++i) {
memcpy(&final[offset], strings[i].s, strings[i].l);
offset += strings[i].l;
+ final[offset] = ',';
+ ++offset;
s8delete(strings[i]);
}
@@ -561,8 +558,7 @@ static struct s8 diagnostic_vec_to_json(diagnostic_vec diagnostics) {
final[len - 1] = ']';
free(strings);
-
- return json;
+ return (struct s8){.s = final, .l = len};
}
struct s8 code_action_params_to_json(struct code_action_params *params) {