Skip to content

Support relative source paths in diagnostic file - #1717

Closed
snprajwal wants to merge 1 commit into
swiftlang:mainfrom
snprajwal:relative-diagnostic-path
Closed

snprajwal wants to merge 1 commit into
swiftlang:mainfrom
snprajwal:relative-diagnostic-path

Conversation

@snprajwal

@snprajwal snprajwal commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When running docc convert with --diagnostics-file, the emitted diagnostics use absolute paths. This is not desirable in cases where DocC is run in an ephemeral location, e.g. in CI with a UUID-prefixed temporary directory. It is instead preferable to use paths relative to the DocC catalog. Add a --relative-diagnostics-file-paths flag that allows the user to control if diagnostics use absolute or relative paths.

Dependencies

N/A

Testing

  1. docc convert /path/to/catalog.docc --diagnostics-file diagnostics.json --relative-diagnostics-file-paths
  2. Run the command without the relative paths flag
  3. Compare the two diagnostics files, the one generated with the flag should use relative paths, and the one generated without the flag should use absolute paths.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • Updated documentation if necessary

When running `docc convert` with `--diagnostics-file`, the emitted
diagnostics use absolute paths. This is not desirable in cases where
DocC is run in an ephemeral location, e.g. in CI with a UUID-prefixed
temporary directory. It is instead preferable to use paths relative to
the DocC catalog. Add a `--relative-diagnostics-file-paths` flag that
allows the user to control if diagnostics use absolute or relative
paths.
@snprajwal
snprajwal requested a review from a team as a code owner October 28, 2026 15:48
@snprajwal

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@d-ronnqvist d-ronnqvist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this feature is for.

Using the example from the testing instructions; can you explain why

docc convert /path/to/catalog.docc --diagnostics-file diagnostics.json --relative-diagnostics-file-paths

is better than

docc convert /path/to/catalog.docc --diagnostics-file /path/to/catalog.docc/diagnostics.json

?


I'll also note that it's slightly odd to place an output file inside one of the input directories.

name: .customLong("relative-diagnostics-file-paths"),
help: ArgumentHelp(
"Write source paths in the diagnostics file relative to the documentation catalog path.",
discussion: "If no documentation catalog path is provided, source paths are relative to the current directory."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This help text is confusing to me. The current directory is always the default if no explicit catalog path is provided and the source path is already relative to the current directory. You can verify that by building any documentation and passing --diagnostics-output-path relative-diagnostics.json (you'll notice that DocC writes the diagnostics file relative to the current directory)

private var fileManager: any FileManagerProtocol
/// The base URL relative to which the diagnostic source paths are written.
/// If set to `nil`, the absolute source paths are written.
private var baseURL: URL?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to store this? Wouldn't we (or even the caller) be able to add the base to the output location?

@snprajwal

Copy link
Copy Markdown
Contributor Author

The goal of this was to allow the paths to the source files reported in diagnostics to be relative to the input catalog, it doesn't affect the path to which the diagnostic file itself is written 😅

I spoke with David offline, and we agreed that this doesn't belong in DocC since we want to ensure that any tooling that consumes diagnostics has the absolute path to be able to retrieve the source file for any operations. If we want to allow for relative paths, we can think of extending the diagnostics schema to add new fields that expose any required info. I'll close this PR for now while we think about how best we can implement this.

@snprajwal snprajwal closed this Oct 28, 2026
@snprajwal
snprajwal deleted the relative-diagnostic-path branch October 28, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants