Add a package manager: rex init/add/remove/get/update/deps

Packages come from git (a registry can be added later; a bare version in
rex.toml is reserved for it). rex.toml [deps] names them, rex.lock pins exact
commits, and run/build/check/test download what is missing. `import json`
reads the package's json.rex; package files get `@json...` module keys so they
never mix with the project's own files. Newest tag of the same major version
wins when packages disagree. The language server reads downloaded packages.
Docs: docs/14-packages.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Your NameandClaude Opus 5.5 committed 2026-11-16 10:30:11 +01:00
1 parent 300d767124
commit 15da1e2379
16 files changed
+1588 -61

No files matched your search

+24
View File
@@ -160,6 +160,30 @@ fn imports_are_read_next_to_the_file() {
assert_eq!(out[0].path(&["params", "diagnostics"]), Some(&Json::Arr(vec![])), "{:?}", out[0]);
}
#[test]
fn packages_are_seen_by_the_editor() {
let dir = std::env::temp_dir().join(format!("rex-lsp-pkg-{}", std::process::id()));
std::fs::create_dir_all(dir.join("app")).unwrap();
std::fs::create_dir_all(dir.join("mylib")).unwrap();
std::fs::write(dir.join("app/rex.toml"), "[deps]\nmylib = \"../mylib\"\n").unwrap();
std::fs::write(dir.join("mylib/mylib.rex"), "pub func n(): int { return 1 }\n").unwrap();
let uri = format!("file://{}/app/main.rex", dir.display());
let good = "import mylib\nfunc main() {\n print(mylib.n())\n}\n";
let bad = "import mylib\nfunc main() {\n print(mylib.n(5))\n}\n";
let mut msgs = vec![request(1, "initialize", Json::obj(vec![])), open(&uri, good), request(2, "textDocument/definition", at(&uri, 2, 17))];
let other = format!("file://{}/app/other.rex", dir.display());
msgs.push(open(&other, bad));
msgs.extend(exit_messages());
let (out, _) = talk(msgs);
let _ = std::fs::remove_dir_all(&dir);
let diags: Vec<&Json> = out.iter().filter_map(|m| m.path(&["params", "diagnostics"])).collect();
assert_eq!(diags[0], &Json::Arr(vec![]), "{out:?}");
assert!(matches!(diags[1], Json::Arr(a) if a.len() == 1), "{out:?}");
let def = out.iter().find(|m| m.get("id") == Some(&Json::Num(2.0))).unwrap();
let target = def.path(&["result", "uri"]).map(|u| u.to_string()).unwrap_or_default();
assert!(target.contains("mylib/mylib.rex"), "{def:?}");
}
#[test]
fn unknown_requests_get_an_error() {
let mut msgs = vec![request(5, "textDocument/codeLens", Json::obj(vec![]))];