Add C and C++ library support

import "zlib.h" reads the header (cc -E + a small C declaration
parser), links via pkg-config or link "name", and builds .c/.cpp
files next to the program. C structs become Dino structs, pointers
become pointer types (nil = NULL), T* parameters take variables or
lists. Adds dino header, editor completion/hover for C names,
docs chapter 13, a raylib example, and tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Your NameandClaude Opus 5.5 committed 2026-11-08 12:55:41 +01:00
1 parent 5b42e2a3bd
commit 2f44f09b6a
26 files changed
+3418 -70

No files matched your search

+30
View File
@@ -225,3 +225,33 @@ fn signature_help_marks_the_parameter() {
assert_eq!(r.get("activeParameter").and_then(Json::as_i64), Some(1), "{r:?}");
assert!(r.to_string().contains("add(a: int, b: int): int"), "{r:?}");
}
// ---------- C headers ----------
fn with_header(src: &str, method: &str, line: i64, ch: i64) -> Json {
let dir = std::env::temp_dir().join(format!("dino-lsp-c-{}-{}", std::process::id(), method.replace('/', "_")));
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("geo.h"), "typedef struct { double x, y; } Point;\n#define ORIGIN_NAME \"origin\"\n/* distance */\ndouble dist(Point a, Point b);\nint clamp(int v, int lo, int hi);\n").unwrap();
let uri = format!("file://{}/main.dino", dir.display());
let mut msgs = vec![request(1, "initialize", Json::obj(vec![])), open(&uri, src), request(2, method, at(&uri, line, ch))];
msgs.extend(exit_messages());
let (out, _) = talk(msgs);
let _ = std::fs::remove_dir_all(&dir);
out.into_iter().find(|m| m.get("id") == Some(&Json::Num(2.0))).unwrap().get("result").cloned().unwrap_or(Json::Null)
}
#[test]
fn completion_lists_what_a_c_header_has() {
let r = with_header("import \"geo.h\"\n\nfunc main() {\n geo.\n}\n", "textDocument/completion", 3, 8).to_string();
assert!(r.contains("\"dist\"") && r.contains("\"Point\"") && r.contains("\"ORIGIN_NAME\"") && r.contains("dist(a: geo.Point, b: geo.Point): float"), "{r}");
}
#[test]
fn hover_and_hints_for_c_functions() {
let src = "import \"geo.h\" { clamp }\n\nfunc main() {\n print(clamp(5, 0, \n}\n";
let h = with_header(src, "textDocument/hover", 3, 11);
let v = h.path(&["contents", "value"]).and_then(Json::as_str).unwrap_or("").to_string();
assert!(v.contains("func clamp(v: i32, lo: i32, hi: i32): i32") && v.contains("geo.h"), "{v}");
let s = with_header(src, "textDocument/signatureHelp", 3, 22);
assert_eq!(s.get("activeParameter").and_then(Json::as_i64), Some(2), "{s:?}");
}