summaryrefslogtreecommitdiff
path: root/src/lsp/lsp_main.c
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-16 12:43:51 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-16 12:43:51 +0000
commite77725b55190b8ec6dcab46aa137c32652ea004b (patch)
treea80e237f1f65873f908f5819488c1c32683aff74 /src/lsp/lsp_main.c
parent2e1aa3d8853f3b49e93b1d50b1b6e60e8238d79c (diff)
Support for 'alias' + test. Improved formatting and '.gitignore'.
Diffstat (limited to 'src/lsp/lsp_main.c')
-rw-r--r--src/lsp/lsp_main.c90
1 files changed, 49 insertions, 41 deletions
diff --git a/src/lsp/lsp_main.c b/src/lsp/lsp_main.c
index a9a9f06..fbe5312 100644
--- a/src/lsp/lsp_main.c
+++ b/src/lsp/lsp_main.c
@@ -6,47 +6,55 @@
#include <unistd.h>
// Simple Main Loop for LSP.
-int lsp_main(int argc, char **argv) {
- (void)argc;
- (void)argv;
- fprintf(stderr, "zls: Zen Language Server starting...\n");
-
- while (1) {
- // Read headers
- int content_len = 0;
- char line[512];
- while (fgets(line, sizeof(line), stdin)) {
- if (0 == strcmp(line, "\r\n")) {
- break; // End of headers
- }
- if (0 == strncmp(line, "Content-Length: ", 16)) {
- content_len = atoi(line + 16);
- }
+int lsp_main(int argc, char **argv)
+{
+ (void)argc;
+ (void)argv;
+ fprintf(stderr, "zls: Zen Language Server starting...\n");
+
+ while (1)
+ {
+ // Read headers
+ int content_len = 0;
+ char line[512];
+ while (fgets(line, sizeof(line), stdin))
+ {
+ if (0 == strcmp(line, "\r\n"))
+ {
+ break; // End of headers
+ }
+ if (0 == strncmp(line, "Content-Length: ", 16))
+ {
+ content_len = atoi(line + 16);
+ }
+ }
+
+ if (content_len <= 0)
+ {
+ // Maybe EOF or error?
+ if (feof(stdin))
+ {
+ break;
+ }
+ continue; // Wait for more (yeah we gotta work on this).
+ }
+
+ // Read body.
+ char *body = malloc(content_len + 1);
+ if (fread(body, 1, content_len, stdin) != (size_t)content_len)
+ {
+ fprintf(stderr, "zls: Error reading body\n");
+ free(body);
+ break;
+ }
+ body[content_len] = 0;
+
+ // Process JSON-RPC.
+ fprintf(stderr, "zls: Received: %s\n", body);
+ handle_request(body);
+
+ free(body);
}
- if (content_len <= 0) {
- // Maybe EOF or error?
- if (feof(stdin)) {
- break;
- }
- continue; // Wait for more (yeah we gotta work on this).
- }
-
- // Read body.
- char *body = malloc(content_len + 1);
- if (fread(body, 1, content_len, stdin) != (size_t)content_len) {
- fprintf(stderr, "zls: Error reading body\n");
- free(body);
- break;
- }
- body[content_len] = 0;
-
- // Process JSON-RPC.
- fprintf(stderr, "zls: Received: %s\n", body);
- handle_request(body);
-
- free(body);
- }
-
- return 0;
+ return 0;
}