Add capabilities to init request

This commit is contained in:
Aaron Cook 2026-06-16 16:12:45 -05:00
commit 81229426da

View file

@ -90,18 +90,11 @@ _notify_handler(json_rpc_request_t *req, void *arg)
int
_initialize(json_rpc_request_t *req, cJSON **resp, void *arg)
{
cJSON *capabilities;
cJSON *val;
(*resp) = cJSON_CreateObject();
val = cJSON_AddObjectToObject((*resp), "capabilities");
if (val == NULL) {
return (-1);
}
if (cJSON_AddStringToObject(val, "positionEncoding", "utf-8") == NULL) {
return (-1);
}
val = cJSON_AddObjectToObject((*resp), "serverInfo");
if (val == NULL) {
@ -113,6 +106,41 @@ _initialize(json_rpc_request_t *req, cJSON **resp, void *arg)
return (-1);
}
/* All capabilities */
capabilities = cJSON_AddObjectToObject((*resp), "capabilities");
if (capabilities == NULL) {
return (-1);
}
/* utf-8 encoding only */
if (cJSON_AddStringToObject(capabilities, "positionEncoding", "utf-8") == NULL) {
return (-1);
}
/* TextDocumentSync */
val = cJSON_AddObjectToObject(capabilities, "textDocumentSync");
if (val == NULL) {
return (-1);
}
if ((cJSON_AddTrueToObject(val, "openClose") == NULL) ||
/* 1 = full content */
(cJSON_AddNumberToObject(val, "change", 1) == NULL)) {
return (-1);
}
/* Hover */
if (cJSON_AddTrueToObject(capabilities, "hoverProvider") == NULL) {
return (-1);
}
/* Go to's */
if ((cJSON_AddTrueToObject(capabilities, "declarationProvider") == NULL) ||
(cJSON_AddTrueToObject(capabilities, "definitionProvider") == NULL)) {
return (-1);
}
return (0);
}