Skip to content

Commit e92876f

Browse files
reid-spencerclaude
andcommitted
Fix prettify include paths to be relative to containing file
Include text was using the CWD-relative path from the AST, which produced wrong paths at every nesting level. Now computes the include path relative to the current output file by stripping the current file's directory prefix from the included file's output path. Works correctly for both top-level and nested files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent df539f3 commit e92876f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

passes/shared/src/main/scala/com/ossuminc/riddl/passes/prettify/PrettifyVisitor.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,17 @@ class PrettifyVisitor(options: PrettifyPass.Options)(using PlatformContext) exte
417417
state.withCurrent { (rfe: RiddlFileEmitter) =>
418418
if !state.flatten then
419419
val url = include.origin
420-
rfe.addLine(s"""include "${url.path}"""")
421420
val outputURL = state.toDestination(url)
421+
// Compute include path relative to the current output file
422+
val currentDir = rfe.url.path.lastIndexOf('/') match
423+
case -1 => ""
424+
case i => rfe.url.path.substring(0, i)
425+
val relativePath =
426+
if currentDir.isEmpty then outputURL.path
427+
else if outputURL.path.startsWith(currentDir + "/") then
428+
outputURL.path.drop(currentDir.length + 1)
429+
else outputURL.path
430+
rfe.addLine(s"""include "$relativePath"""")
422431
val newRFE = RiddlFileEmitter(outputURL)
423432
state.pushFile(newRFE)
424433
end if

0 commit comments

Comments
 (0)