diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-16 00:19:37 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-16 00:19:37 +0000 |
| commit | 23d18925df02157e9330c3612992e40553bb5da1 (patch) | |
| tree | 89a893944aa7555c59b7700aa608f39680c0a120 /src/lsp/lsp_main.c | |
| parent | 301d9582884ec7d180791e5c9c6ec649dc01ff68 (diff) | |
Working on reducing function pollution
Diffstat (limited to 'src/lsp/lsp_main.c')
| -rw-r--r-- | src/lsp/lsp_main.c | 90 |
1 files changed, 41 insertions, 49 deletions
diff --git a/src/lsp/lsp_main.c b/src/lsp/lsp_main.c index fbe5312..a9a9f06 100644 --- a/src/lsp/lsp_main.c +++ b/src/lsp/lsp_main.c @@ -6,55 +6,47 @@ #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); - } - } - - 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); +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); + } } - return 0; + 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; } |
