Import files from folders above: import ..a.b, import ...a.b

Leading dots go up one folder less than their count (.. is one up, ...
is two). The language server index and formatter understand them, and a
missing file is reported with its real path.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Your NameandClaude Sonnet 5.5 committed 2026-11-08 23:54:11 +01:00
1 parent 9b496a7b03
commit 910bde692a
11 files changed
+139 -8

No files matched your search

+20
View File
@@ -267,3 +267,23 @@ fn hover_and_hints_for_c_functions() {
let s = with_header(src, "textDocument/signatureHelp", 3, 22);
assert_eq!(s.get("activeParameter").and_then(Json::as_i64), Some(2), "{s:?}");
}
#[test]
fn imports_from_a_folder_above_are_found() {
let dir = std::env::temp_dir().join(format!("rex-lsp-up-{}", std::process::id()));
std::fs::create_dir_all(dir.join("engine")).unwrap();
std::fs::create_dir_all(dir.join("game")).unwrap();
std::fs::write(dir.join("engine/engine.rex"), "pub func twice(x: int): int { return x * 2 }\n").unwrap();
let uri = format!("file://{}/game/main.rex", dir.display());
let src = "import ..engine.engine\nfunc main() {\n print(engine.twice(2))\n}\n";
// hover on `twice` reads the signature from the file above
let mut msgs = vec![request(1, "initialize", Json::obj(vec![])), open(&uri, src)];
msgs.push(request(2, "textDocument/hover", at(&uri, 2, 17)));
msgs.extend(exit_messages());
let (out, _) = talk(msgs);
let _ = std::fs::remove_dir_all(&dir);
let diags = out.iter().find(|m| m.get("method").is_some()).unwrap();
assert_eq!(diags.path(&["params", "diagnostics"]), Some(&Json::Arr(vec![])), "{diags:?}");
let hover = out.iter().find(|m| m.get("id") == Some(&Json::Num(2.0))).unwrap();
assert!(format!("{hover:?}").contains("twice"), "{hover:?}");
}