summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZuhaitz <zuhaitz.zechhub@gmail.com>2026-01-22 22:57:35 +0000
committerGitHub <noreply@github.com>2026-01-22 22:57:35 +0000
commitdf8c377cfe4397c522ea67fe97bdacc1c7115ee9 (patch)
tree84dfba4074042e5d9aa62cce88f0d38fdd2fd4e9 /src
parent5d31f28bedc3d045f01f390245b5afbbb316e414 (diff)
parent15db02b89fba02bbe83da5c49ea7f1dd1a141b44 (diff)
Merge pull request #96 from ltecheroffical/lsp-ids
fix: Fix LSP IDs
Diffstat (limited to 'src')
-rw-r--r--src/lsp/json_rpc.c51
-rw-r--r--src/lsp/lsp_analysis.c28
2 files changed, 44 insertions, 35 deletions
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)
{