summaryrefslogtreecommitdiff
path: root/src/lsp
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-11 17:16:40 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-11 17:17:04 +0000
commitd2461482caf9e93d6e2bc7ff17567102f635211a (patch)
treec302d1a2e7cb829b6ed006c905db0b8bbf45f57a /src/lsp
parentf9b1992795142a073cd5dc1794350fc64e9aa695 (diff)
Fixed some things. Next thing will be tests.
Diffstat (limited to 'src/lsp')
-rw-r--r--src/lsp/json_rpc.c16
-rw-r--r--src/lsp/lsp_analysis.c27
-rw-r--r--src/lsp/lsp_index.c2
-rw-r--r--src/lsp/lsp_main.c2
4 files changed, 27 insertions, 20 deletions
diff --git a/src/lsp/json_rpc.c b/src/lsp/json_rpc.c
index 008a147..903da71 100644
--- a/src/lsp/json_rpc.c
+++ b/src/lsp/json_rpc.c
@@ -1,8 +1,8 @@
+#include "json_rpc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "json_rpc.h"
// Basic JSON parsing helpers
char *get_json_string(const char *json, const char *key)
@@ -27,8 +27,9 @@ char *get_json_string(const char *json, const char *key)
return res;
}
-// Extract nested "text" from params/contentChanges/0/text or params/textDocument/text
-// This is very hacky for MVP. proper JSON library needed.
+// Extract nested "text" from params/contentChanges/0/text or
+// params/textDocument/text This is very hacky for MVP. proper JSON library
+// needed.
char *get_text_content(const char *json)
{
@@ -116,10 +117,11 @@ void handle_request(const char *json_str)
{
if (strstr(json_str, "\"method\":\"initialize\""))
{
- const char *response =
- "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"capabilities\":{\"textDocumentSync\":1,"
- "\"definitionProvider\":true,\"hoverProvider\":true,\"completionProvider\":{"
- "\"triggerCharacters\":[\".\"]}}}}";
+ const char *response = "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{"
+ "\"capabilities\":{\"textDocumentSync\":1,"
+ "\"definitionProvider\":true,\"hoverProvider\":true,"
+ "\"completionProvider\":{"
+ "\"triggerCharacters\":[\".\"]}}}}";
fprintf(stdout, "Content-Length: %ld\r\n\r\n%s", strlen(response), response);
fflush(stdout);
return;
diff --git a/src/lsp/lsp_analysis.c b/src/lsp/lsp_analysis.c
index 7a22906..d455894 100644
--- a/src/lsp/lsp_analysis.c
+++ b/src/lsp/lsp_analysis.c
@@ -1,12 +1,11 @@
+#include "json_rpc.h"
+#include "lsp_index.h"
+#include "parser.h"
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
-#include "parser.h"
-#include "parser.h"
-#include "json_rpc.h"
-#include "lsp_index.h"
static LSPIndex *g_index = NULL;
@@ -101,7 +100,8 @@ void lsp_check_file(const char *uri, const char *json_src)
{
p += sprintf(p,
- "{\"range\":{\"start\":{\"line\":%d,\"character\":%d},\"end\":{\"line\":%d,"
+ "{\"range\":{\"start\":{\"line\":%d,\"character\":%d},\"end\":"
+ "{\"line\":%d,"
"\"character\":%d}},\"severity\":1,\"message\":\"%s\"}",
d->line, d->col, d->line, d->col + 1, d->message);
@@ -146,8 +146,10 @@ void lsp_goto_definition(const char *uri, int line, int col)
// Found reference, return definition
char resp[1024];
sprintf(resp,
- "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"uri\":\"%s\",\"range\":{\"start\":{"
- "\"line\":%d,\"character\":%d},\"end\":{\"line\":%d,\"character\":%d}}}}",
+ "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"uri\":\"%s\","
+ "\"range\":{\"start\":{"
+ "\"line\":%d,\"character\":%d},\"end\":{\"line\":%d,\"character\":%"
+ "d}}}}",
uri, r->def_line, r->def_col, r->def_line, r->def_col);
fprintf(stdout, "Content-Length: %ld\r\n\r\n%s", strlen(resp), resp);
@@ -158,8 +160,10 @@ void lsp_goto_definition(const char *uri, int line, int col)
// Already at definition? Return itself.
char resp[1024];
sprintf(resp,
- "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"uri\":\"%s\",\"range\":{\"start\":{"
- "\"line\":%d,\"character\":%d},\"end\":{\"line\":%d,\"character\":%d}}}}",
+ "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"uri\":\"%s\","
+ "\"range\":{\"start\":{"
+ "\"line\":%d,\"character\":%d},\"end\":{\"line\":%d,\"character\":%"
+ "d}}}}",
uri, r->start_line, r->start_col, r->end_line, r->end_col);
fprintf(stdout, "Content-Length: %ld\r\n\r\n%s", strlen(resp), resp);
@@ -206,7 +210,8 @@ void lsp_hover(const char *uri, int line, int col)
char *json = malloc(16384);
// content: { kind: markdown, value: text }
sprintf(json,
- "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"contents\":{\"kind\":\"markdown\","
+ "{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"contents\":{\"kind\":"
+ "\"markdown\","
"\"value\":\"```c\\n%s\\n```\"}}}",
text);
diff --git a/src/lsp/lsp_index.c b/src/lsp/lsp_index.c
index 23d81ac..d952b77 100644
--- a/src/lsp/lsp_index.c
+++ b/src/lsp/lsp_index.c
@@ -1,8 +1,8 @@
+#include "lsp_index.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "lsp_index.h"
LSPIndex *lsp_index_new()
{
diff --git a/src/lsp/lsp_main.c b/src/lsp/lsp_main.c
index 9a3489b..fbe5312 100644
--- a/src/lsp/lsp_main.c
+++ b/src/lsp/lsp_main.c
@@ -1,9 +1,9 @@
+#include "json_rpc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "json_rpc.h"
// Simple Main Loop for LSP.
int lsp_main(int argc, char **argv)