Skip to content

Commit

Permalink
Use a custom scheme for local "Declared In" source file URLs (swiftla…
Browse files Browse the repository at this point in the history
…ng#513)

rdar://106667647
  • Loading branch information
d-ronnqvist committed Mar 24, 2023
1 parent 7513841 commit 4d0fc1d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Sources/SwiftDocC/SourceRepository/SourceRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ public extension SourceRepository {

/// Creates a source repository hosted by the device's filesystem.
///
/// Use this source repository to format `file://` links to files on the
/// Use this source repository to format `doc-source-file://` links to files on the
/// device where documentation is being presented.
///
/// This source repository uses a custom scheme to offer more control local source file navigation.
static func localFilesystem() -> SourceRepository {
SourceRepository(
checkoutPath: "",
sourceServiceBaseURL: URL(fileURLWithPath: "/"),
// 2 slashes to specify an empty authority/host component and 1 slash to specify a base path at the root.
sourceServiceBaseURL: URL(string: "doc-source-file:///")!,
formatLineNumber: { line in "L\(line)" }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ConvertServiceTests: XCTestCase {

XCTAssertEqual(
renderNode.metadata.remoteSource?.url.absoluteString,
"file:///private/tmp/test.swift#L2"
"doc-source-file:///private/tmp/test.swift#L2"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SourceRepositoryTests: XCTestCase {
XCTAssertEqual(
SourceRepository.localFilesystem()
.format(sourceFileURL: URL(string: "file:///path/to/file")!, lineNumber: 5),
URL(string: "file:///path/to/file#L5")!
URL(string: "doc-source-file:///path/to/file#L5")!
)
}
}

0 comments on commit 4d0fc1d

Please sign in to comment.