BUDL4NZH6PIACJKSIPSZNL3F7XPNLB2BVYCCVUO4C3T47IAIQCEAC /--Resolve a path to an absolute path.- Absolute input is used as-is.- Relative input is resolved from `basePath` when provided, otherwise from current directory.- Uses `realPath` when possible; falls back to normalized absolute syntax when the path does not exist.-/def resolveAbsolutePath (basePath : Option String) (path : String) : IO String := dolet candidate : System.FilePath ←if path.startsWith "/" thenpure (System.FilePath.mk path)elsematch basePath with| some base => pure <| System.FilePath.mk (base ++ "/" ++ path)| none =>let cwd ← IO.currentDirpure <| System.FilePath.mk (cwd.toString ++ "/" ++ path)trylet resolved ← IO.FS.realPath candidatepure resolved.toStringcatch _ =>pure candidate.normalize.toString
let absPath := if path.startsWith "/" then pathelse match ws.rootPath with| some root => root ++ "/" ++ path| none => path
let absPath ← ViE.resolveAbsolutePath ws.rootPath path
-- Path doesn't exist, treat as new filepure (none, some path)
-- Path doesn't exist yet: still anchor workspace resolution at its parent.let parentDir := match filePath.parent with| some p => p.toString| none => "/"pure (some parentDir, some absPath)
IO.println "Starting Workspace Relative Path Resolution Test..."let stamp ← IO.monoMsNowlet relBase := s!"/tmp/vie-ws-rel-{stamp}"IO.FS.createDirAll (System.FilePath.mk relBase)let sRel0 := s11.updateCurrentWorkspace fun ws =>{ ws with rootPath := some relBase, name := "RelBase" }let sRel1 ← ViE.Command.cmdCd ["child"] sRel0assertEqual "cd relative resolves from workspace root" (some s!"{relBase}/child") sRel1.getCurrentWorkspace.rootPathlet sRel2 ← ViE.Command.cmdWs ["open", "nested"] sRel0assertEqual "ws open relative resolves from workspace root" (some s!"{relBase}/nested") sRel2.getCurrentWorkspace.rootPathassertEqual "ws open relative uses basename from absolute path" "nested" sRel2.getCurrentWorkspace.namelet sRel3 ← ViE.Command.cmdWs ["new", "RelChild", "child2"] sRel0assertEqual "ws new relative resolves from workspace root" (some s!"{relBase}/child2") sRel3.getCurrentWorkspace.rootPath
assertEqual "File arg sets workspace to parent dir" (some s!"{base}/dir0/dir1/dir2") wsFileNestedassertEqual "File arg keeps filename" (some fileNested) fileFileNested
assertEqual "File arg sets workspace to parent dir" (some nestedParent) wsFileNestedassertEqual "File arg keeps filename" (some absFileNested) fileFileNested
assertEqual "Top-level file sets workspace to base" (some base) wsFileTopassertEqual "Top-level file keeps filename" (some fileTop) fileFileTop
assertEqual "Top-level file sets workspace to base" (some absBase) wsFileTopassertEqual "Top-level file keeps filename" (some absFileTop) fileFileToplet newNested := s!"{base}/newdir/newfile.txt"let absNewNested ← ViE.resolveAbsolutePath none newNestedlet newNestedParent := match (System.FilePath.mk absNewNested).parent with| some p => p.toString| none => "/"let (wsNewNested, fileNewNested) ← ViE.resolveStartupTarget (some newNested)assertEqual "Nonexistent file sets workspace to parent dir" (some newNestedParent) wsNewNestedassertEqual "Nonexistent file keeps absolute filename" (some absNewNested) fileNewNested
{ ws with rootPath := some "Test", name := "Test" }let s14 ← ViE.Feature.openExplorer s13 "Test"assertEqual "Explorer opens workspace root without duplication" (some "explorer://Test") s14.getActiveBuffer.filename
{ ws with rootPath := some absTest, name := "Test" }let s14 ← ViE.Feature.openExplorer s13 "."assertEqual "Explorer opens absolute workspace root from dot" (some s!"explorer://{absTest}") s14.getActiveBuffer.filenamelet s15 ← ViE.Feature.openExplorer s13 "test_paths"assertEqual "Explorer resolves relative path from absolute workspace root" (some s!"explorer://{absTest}/test_paths") s15.getActiveBuffer.filename