diff options
| author | LTecher Offical <ltecheroffical@gmail.com> | 2026-01-22 17:49:14 -0500 |
|---|---|---|
| committer | LTecher Offical <ltecheroffical@gmail.com> | 2026-01-22 17:49:14 -0500 |
| commit | 15db02b89fba02bbe83da5c49ea7f1dd1a141b44 (patch) | |
| tree | 99621aa6347b8f007b824922898f7530b674c5bb | |
| parent | 3d1840e8690bef6e58a208d9ca33857a59a2e852 (diff) | |
fix lsp ids
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | src/lsp/json_rpc.c | 51 | ||||
| -rw-r--r-- | src/lsp/lsp_analysis.c | 28 |
3 files changed, 45 insertions, 35 deletions
@@ -17,3 +17,4 @@ compile_commands.json vgcore.* tests/**/*.o plugins/*.so +.cache
\ No newline at end of file diff --git a/src/lsp/json_rpc.c b/src/lsp/json_rpc.c index 9b281bc..9baf33e 100644 --- a/src/lsp/json_rpc.c +++ b/src/lsp/json_rpc.c @@ -5,13 +5,13 @@ #include <stdlib.h> #include <string.h> -void lsp_check_file(const char *uri, const char *src); -void lsp_goto_definition(const char *uri, int line, int col); -void lsp_hover(const char *uri, int line, int col); -void lsp_completion(const char *uri, int line, int col); -void lsp_document_symbol(const char *uri); -void lsp_references(const char *uri, int line, int col); -void lsp_signature_help(const char *uri, int line, int col); +void lsp_check_file(const char *uri, const char *src, int id); +void lsp_goto_definition(const char *uri, int line, int col, int id); +void lsp_hover(const char *uri, int line, int col, int id); +void lsp_completion(const char *uri, int line, int col, int id); +void lsp_document_symbol(const char *uri, int id); +void lsp_references(const char *uri, int line, int col, int id); +void lsp_signature_help(const char *uri, int line, int col, int id); // Helper to extract textDocument params static void get_params(cJSON *root, char **uri, int *line, int *col) @@ -56,6 +56,13 @@ void handle_request(const char *json_str) return; } + int id = 0; + cJSON *id_item = cJSON_GetObjectItem(json, "id"); + if (id_item) + { + id = id_item->valueint; + } + cJSON *method_item = cJSON_GetObjectItem(json, "method"); if (!method_item || !method_item->valuestring) { @@ -98,13 +105,15 @@ void handle_request(const char *json_str) free(root); } - const char *response = "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{" - "\"capabilities\":{\"textDocumentSync\":1," - "\"definitionProvider\":true,\"hoverProvider\":true," - "\"referencesProvider\":true,\"documentSymbolProvider\":true," - "\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\"]}," - "\"completionProvider\":{" - "\"triggerCharacters\":[\".\"]}}}}"; + const char *response = + "{\"jsonrpc\":\"2.0\",\"id\":0,\"result\":{" + "\"serverInfo\":{\"name\":\"ZenC LS\",\"version\": \"1.0.0\"}," + "\"capabilities\":{\"textDocumentSync\":{\"openClose\":true,\"change\":1}," + "\"definitionProvider\":true,\"hoverProvider\":true," + "\"referencesProvider\":true,\"documentSymbolProvider\":true," + "\"signatureHelpProvider\":{\"triggerCharacters\":[\"(\"]}," + "\"completionProvider\":{" + "\"triggerCharacters\":[\".\"]}}}}"; fprintf(stdout, "Content-Length: %ld\r\n\r\n%s", strlen(response), response); fflush(stdout); } @@ -132,7 +141,7 @@ void handle_request(const char *json_str) if (uri && uri->valuestring && text && text->valuestring) { - lsp_check_file(uri->valuestring, text->valuestring); + lsp_check_file(uri->valuestring, text->valuestring, id); } } } @@ -144,7 +153,7 @@ void handle_request(const char *json_str) get_params(json, &uri, &line, &col); if (uri) { - lsp_goto_definition(uri, line, col); + lsp_goto_definition(uri, line, col, id); free(uri); } } @@ -155,7 +164,7 @@ void handle_request(const char *json_str) get_params(json, &uri, &line, &col); if (uri) { - lsp_hover(uri, line, col); + lsp_hover(uri, line, col, id); free(uri); } } @@ -166,7 +175,7 @@ void handle_request(const char *json_str) get_params(json, &uri, &line, &col); if (uri) { - lsp_completion(uri, line, col); + lsp_completion(uri, line, col, id); free(uri); } } @@ -177,7 +186,7 @@ void handle_request(const char *json_str) get_params(json, &uri, &line, &col); if (uri) { - lsp_document_symbol(uri); + lsp_document_symbol(uri, id); free(uri); } } @@ -188,7 +197,7 @@ void handle_request(const char *json_str) get_params(json, &uri, &line, &col); if (uri) { - lsp_references(uri, line, col); + lsp_references(uri, line, col, id); free(uri); } } @@ -199,7 +208,7 @@ void handle_request(const char *json_str) get_params(json, &uri, &line, &col); if (uri) { - lsp_signature_help(uri, line, col); + lsp_signature_help(uri, line, col, id); free(uri); } } diff --git a/src/lsp/lsp_analysis.c b/src/lsp/lsp_analysis.c index e63ae4a..9fe42f9 100644 --- a/src/lsp/lsp_analysis.c +++ b/src/lsp/lsp_analysis.c @@ -1,4 +1,3 @@ -#include "json_rpc.h" #include "cJSON.h" #include "lsp_project.h" // Includes lsp_index.h, parser.h #include <ctype.h> @@ -57,7 +56,7 @@ void lsp_on_error(void *data, Token t, const char *msg) } } -void lsp_check_file(const char *uri, const char *json_src) +void lsp_check_file(const char *uri, const char *json_src, int id) { if (!g_project) { @@ -94,6 +93,7 @@ void lsp_check_file(const char *uri, const char *json_src) // Construct JSON Response (publishDiagnostics) cJSON *root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "jsonrpc", "2.0"); + cJSON_AddNumberToObject(root, "id", id); cJSON_AddStringToObject(root, "method", "textDocument/publishDiagnostics"); cJSON *params = cJSON_CreateObject(); @@ -142,7 +142,7 @@ void lsp_check_file(const char *uri, const char *json_src) } } -void lsp_goto_definition(const char *uri, int line, int col) +void lsp_goto_definition(const char *uri, int line, int col, int id) { ProjectFile *pf = lsp_project_get_file(uri); LSPIndex *idx = pf ? pf->index : NULL; @@ -222,7 +222,7 @@ void lsp_goto_definition(const char *uri, int line, int col) cJSON *root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "jsonrpc", "2.0"); - cJSON_AddNumberToObject(root, "id", 1); + cJSON_AddNumberToObject(root, "id", id); if (found) { @@ -252,7 +252,7 @@ void lsp_goto_definition(const char *uri, int line, int col) send_json_response(root); } -void lsp_hover(const char *uri, int line, int col) +void lsp_hover(const char *uri, int line, int col, int id) { (void)uri; ProjectFile *pf = lsp_project_get_file(uri); @@ -284,7 +284,7 @@ void lsp_hover(const char *uri, int line, int col) cJSON *root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "jsonrpc", "2.0"); - cJSON_AddNumberToObject(root, "id", 1); + cJSON_AddNumberToObject(root, "id", id); if (text) { @@ -309,7 +309,7 @@ void lsp_hover(const char *uri, int line, int col) send_json_response(root); } -void lsp_completion(const char *uri, int line, int col) +void lsp_completion(const char *uri, int line, int col, int id) { ProjectFile *pf = lsp_project_get_file(uri); // Need global project context @@ -320,7 +320,7 @@ void lsp_completion(const char *uri, int line, int col) cJSON *root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "jsonrpc", "2.0"); - cJSON_AddNumberToObject(root, "id", 1); + cJSON_AddNumberToObject(root, "id", id); cJSON *items = cJSON_CreateArray(); // 1. Context-aware completion (Dot access) @@ -465,12 +465,12 @@ void lsp_completion(const char *uri, int line, int col) send_json_response(root); } -void lsp_document_symbol(const char *uri) +void lsp_document_symbol(const char *uri, int id) { ProjectFile *pf = lsp_project_get_file(uri); cJSON *root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "jsonrpc", "2.0"); - cJSON_AddNumberToObject(root, "id", 1); + cJSON_AddNumberToObject(root, "id", id); if (!pf || !pf->index) { @@ -542,12 +542,12 @@ void lsp_document_symbol(const char *uri) send_json_response(root); } -void lsp_references(const char *uri, int line, int col) +void lsp_references(const char *uri, int line, int col, int id) { ProjectFile *pf = lsp_project_get_file(uri); cJSON *root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "jsonrpc", "2.0"); - cJSON_AddNumberToObject(root, "id", 1); + cJSON_AddNumberToObject(root, "id", id); cJSON *items = cJSON_CreateArray(); if (pf && pf->index) @@ -615,12 +615,12 @@ void lsp_references(const char *uri, int line, int col) send_json_response(root); } -void lsp_signature_help(const char *uri, int line, int col) +void lsp_signature_help(const char *uri, int line, int col, int id) { ProjectFile *pf = lsp_project_get_file(uri); cJSON *root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "jsonrpc", "2.0"); - cJSON_AddNumberToObject(root, "id", 1); + cJSON_AddNumberToObject(root, "id", id); if (!g_project || !g_project->ctx || !pf || !pf->source) { |
