merge tools/lsp (full) — 184 completions, hover, go-to-def, live diagnostics, enhanced VSCode extension

This commit is contained in:
Will Anderson
2026-05-03 16:01:11 -05:00
11 changed files with 1381 additions and 930 deletions
+33
View File
@@ -155,6 +155,39 @@ el_val_t readline(void) {
return el_wrap_str(el_strdup(buf));
}
/* __read_n — read exactly n bytes from stdin.
* Allocates a buffer of size n+1, calls fread(buf, 1, n, stdin) to read
* exactly n raw bytes (including \r, \n, NUL, etc.), null-terminates, and
* returns the buffer as an El String. Returns "" on EOF or I/O error.
*
* Used by the El LSP server to read JSON-RPC message bodies after parsing
* the Content-Length header. readline() cannot be used for the body because
* it stops at the first \n and LSP JSON bodies are not newline-terminated. */
el_val_t __read_n(el_val_t nv) {
int64_t n = EL_INT(nv);
if (n <= 0) return el_wrap_str(el_strdup(""));
char* buf = malloc((size_t)n + 1);
if (!buf) { fputs("el_runtime: __read_n: out of memory\n", stderr); return el_wrap_str(el_strdup("")); }
size_t got = fread(buf, 1, (size_t)n, stdin);
buf[got] = '\0';
if (got == 0) { free(buf); return el_wrap_str(el_strdup("")); }
/* Track in arena so the allocation is freed when the request ends. */
el_arena_track(buf);
return el_wrap_str(buf);
}
/* __print_raw — write a string to stdout without any modification.
* Unlike println/print (which call puts/fputs and may add newlines or flush
* in platform-specific ways), this uses fwrite with the exact byte count so
* that embedded \r\n pairs in LSP Content-Length headers survive intact. */
void __print_raw(el_val_t sv) {
const char* s = EL_CSTR(sv);
if (!s) return;
size_t len = strlen(s);
fwrite(s, 1, len, stdout);
fflush(stdout);
}
/* ── String builtins ─────────────────────────────────────────────────────── */
el_val_t el_str_concat(el_val_t av, el_val_t bv) {
+10
View File
@@ -80,6 +80,16 @@ void println(el_val_t s);
void print(el_val_t s);
el_val_t readline(void);
/* __read_n — read exactly n bytes from stdin; returns String of length n.
* Returns "" on EOF or read error. Used by the El LSP server to read
* JSON-RPC message bodies after the Content-Length header is parsed. */
el_val_t __read_n(el_val_t n);
/* __print_raw — write a string to stdout using fwrite + fflush, preserving
* embedded \r\n byte pairs as-is. Used by the El LSP server to emit
* Content-Length framed JSON-RPC messages. */
void __print_raw(el_val_t s);
/* ── String builtins ─────────────────────────────────────────────────────── */
el_val_t el_str_concat(el_val_t a, el_val_t b);
+3
View File
@@ -2049,6 +2049,9 @@ fn builtin_arity(name: String) -> Int {
if str_eq(name, "println") { return 1 }
if str_eq(name, "print") { return 1 }
if str_eq(name, "readline") { return 0 }
// LSP seed primitives
if str_eq(name, "__read_n") { return 1 }
if str_eq(name, "__print_raw") { return 1 }
// String
if str_eq(name, "el_str_concat") { return 2 }
if str_eq(name, "str_eq") { return 2 }